-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkerThread_test.go
More file actions
47 lines (38 loc) · 825 Bytes
/
workerThread_test.go
File metadata and controls
47 lines (38 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package workerThread
import (
"errors"
"fmt"
"os"
"testing"
)
// var MaxWorker *int
func TestingMain(m *testing.M) {
//setup
// MaxWorker = flag.Int("mw", 1000, "maxworkers")
code := m.Run() //调用测试用例函数
//teardown
os.Exit(code) //注意: os.Exit不会执行defer
}
//实现接口interface
type PayloadTest struct {
Id int
Name string
Age int
}
func (p *PayloadTest) Do() error {
if p.Name == "" {
return errors.New("payload id and name can not empty.")
}
fmt.Printf("id - %v - name - %v - age - %v\n", p.Id, p.Name, p.Age)
return nil
}
//benchmark test
func BenchmarkWorkerThread(b *testing.B) {
JobQueue = make(chan Job, 1000)
dispatcher := NewDispatcher(1000)
dispatcher.Run()
for i := 0; i < b.N; i++ {
job := Job{&PayloadTest{i, "testWorker", i}}
EnJobQueue(job)
}
}