-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin_test.go
50 lines (44 loc) · 863 Bytes
/
plugin_test.go
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
48
49
50
package youcrawl
import (
"fmt"
"testing"
"time"
)
type HeartbeatPlugin struct {
}
func (p *HeartbeatPlugin) Run(e *Engine) {
for {
<-time.After(1*time.Second)
fmt.Println("heartbeat log of engine")
}
}
func TestPlugins(t *testing.T) {
e := NewEngine(&EngineOption{
MaxRequest: 3,
Daemon: true,
})
plugin := HeartbeatPlugin{}
e.AddPlugins(&plugin)
e.AddURLs("http://www.example.com")
go e.RunAndWait()
<-time.After(2*time.Second)
e.StopPoolChan <- struct{}{}
}
func TestStatusOutputPlugin_Run(t *testing.T) {
e := NewEngine(&EngineOption{
MaxRequest: 2,
Daemon: false,
})
plugin := StatusOutputPlugin{
LogOutput: true,
}
e.AddPlugins(&plugin)
e.AddURLs("http://www.example.com")
go func() {
for {
fmt.Println(e.GlobalStore.GetValue(STATUS_KEY_SPEED))
<-time.After(1 * time.Second)
}
}()
e.RunAndWait()
}