Skip to content

Commit

Permalink
[IMPROVED] Fixed flaky tests in js.Subscribe() and kv
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Piotrowski <[email protected]>
  • Loading branch information
piotrpio committed Aug 28, 2023
1 parent 3196448 commit f80b4af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions test/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4155,19 +4155,21 @@ func TestJetStreamSubscribe_AckPolicy(t *testing.T) {
}

<-ctx.Done()
sub.Drain()

if got != totalMsgs {
t.Fatalf("Expected %d, got %d", totalMsgs, got)
}

// check if consumer is configured properly
ci, err := js.ConsumerInfo("TEST", test.name)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if ci.Config.AckPolicy != test.expected {
t.Fatalf("Expected %v, got %v", test.expected, ci.Config.AckPolicy)
}

// drain the subscription. This will remove the consumer
sub.Drain()
})
}

Expand Down
6 changes: 6 additions & 0 deletions test/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,13 +952,16 @@ func TestKeyValueMirrorCrossDomains(t *testing.T) {

_, err = mkv.PutString("v", "vv")
expectOk(t, err)
// wait for the key to be propagated to the mirror
time.Sleep(10 * time.Millisecond)
e, err := mkv.Get("v")
expectOk(t, err)
if e.Operation() != nats.KeyValuePut {
t.Fatalf("Got wrong value: %q vs %q", e.Operation(), nats.KeyValuePut)
}
err = mkv.Delete("v")
expectOk(t, err)
time.Sleep(10 * time.Millisecond)
_, err = mkv.Get("v")
expectErr(t, err, nats.ErrKeyNotFound)

Expand All @@ -983,20 +986,23 @@ func TestKeyValueMirrorCrossDomains(t *testing.T) {
_, err = rkv.PutString("name", "ivan")
expectOk(t, err)

time.Sleep(10 * time.Millisecond)
e, err = rkv.Get("name")
expectOk(t, err)
if string(e.Value()) != "ivan" {
t.Fatalf("Got wrong value: %q vs %q", e.Value(), "ivan")
}
_, err = rkv.PutString("v", "vv")
expectOk(t, err)
time.Sleep(10 * time.Millisecond)
e, err = mkv.Get("v")
expectOk(t, err)
if e.Operation() != nats.KeyValuePut {
t.Fatalf("Got wrong value: %q vs %q", e.Operation(), nats.KeyValuePut)
}
err = rkv.Delete("v")
expectOk(t, err)
time.Sleep(10 * time.Millisecond)
_, err = rkv.Get("v")
expectErr(t, err, nats.ErrKeyNotFound)

Expand Down

0 comments on commit f80b4af

Please sign in to comment.