From 71a2b20301e9474dbcebeb5d4dae36e54e6a1d5b Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sun, 27 Dec 2020 14:45:14 +0800 Subject: [PATCH] add more tests for prof (#322) --- core/prof/profilecenter_test.go | 16 ++++++++++++++++ core/prof/profiler_test.go | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 core/prof/profilecenter_test.go create mode 100644 core/prof/profiler_test.go diff --git a/core/prof/profilecenter_test.go b/core/prof/profilecenter_test.go new file mode 100644 index 00000000..77e4b96d --- /dev/null +++ b/core/prof/profilecenter_test.go @@ -0,0 +1,16 @@ +package prof + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestReport(t *testing.T) { + once.Do(func() {}) + assert.NotContains(t, generateReport(), "foo") + report("foo", time.Second) + assert.Contains(t, generateReport(), "foo") + report("foo", time.Second) +} diff --git a/core/prof/profiler_test.go b/core/prof/profiler_test.go new file mode 100644 index 00000000..617abdc7 --- /dev/null +++ b/core/prof/profiler_test.go @@ -0,0 +1,23 @@ +package prof + +import ( + "testing" + + "github.com/tal-tech/go-zero/core/utils" +) + +func TestProfiler(t *testing.T) { + EnableProfiling() + Start() + Report("foo", ProfilePoint{ + ElapsedTimer: utils.NewElapsedTimer(), + }) +} + +func TestNullProfiler(t *testing.T) { + p := newNullProfiler() + p.Start() + p.Report("foo", ProfilePoint{ + ElapsedTimer: utils.NewElapsedTimer(), + }) +}