Attempt to fix flaky tests.

This commit is contained in:
Joachim Bauch 2021-05-31 16:53:52 +02:00
parent 21f3f506d1
commit 6e54d8f4f4
No known key found for this signature in database
GPG Key ID: 77C1D22D53E15F02
2 changed files with 7 additions and 0 deletions

View File

@ -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 {

View File

@ -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()
}