github.com/lingyao2333/mo-zero@v1.4.1/core/threading/routines_test.go (about) 1 package threading 2 3 import ( 4 "io" 5 "log" 6 "testing" 7 8 "github.com/lingyao2333/mo-zero/core/lang" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestRoutineId(t *testing.T) { 13 assert.True(t, RoutineId() > 0) 14 } 15 16 func TestRunSafe(t *testing.T) { 17 log.SetOutput(io.Discard) 18 19 i := 0 20 21 defer func() { 22 assert.Equal(t, 1, i) 23 }() 24 25 ch := make(chan lang.PlaceholderType) 26 go RunSafe(func() { 27 defer func() { 28 ch <- lang.Placeholder 29 }() 30 31 panic("panic") 32 }) 33 34 <-ch 35 i++ 36 }