MCPcopy
hub / github.com/grafana/k6 / TestExecutionStateVUIDs

Function TestExecutionStateVUIDs

lib/executor/execution_test.go:21–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestExecutionStateVUIDs(t *testing.T) {
22 t.Parallel()
23
24 testCases := []struct {
25 seq, seg string
26 }{
27 {},
28 {seq: "0,1/4,3/4,1", seg: "0:1/4"},
29 {seq: "0,0.3,0.5,0.6,0.7,0.8,0.9,1", seg: "0.5:0.6"},
30 }
31
32 for _, tc := range testCases {
33 t.Run(fmt.Sprintf("seq:%s;segment:%s", tc.seq, tc.seg), func(t *testing.T) {
34 t.Parallel()
35 ess, err := lib.NewExecutionSegmentSequenceFromString(tc.seq)
36 require.NoError(t, err)
37 segment, err := lib.NewExecutionSegmentFromString(tc.seg)
38 require.NoError(t, err)
39 et, err := lib.NewExecutionTuple(segment, &ess)
40 require.NoError(t, err)
41
42 start, offsets, _ := et.GetStripedOffsets()
43 es := lib.NewExecutionState(nil, et, 0, 0)
44
45 idl, idg := es.GetUniqueVUIdentifiers()
46 assert.EqualValues(t, 1, idl)
47 expGlobal := start + 1
48 assert.EqualValues(t, expGlobal, idg)
49
50 idl, idg = es.GetUniqueVUIdentifiers()
51 assert.EqualValues(t, 2, idl)
52 expGlobal += offsets[0]
53 assert.EqualValues(t, expGlobal, idg)
54
55 idl, idg = es.GetUniqueVUIdentifiers()
56 assert.EqualValues(t, 3, idl)
57 expGlobal += offsets[0]
58 assert.EqualValues(t, expGlobal, idg)
59
60 seed := time.Now().UnixNano()
61 r := rand.New(rand.NewSource(seed))
62 t.Logf("Random source seeded with %d\n", seed)
63 count := 100 + r.Intn(50)
64
65 synctest.Test(t, func(t *testing.T) {
66 for range count {
67 go func() {
68 es.GetUniqueVUIdentifiers()
69 }()
70 }
71 synctest.Wait()
72 idl, idg = es.GetUniqueVUIdentifiers()
73 assert.EqualValues(t, 4+count, idl)
74 assert.EqualValues(t, (3+count)*int(offsets[0])+int(start+1), idg)
75 })
76 })
77 }
78}

Callers

nothing calls this directly

Calls 9

GetStripedOffsetsMethod · 0.95
NewExecutionTupleFunction · 0.92
NewExecutionStateFunction · 0.92
LogfMethod · 0.80
RunMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…