mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
29 lines
405 B
Go
29 lines
405 B
Go
|
package rescue
|
||
|
|
||
|
import (
|
||
|
"sync/atomic"
|
||
|
"testing"
|
||
|
|
||
|
"zero/core/logx"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
logx.Disable()
|
||
|
}
|
||
|
|
||
|
func TestRescue(t *testing.T) {
|
||
|
var count int32
|
||
|
assert.NotPanics(t, func() {
|
||
|
defer Recover(func() {
|
||
|
atomic.AddInt32(&count, 2)
|
||
|
}, func() {
|
||
|
atomic.AddInt32(&count, 3)
|
||
|
})
|
||
|
|
||
|
panic("hello")
|
||
|
})
|
||
|
assert.Equal(t, int32(5), atomic.LoadInt32(&count))
|
||
|
}
|