-
I'm writing a test case to eventually capture panics in my app. But eventually, they could come from within the execution of a Go Routine. I've created a quick test case to prove my point here. As described, the func TestGoRoutinePanic(t *testing.T) {
assert.Panics(t, func() {
go func() {
panic("timeout")
}()
time.Sleep(5 * time.Second)
})
} From within this caller, I've spawned a new Go routine that immediately panics, and the result of running this is: panic: timeout
goroutine 36 [running]:
test.TestGoRoutinePanic.func1.1()
/.../Desktop/main_test.go:13 +0x2c
created by test.TestGoRoutinePanic.func1 in goroutine 35
/.../Desktop/main_test.go:12 +0x24
FAIL test 0.763s
FAIL So the assert failed to capture a panic that happened from within the passed function. func TestGoRoutinePanic(t *testing.T) {
assert.Panics(t, func() {
func() {
panic("timeout")
}()
time.Sleep(5 * time.Second)
})
} ok test 1.004s Could someone tell me why this is? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
panic
andrecover
works in context of current goroutine only