Home / Function/ Test_Hook_OnPostShutdown() — fiber Function Reference

Test_Hook_OnPostShutdown() — fiber Function Reference

Architecture documentation for the Test_Hook_OnPostShutdown() function in hooks_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  6d5682ac_0451_2c6b_251f_78aa5c3e7f81["Test_Hook_OnPostShutdown()"]
  2d218330_4ff5_8bbe_d9c4_174410c41dd0["hooks_test.go"]
  6d5682ac_0451_2c6b_251f_78aa5c3e7f81 -->|defined in| 2d218330_4ff5_8bbe_d9c4_174410c41dd0
  style 6d5682ac_0451_2c6b_251f_78aa5c3e7f81 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

hooks_test.go lines 201–266

func Test_Hook_OnPostShutdown(t *testing.T) {
	t.Run("should execute post shutdown hook with error", func(t *testing.T) {
		app := New()
		expectedErr := errors.New("test shutdown error")

		hookCalled := make(chan error, 1)
		defer close(hookCalled)

		app.Hooks().OnPostShutdown(func(err error) error {
			hookCalled <- err
			return nil
		})

		go func() {
			if err := app.Listen(":0"); err != nil {
				return
			}
		}()

		time.Sleep(100 * time.Millisecond)

		app.hooks.executeOnPostShutdownHooks(expectedErr)

		select {
		case err := <-hookCalled:
			require.Equal(t, expectedErr, err)
		case <-time.After(time.Second):
			t.Fatal("hook execution timeout")
		}

		require.NoError(t, app.Shutdown())
	})

	t.Run("should execute multiple hooks in order", func(t *testing.T) {
		app := New()

		execution := make([]int, 0)

		app.Hooks().OnPostShutdown(func(_ error) error {
			execution = append(execution, 1)
			return nil
		})

		app.Hooks().OnPostShutdown(func(_ error) error {
			execution = append(execution, 2)
			return nil
		})

		app.hooks.executeOnPostShutdownHooks(nil)

		require.Len(t, execution, 2, "expected 2 hooks to execute")
		require.Equal(t, []int{1, 2}, execution, "hooks executed in wrong order")
	})

	t.Run("should handle hook error", func(_ *testing.T) {
		app := New()
		hookErr := errors.New("hook error")

		app.Hooks().OnPostShutdown(func(_ error) error {
			return hookErr
		})

		// Should not panic
		app.hooks.executeOnPostShutdownHooks(nil)
	})
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does Test_Hook_OnPostShutdown() do?
Test_Hook_OnPostShutdown() is a function in the fiber codebase, defined in hooks_test.go.
Where is Test_Hook_OnPostShutdown() defined?
Test_Hook_OnPostShutdown() is defined in hooks_test.go at line 201.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free