-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskExecutor_test.go
More file actions
42 lines (29 loc) · 797 Bytes
/
Copy pathtaskExecutor_test.go
File metadata and controls
42 lines (29 loc) · 797 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
package executor
import (
"fmt"
"testing"
"time"
"gotest.tools/assert"
)
type TaskImpl struct {
input int
}
func (t *TaskImpl) Exec() (int, error) {
time.Sleep(3 * time.Second)
return t.input * t.input, nil
}
func (t *TaskImpl) Hash(f func(string) int) []int {
return []int{t.input}
}
func TestLimitedThread(t *testing.T) {
expected := []int{1, 4, 4, 9, 16, 25, 36, 49, 64, 81, 4}
e := NewTaskExecutor[int](100)
e.Progress(func(p int) {
fmt.Println("progress", p)
})
results, _ := e.ExecuteTask(&TaskImpl{1}, &TaskImpl{2}, &TaskImpl{2}, &TaskImpl{3}, &TaskImpl{4}, &TaskImpl{5}, &TaskImpl{6}, &TaskImpl{7}, &TaskImpl{8}, &TaskImpl{9}, &TaskImpl{2})
assert.Equal(t, len(expected), len(results))
for x := range results {
assert.Equal(t, expected[x], results[x])
}
}