Skip to content

Commit

Permalink
fix(blob): fix blobsub subscription cancellation test (#3746)
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Sep 18, 2024
1 parent 1279c2e commit 89e8781
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,23 +683,28 @@ func TestService_Subscribe(t *testing.T) {

t.Run("subscription cancellation", func(t *testing.T) {
ns := blobs[0].Namespace()
subCtx, subCancel := context.WithCancel(ctx)
subCtx, subCancel := context.WithTimeout(ctx, time.Second*2)
subCh, err := service.Subscribe(subCtx, ns)
require.NoError(t, err)

// cancel the subscription context after receiving the first response
select {
case <-subCh:
subCancel()
case <-time.After(time.Second * 2):
case <-ctx.Done():
t.Fatal("timeout waiting for first subscription response")
}

select {
case _, ok := <-subCh:
assert.False(t, ok, "expected subscription channel to be closed")
case <-time.After(time.Second * 2):
t.Fatal("timeout waiting for subscription channel to close")
for {
select {
case _, ok := <-subCh:
if !ok {
// channel closed as expected
return
}
case <-ctx.Done():
t.Fatal("timeout waiting for subscription channel to close")
}
}
})

Expand Down

0 comments on commit 89e8781

Please sign in to comment.