go-zero/core/threading/routines_test.go

37 lines
478 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package threading
import (
"io/ioutil"
"log"
"testing"
"github.com/stretchr/testify/assert"
2020-08-08 16:40:10 +08:00
"github.com/tal-tech/go-zero/core/lang"
2020-07-26 17:09:05 +08:00
)
func TestRoutineId(t *testing.T) {
assert.True(t, RoutineId() > 0)
}
func TestRunSafe(t *testing.T) {
log.SetOutput(ioutil.Discard)
i := 0
defer func() {
assert.Equal(t, 1, i)
}()
ch := make(chan lang.PlaceholderType)
go RunSafe(func() {
defer func() {
ch <- lang.Placeholder
}()
panic("panic")
})
<-ch
i++
}