mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
refactor: fork boomer as sub module
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package boomer
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type HitOutput struct {
|
||||
onStart bool
|
||||
onEvent bool
|
||||
onStop bool
|
||||
}
|
||||
|
||||
func (o *HitOutput) OnStart() {
|
||||
o.onStart = true
|
||||
}
|
||||
|
||||
func (o *HitOutput) OnEvent(data map[string]interface{}) {
|
||||
o.onEvent = true
|
||||
}
|
||||
|
||||
func (o *HitOutput) OnStop() {
|
||||
o.onStop = true
|
||||
}
|
||||
|
||||
func TestSafeRun(t *testing.T) {
|
||||
runner := &runner{}
|
||||
runner.safeRun(func() {
|
||||
panic("Runner will catch this panic")
|
||||
})
|
||||
}
|
||||
|
||||
func TestOutputOnStart(t *testing.T) {
|
||||
hitOutput := &HitOutput{}
|
||||
hitOutput2 := &HitOutput{}
|
||||
runner := &runner{}
|
||||
runner.addOutput(hitOutput)
|
||||
runner.addOutput(hitOutput2)
|
||||
runner.outputOnStart()
|
||||
if !hitOutput.onStart {
|
||||
t.Error("hitOutput's OnStart has not been called")
|
||||
}
|
||||
if !hitOutput2.onStart {
|
||||
t.Error("hitOutput2's OnStart has not been called")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputOnEevent(t *testing.T) {
|
||||
hitOutput := &HitOutput{}
|
||||
hitOutput2 := &HitOutput{}
|
||||
runner := &runner{}
|
||||
runner.addOutput(hitOutput)
|
||||
runner.addOutput(hitOutput2)
|
||||
runner.outputOnEevent(nil)
|
||||
if !hitOutput.onEvent {
|
||||
t.Error("hitOutput's OnEvent has not been called")
|
||||
}
|
||||
if !hitOutput2.onEvent {
|
||||
t.Error("hitOutput2's OnEvent has not been called")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputOnStop(t *testing.T) {
|
||||
hitOutput := &HitOutput{}
|
||||
hitOutput2 := &HitOutput{}
|
||||
runner := &runner{}
|
||||
runner.addOutput(hitOutput)
|
||||
runner.addOutput(hitOutput2)
|
||||
runner.outputOnStop()
|
||||
if !hitOutput.onStop {
|
||||
t.Error("hitOutput's OnStop has not been called")
|
||||
}
|
||||
if !hitOutput2.onStop {
|
||||
t.Error("hitOutput2's OnStop has not been called")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalRunner(t *testing.T) {
|
||||
taskA := &Task{
|
||||
Weight: 10,
|
||||
Fn: func() {
|
||||
time.Sleep(time.Second)
|
||||
},
|
||||
Name: "TaskA",
|
||||
}
|
||||
tasks := []*Task{taskA}
|
||||
runner := newLocalRunner(tasks, nil, 2, 2)
|
||||
go runner.run()
|
||||
time.Sleep(4 * time.Second)
|
||||
runner.close()
|
||||
}
|
||||
Reference in New Issue
Block a user