1
0

profile_test.go 513 B

1234567891011121314151617181920212223242526272829
  1. package proc
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. )
  8. func TestProfile(t *testing.T) {
  9. var buf strings.Builder
  10. w := logx.NewWriter(&buf)
  11. o := logx.Reset()
  12. logx.SetWriter(w)
  13. defer func() {
  14. logx.Reset()
  15. logx.SetWriter(o)
  16. }()
  17. profiler := StartProfile()
  18. // start again should not work
  19. assert.NotNil(t, StartProfile())
  20. profiler.Stop()
  21. // stop twice
  22. profiler.Stop()
  23. assert.True(t, strings.Contains(buf.String(), ".pprof"))
  24. }