feat: specify running cycles for load testing.

This commit is contained in:
徐聪
2022-01-12 14:48:43 +08:00
parent b80730d8a4
commit 7a15df3177
4 changed files with 83 additions and 8 deletions
+25 -2
View File
@@ -3,6 +3,8 @@ package boomer
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type HitOutput struct {
@@ -45,13 +47,13 @@ func TestOutputOnStart(t *testing.T) {
}
}
func TestOutputOnEevent(t *testing.T) {
func TestOutputOnEvent(t *testing.T) {
hitOutput := &HitOutput{}
hitOutput2 := &HitOutput{}
runner := &runner{}
runner.addOutput(hitOutput)
runner.addOutput(hitOutput2)
runner.outputOnEevent(nil)
runner.outputOnEvent(nil)
if !hitOutput.onEvent {
t.Error("hitOutput's OnEvent has not been called")
}
@@ -90,3 +92,24 @@ func TestLocalRunner(t *testing.T) {
time.Sleep(4 * time.Second)
runner.stop()
}
func TestLoopCount(t *testing.T) {
taskA := &Task{
Weight: 10,
Fn: func() {
time.Sleep(time.Second)
},
Name: "TaskA",
}
tasks := []*Task{taskA}
runner := newLocalRunner(2, 2)
runner.loop = &Loop{loopCount: 4}
runner.setTasks(tasks)
go runner.start()
ticker := time.NewTicker(4 * time.Second)
defer ticker.Stop()
<-ticker.C
if !assert.Equal(t, runner.loop.loopCount, runner.loop.finishedCount) {
t.Fail()
}
}