Skip to content

Commit

Permalink
Make sure sub registered, wait a bit for all msgs
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Collison <[email protected]>
  • Loading branch information
derekcollison committed Jun 29, 2018
1 parent 061788a commit 535367e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions server/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ func TestClientPubWithQueueSubNoEcho(t *testing.T) {
if err != nil {
t.Fatalf("Error on subscribe: %v", err)
}
nc1.Flush()

nc2, err := nats.Connect(fmt.Sprintf("nats://%s:%d", opts.Host, opts.Port))
if err != nil {
Expand All @@ -484,18 +485,22 @@ func TestClientPubWithQueueSubNoEcho(t *testing.T) {
if err != nil {
t.Fatalf("Error on subscribe: %v", err)
}
nc2.Flush()

// Now publish 100 messages.
// Now publish 100 messages on nc1 which does not allow echo.
for i := 0; i < 100; i++ {
nc1.Publish("foo", []byte("Hello"))
}
nc1.Flush()
nc2.Flush()

num := atomic.LoadInt32(&n)
if num != int32(100) {
t.Fatalf("Expected all the msgs to be received by nc2, got %d\n", num)
}
checkFor(t, 5*time.Second, 10*time.Millisecond, func() error {
num := atomic.LoadInt32(&n)
if num != int32(100) {
return fmt.Errorf("Expected all the msgs to be received by nc2, got %d\n", num)
}
return nil
})
}

func TestClientUnSub(t *testing.T) {
Expand Down

0 comments on commit 535367e

Please sign in to comment.