You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/core/threading/routines_test.go

37 lines
478 B
Go

package threading
import (
"io/ioutil"
"log"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tal-tech/go-zero/core/lang"
)
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++
}