(t *testing.T)
| 1495 | } |
| 1496 | |
| 1497 | func Test_App_ShutdownWithContext(t *testing.T) { |
| 1498 | t.Parallel() |
| 1499 | |
| 1500 | t.Run("successful shutdown", func(t *testing.T) { |
| 1501 | t.Parallel() |
| 1502 | app := New() |
| 1503 | |
| 1504 | // Fast request that should complete |
| 1505 | app.Get("/", func(c Ctx) error { |
| 1506 | return c.SendString("OK") |
| 1507 | }) |
| 1508 | |
| 1509 | ln := fasthttputil.NewInmemoryListener() |
| 1510 | serverStarted := make(chan bool, 1) |
| 1511 | |
| 1512 | go func() { |
| 1513 | serverStarted <- true |
| 1514 | if err := app.Listener(ln); err != nil { |
| 1515 | t.Errorf("Failed to start listener: %v", err) |
| 1516 | } |
| 1517 | }() |
| 1518 | |
| 1519 | <-serverStarted |
| 1520 | |
| 1521 | // Execute normal request |
| 1522 | conn, err := ln.Dial() |
| 1523 | require.NoError(t, err) |
| 1524 | _, err = conn.Write([]byte("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")) |
| 1525 | require.NoError(t, err) |
| 1526 | |
| 1527 | // Shutdown with sufficient timeout |
| 1528 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1529 | defer cancel() |
| 1530 | |
| 1531 | err = app.ShutdownWithContext(ctx) |
| 1532 | require.NoError(t, err, "Expected successful shutdown") |
| 1533 | }) |
| 1534 | |
| 1535 | t.Run("shutdown with hooks", func(t *testing.T) { |
| 1536 | t.Parallel() |
| 1537 | app := New() |
| 1538 | |
| 1539 | hookOrder := make([]string, 0) |
| 1540 | var hookMutex sync.Mutex |
| 1541 | |
| 1542 | app.Hooks().OnPreShutdown(func() error { |
| 1543 | hookMutex.Lock() |
| 1544 | hookOrder = append(hookOrder, "pre") |
| 1545 | hookMutex.Unlock() |
| 1546 | return nil |
| 1547 | }) |
| 1548 | |
| 1549 | app.Hooks().OnPostShutdown(func(_ error) error { |
| 1550 | hookMutex.Lock() |
| 1551 | hookOrder = append(hookOrder, "post") |
| 1552 | hookMutex.Unlock() |
| 1553 | return nil |
| 1554 | }) |
nothing calls this directly
no test coverage detected
searching dependent graphs…