Skip to content

Commit

Permalink
adding graceful shutdown unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
distractedm1nd committed Jul 24, 2024
1 parent da7c540 commit 7133e90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 22 additions & 1 deletion blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,14 +734,35 @@ func TestService_Subscribe(t *testing.T) {
t.Fatal("timeout waiting for first subscription response")
}

// check that the subscription channel is closed
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")
}
})

t.Run("graceful shutdown", func(t *testing.T) {
ns := blobs[0].Namespace()
subCh, err := service.Subscribe(ctx, ns)
require.NoError(t, err)

// cancel the subscription context after receiving the first response
select {
case <-subCh:
service.Stop(context.Background())

Check failure on line 753 in blob/service_test.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

Error return value of `service.Stop` is not checked (errcheck)
case <-time.After(time.Second * 2):
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")
}

})

Check failure on line 765 in blob/service_test.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

unnecessary trailing newline (whitespace)
}

func TestService_Subscribe_MultipleNamespaces(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion nodebuilder/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type Module interface {

type API struct {
Internal struct {
<<<<<<< HEAD
Submit func(
context.Context,
[]*blob.Blob,
Expand Down

0 comments on commit 7133e90

Please sign in to comment.