MCPcopy Create free account
hub / github.com/JordanCoin/codemap / TestRunWithTimeout

Function TestRunWithTimeout

cmd/hooks_test.go:121–145  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

119}
120
121func TestRunWithTimeout(t *testing.T) {
122 t.Run("returns function result before timeout", func(t *testing.T) {
123 errExpected := errors.New("boom")
124 err := runWithTimeout("test-hook", 50*time.Millisecond, func() error {
125 return errExpected
126 })
127 if !errors.Is(err, errExpected) {
128 t.Fatalf("expected %v, got %v", errExpected, err)
129 }
130 })
131
132 t.Run("returns timeout error when function blocks too long", func(t *testing.T) {
133 err := runWithTimeout("slow-hook", 20*time.Millisecond, func() error {
134 time.Sleep(80 * time.Millisecond)
135 return nil
136 })
137 var timeoutErr *HookTimeoutError
138 if !errors.As(err, &timeoutErr) {
139 t.Fatalf("expected HookTimeoutError, got %v", err)
140 }
141 if timeoutErr.Hook != "slow-hook" {
142 t.Fatalf("expected hook name slow-hook, got %q", timeoutErr.Hook)
143 }
144 })
145}
146
147func TestCappedStringWriter(t *testing.T) {
148 t.Run("captures full output under limit", func(t *testing.T) {

Callers

nothing calls this directly

Calls 1

runWithTimeoutFunction · 0.85

Tested by

no test coverage detected