2020-09-29 14:30:22 +08:00
|
|
|
package proc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-05-03 17:34:26 +08:00
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
2020-09-29 14:30:22 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestProfile(t *testing.T) {
|
|
|
|
var buf strings.Builder
|
2022-05-03 17:34:26 +08:00
|
|
|
w := logx.NewWriter(&buf)
|
|
|
|
o := logx.Reset()
|
|
|
|
logx.SetWriter(w)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
logx.Reset()
|
|
|
|
logx.SetWriter(o)
|
|
|
|
}()
|
|
|
|
|
2020-09-29 14:30:22 +08:00
|
|
|
profiler := StartProfile()
|
|
|
|
// start again should not work
|
|
|
|
assert.NotNil(t, StartProfile())
|
|
|
|
profiler.Stop()
|
|
|
|
// stop twice
|
|
|
|
profiler.Stop()
|
|
|
|
assert.True(t, strings.Contains(buf.String(), ".pprof"))
|
|
|
|
}
|