-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathconstant_vus_test.go
More file actions
58 lines (48 loc) · 1.29 KB
/
constant_vus_test.go
File metadata and controls
58 lines (48 loc) · 1.29 KB
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
package executor
import (
"context"
"sync"
"testing"
"testing/synctest"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/guregu/null.v3"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/types"
)
func getTestConstantVUsConfig() ConstantVUsConfig {
return ConstantVUsConfig{
BaseConfig: BaseConfig{GracefulStop: types.NullDurationFrom(100 * time.Millisecond)},
VUs: null.IntFrom(10),
Duration: types.NullDurationFrom(1 * time.Second),
}
}
func TestConstantVUsRun(t *testing.T) {
t.Parallel()
synctest.Test(t, func(t *testing.T) {
var result sync.Map
runner := simpleRunner(func(ctx context.Context, state *lib.State) error {
select {
case <-ctx.Done():
return nil
default:
}
currIter, _ := result.LoadOrStore(state.VUID, uint64(0))
result.Store(state.VUID, currIter.(uint64)+1)
time.Sleep(210 * time.Millisecond)
return nil
})
test := setupExecutorTest(t, "", "", lib.Options{}, runner, getTestConstantVUsConfig())
defer test.cancel()
require.NoError(t, test.executor.Run(test.ctx, nil))
var totalIters uint64
result.Range(func(_, value any) bool {
vuIters := value.(uint64)
assert.Equal(t, uint64(5), vuIters)
totalIters += vuIters
return true
})
assert.Equal(t, uint64(50), totalIters)
})
}