mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-08 14:42:27 +08:00
feat: add watcher for record code excution time
This commit is contained in:
32
function/watcher_test.go
Normal file
32
function/watcher_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package function
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWatcher(t *testing.T) {
|
||||
w := &Watcher{}
|
||||
w.Start()
|
||||
|
||||
longRunningTask()
|
||||
|
||||
if !w.excuting {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
w.Stop()
|
||||
|
||||
eapsedTime := w.GetElapsedTime().Milliseconds()
|
||||
t.Log("Elapsed Time (milsecond)", eapsedTime)
|
||||
|
||||
if w.excuting {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func longRunningTask() {
|
||||
var slice []int64
|
||||
for i := 0; i < 10000000; i++ {
|
||||
slice = append(slice, int64(i))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user