feat: configure application transports and unify graceful shutdown
This commit is contained in:
@@ -504,12 +504,13 @@ func (b *closeBody) Close() error {
|
||||
return errors.Join(err, b.conn.Close())
|
||||
}
|
||||
|
||||
func TestServerShutdownCancelsActiveHandler(t *testing.T) {
|
||||
started := make(chan struct{})
|
||||
func TestServerShutdownTimeoutCancelsActiveHandler(t *testing.T) {
|
||||
started, canceled := make(chan struct{}), make(chan struct{})
|
||||
application := omni.NewWithRouter(netrouter.New())
|
||||
application.GET("/wait", func(ctx *omni.Context) error {
|
||||
close(started)
|
||||
<-ctx.Context().Done()
|
||||
close(canceled)
|
||||
return ctx.Context().Err()
|
||||
})
|
||||
server, listener, done := startServer(t, application)
|
||||
@@ -524,19 +525,12 @@ func TestServerShutdownCancelsActiveHandler(t *testing.T) {
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("handler did not start")
|
||||
}
|
||||
shutdownContext, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
shutdownContext, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
|
||||
defer cancel()
|
||||
if err := server.Shutdown(shutdownContext); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
response, err := http.ReadResponse(bufio.NewReader(conn), &http.Request{Method: http.MethodGet})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
response.Body.Close()
|
||||
if response.StatusCode != http.StatusInternalServerError {
|
||||
t.Fatalf("expected canceled handler to become 500, got %d", response.StatusCode)
|
||||
if err := server.Shutdown(shutdownContext); !errors.Is(err, context.DeadlineExceeded) {
|
||||
t.Fatalf("expected shutdown deadline, got %v", err)
|
||||
}
|
||||
<-canceled
|
||||
conn.Close()
|
||||
select {
|
||||
case err := <-done:
|
||||
|
||||
Reference in New Issue
Block a user