Skip to content

Commit

Permalink
Add test case about subscription timeout behavior
Browse files Browse the repository at this point in the history
Follow TDD principle, write test watch it fails.
  • Loading branch information
wdhongtw committed Jul 2, 2022
1 parent d29a40a commit 428daee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions js_test.go
Expand Up @@ -939,6 +939,7 @@ func TestJetStreamExpiredPullRequests(t *testing.T) {
t.Fatalf("Expected error and wait for 250ms, got err=%v and dur=%v", err, dur)
}
}

}

func TestJetStreamSyncSubscribeWithMaxAckPending(t *testing.T) {
Expand Down
16 changes: 16 additions & 0 deletions test/js_test.go
Expand Up @@ -6867,6 +6867,22 @@ func testJetStreamFetchContext(t *testing.T, srvs ...*jsServer) {
t.Errorf("Expected %d pending messages, got: %d", pending, total)
}
})

t.Run("MaxWait timeout should return nats error", func(t *testing.T) {
_, err := sub.Fetch(1, nats.MaxWait(1*time.Nanosecond))
if !errors.Is(err, nats.ErrTimeout) {
t.Fatalf("Expect ErrTimeout, got err=%#v", err)
}
})

t.Run("Context timeout should return context error", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond)
defer cancel()
_, err := sub.Fetch(1, nats.Context(ctx))
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatalf("Expect context.DeadlineExceeded, got err=%#v", err)
}
})
}

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

0 comments on commit 428daee

Please sign in to comment.