diff --git a/hub_test.go b/hub_test.go index 654ed00..ff44955 100644 --- a/hub_test.go +++ b/hub_test.go @@ -1933,6 +1933,9 @@ func TestClientMessageToSessionIdWhileDisconnected(t *testing.T) { client1.SendMessage(recipient2, data1) // nolint client1.SendMessage(recipient2, data1) // nolint + // Simulate some time until client resumes the session. + time.Sleep(10 * time.Millisecond) + client2 = NewTestClient(t, server, hub) defer client2.CloseWithBye() if err := client2.SendHelloResume(hello2.Hello.ResumeId); err != nil { diff --git a/natsclient_loopback.go b/natsclient_loopback.go index 12fb8db..e9c33d7 100644 --- a/natsclient_loopback.go +++ b/natsclient_loopback.go @@ -25,6 +25,7 @@ import ( "encoding/json" "strings" "sync" + "time" "github.com/nats-io/nats.go" ) @@ -95,6 +96,9 @@ func (s *loopbackNatsSubscription) run() { msg := s.incoming[0] s.incoming = s.incoming[1:] s.cond.L.Unlock() + // A "real" NATS server would take some time to process the request, + // simulate this by sleeping a tiny bit. + time.Sleep(time.Millisecond) s.ch <- msg s.cond.L.Lock() }