github.com/lingyao2333/mo-zero@v1.4.1/core/rescue/recover_test.go (about) 1 package rescue 2 3 import ( 4 "sync/atomic" 5 "testing" 6 7 "github.com/lingyao2333/mo-zero/core/logx" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func init() { 12 logx.Disable() 13 } 14 15 func TestRescue(t *testing.T) { 16 var count int32 17 assert.NotPanics(t, func() { 18 defer Recover(func() { 19 atomic.AddInt32(&count, 2) 20 }, func() { 21 atomic.AddInt32(&count, 3) 22 }) 23 24 panic("hello") 25 }) 26 assert.Equal(t, int32(5), atomic.LoadInt32(&count)) 27 }