-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqpool_test.go
52 lines (45 loc) · 1.06 KB
/
qpool_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
package qpool
import (
"context"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
const (
testTimeout = 10 * time.Second
channelTimeout = 5 * time.Second
cleanupTimeout = 500 * time.Millisecond
)
func TestQuantumPool(t *testing.T) {
Convey("Given a new quantum pool", t, func() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
q := NewQ(ctx, 2, 5, &Config{
SchedulingTimeout: time.Second,
})
Reset(func() {
cancel()
if q != nil {
q.Close()
}
})
Convey("When scheduling a simple job", func() {
done := make(chan struct{})
resultCh := q.Schedule("test-job", func() (any, error) {
defer close(done)
return "success", nil
})
select {
case <-time.After(2 * time.Second):
t.Fatal("Test timed out waiting for job completion")
case <-done:
select {
case result := <-resultCh:
So(result.Error, ShouldBeNil)
So(result.Value, ShouldEqual, "success")
case <-time.After(time.Second):
t.Fatal("Test timed out waiting for result")
}
}
})
})
}