-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner_test.go
59 lines (53 loc) · 1.01 KB
/
runner_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
51
52
53
54
55
56
57
58
59
package runner_test
import (
"errors"
"fmt"
"sync"
"time"
runner "github.com/sotirispl/job-runner"
)
func ExampleRunner_first() {
mu := &sync.Mutex{}
counter := 1
printOutSmth := func() error {
mu.Lock()
defer mu.Unlock()
fmt.Printf("executed: %d\n", counter)
counter++
return nil
}
runner := runner.New(2, 3*time.Second, printOutSmth)
runner.Start()
time.Sleep(4 * time.Second)
runner.Stop()
// Output: job 0 starting
// job 1 starting
// executed: 1
// executed: 2
// executed: 3
// executed: 4
// job 0 clossing
// job 1 clossing
}
func ExampleRunner_second() {
mu := &sync.Mutex{}
counter := 1
printOutSmth := func() error {
mu.Lock()
defer mu.Unlock()
if counter == 1 {
counter++
return errors.New("some error")
}
fmt.Printf("executed: %d\n", counter-1)
counter++
return nil
}
runner := runner.New(1, 3*time.Second, printOutSmth)
runner.Start()
time.Sleep(1 * time.Second)
runner.Stop()
// Output: job 0 starting
// job 0 got error: some error
// job 0 clossing
}