chore: add more tests (#3229)

This commit is contained in:
Kevin Wan
2023-05-08 23:49:13 +08:00
committed by GitHub
parent 851a72f1cc
commit 93124329ac
2 changed files with 17 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package rescue
import (
"context"
"sync/atomic"
"testing"
@@ -25,3 +26,17 @@ func TestRescue(t *testing.T) {
})
assert.Equal(t, int32(5), atomic.LoadInt32(&count))
}
func TestRescueCtx(t *testing.T) {
var count int32
assert.NotPanics(t, func() {
defer RecoverCtx(context.Background(), func() {
atomic.AddInt32(&count, 2)
}, func() {
atomic.AddInt32(&count, 3)
})
panic("hello")
})
assert.Equal(t, int32(5), atomic.LoadInt32(&count))
}