-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
scheduler_int_test.go
91 lines (80 loc) · 2.54 KB
/
scheduler_int_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package execution
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/testutils"
"go.k6.io/k6/lib/testutils/minirunner"
"go.k6.io/k6/metrics"
)
func getBogusTestRunState(tb testing.TB) *lib.TestRunState {
reg := metrics.NewRegistry()
piState := &lib.TestPreInitState{
Logger: testutils.NewLogger(tb),
RuntimeOptions: lib.RuntimeOptions{},
Registry: reg,
BuiltinMetrics: metrics.RegisterBuiltinMetrics(reg),
}
return &lib.TestRunState{
TestPreInitState: piState,
Options: lib.Options{},
Runner: &minirunner.MiniRunner{},
RunTags: piState.Registry.RootTagSet(),
}
}
// Just a lib.PausableExecutor implementation that can return an error
type pausableExecutor struct {
lib.Executor
err error
}
func (p pausableExecutor) SetPaused(bool) error {
return p.err
}
func TestSetPaused(t *testing.T) {
t.Parallel()
t.Run("second pause is an error", func(t *testing.T) {
t.Parallel()
testRunState := getBogusTestRunState(t)
sched, err := NewScheduler(testRunState)
require.NoError(t, err)
sched.executors = []lib.Executor{pausableExecutor{err: nil}}
require.NoError(t, sched.SetPaused(true))
err = sched.SetPaused(true)
require.Error(t, err)
require.Contains(t, err.Error(), "execution is already paused")
})
t.Run("unpause at the start is an error", func(t *testing.T) {
t.Parallel()
testRunState := getBogusTestRunState(t)
sched, err := NewScheduler(testRunState)
require.NoError(t, err)
sched.executors = []lib.Executor{pausableExecutor{err: nil}}
err = sched.SetPaused(false)
require.Error(t, err)
require.Contains(t, err.Error(), "execution wasn't paused")
})
t.Run("second unpause is an error", func(t *testing.T) {
t.Parallel()
testRunState := getBogusTestRunState(t)
sched, err := NewScheduler(testRunState)
require.NoError(t, err)
sched.executors = []lib.Executor{pausableExecutor{err: nil}}
require.NoError(t, sched.SetPaused(true))
require.NoError(t, sched.SetPaused(false))
err = sched.SetPaused(false)
require.Error(t, err)
require.Contains(t, err.Error(), "execution wasn't paused")
})
t.Run("an error on pausing is propagated", func(t *testing.T) {
t.Parallel()
testRunState := getBogusTestRunState(t)
sched, err := NewScheduler(testRunState)
require.NoError(t, err)
expectedErr := errors.New("testing pausable executor error")
sched.executors = []lib.Executor{pausableExecutor{err: expectedErr}}
err = sched.SetPaused(true)
require.Error(t, err)
require.Equal(t, err, expectedErr)
})
}