Skip to content

Commit

Permalink
server_test: add Serve()/Shutdown() race test.
Browse files Browse the repository at this point in the history
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
  • Loading branch information
klihub committed Sep 16, 2024
1 parent 3f02183 commit ed6c3ba
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,36 @@ func TestServerClose(t *testing.T) {
checkServerShutdown(t, server)
}

func TestImmediateServerShutdown(t *testing.T) {
var (
ctx = context.Background()
server = mustServer(t)(NewServer())
addr, listener = newTestListener(t)
errs = make(chan error, 1)
_, cleanup = newTestClient(t, addr)
)
defer cleanup()
defer listener.Close()
go func() {
time.Sleep(1 * time.Millisecond)
errs <- server.Serve(ctx, listener)
}()

registerTestingService(server, &testingServer{})

if err := server.Shutdown(ctx); err != nil {
t.Fatal(err)
}
select {
case err := <-errs:
if err != ErrServerClosed {
t.Fatal(err)
}
case <-time.After(2 * time.Second):
t.Fatal("retreiving error from server.Shutdown() timed out")
}
}

func TestOversizeCall(t *testing.T) {
var (
ctx = context.Background()
Expand Down

0 comments on commit ed6c3ba

Please sign in to comment.