diff --git a/components/providers/http_scenario/decode.go b/components/providers/http_scenario/decode.go index fbed6f143..24a664d04 100644 --- a/components/providers/http_scenario/decode.go +++ b/components/providers/http_scenario/decode.go @@ -71,7 +71,7 @@ func convertScenarioToAmmo(sc ScenarioConfig, reqs map[string]RequestConfig) (*A iter := mp.NewNextIterator(time.Now().UnixNano()) result := &Ammo{name: sc.Name, minWaitingTime: time.Millisecond * time.Duration(sc.MinWaitingTime)} for _, sh := range sc.Requests { - name, cnt, err := parseShootName(sh) + name, cnt, sleep, err := parseShootName(sh) if err != nil { return nil, fmt.Errorf("failed to parse shoot %s: %w", sh, err) } @@ -84,6 +84,9 @@ func convertScenarioToAmmo(sc ScenarioConfig, reqs map[string]RequestConfig) (*A return nil, fmt.Errorf("request %s not found", name) } r := convertConfigToRequest(req, iter) + if sleep > 0 { + r.sleep += time.Millisecond * time.Duration(sleep) + } for i := 0; i < cnt; i++ { result.Requests = append(result.Requests, r) } @@ -117,19 +120,26 @@ func convertConfigToRequest(req RequestConfig, iter mp.Iterator) Request { return result } -func parseShootName(shoot string) (string, int, error) { +func parseShootName(shoot string) (string, int, int, error) { name, args, err := str.ParseStringFunc(shoot) if err != nil { - return "", 0, err + return "", 0, 0, err } cnt := 1 if len(args) > 0 && args[0] != "" { cnt, err = strconv.Atoi(args[0]) if err != nil { - return "", 0, fmt.Errorf("failed to parse count: %w", err) + return "", 0, 0, fmt.Errorf("failed to parse count: %w", err) + } + } + sleep := 0 + if len(args) > 1 && args[1] != "" { + sleep, err = strconv.Atoi(args[1]) + if err != nil { + return "", 0, 0, fmt.Errorf("failed to parse count: %w", err) } } - return name, cnt, nil + return name, cnt, sleep, nil } func spreadNames(input []ScenarioConfig) (map[string]int, int) { diff --git a/components/providers/http_scenario/decode_test.go b/components/providers/http_scenario/decode_test.go index 2488ad0de..bf21dca2e 100644 --- a/components/providers/http_scenario/decode_test.go +++ b/components/providers/http_scenario/decode_test.go @@ -113,13 +113,14 @@ func TestParseShootName(t *testing.T) { for _, tc := range testCases { t.Run(tc.input, func(t *testing.T) { - name, cnt, err := parseShootName(tc.input) + name, cnt, sleep, err := parseShootName(tc.input) if tc.wantErr { assert.Error(t, err) return } assert.NoError(t, err) assert.Equal(t, tc.wantName, name, "Name does not match for input: %s", tc.input) + assert.Equal(t, tc.wantSleep, sleep, "Name does not match for input: %s", tc.input) assert.Equal(t, tc.wantCnt, cnt, "Count does not match for input: %s", tc.input) }) } @@ -198,9 +199,9 @@ func Test_convertScenarioToAmmo(t *testing.T) { Requests: []Request{ convertConfigToRequestWithSleep(req1, 0), convertConfigToRequestWithSleep(req2, 0), - convertConfigToRequestWithSleep(req2, 0), - convertConfigToRequestWithSleep(req2, 0), - convertConfigToRequestWithSleep(req2, time.Millisecond*500), + convertConfigToRequestWithSleep(req2, time.Millisecond*100), + convertConfigToRequestWithSleep(req2, time.Millisecond*100), + convertConfigToRequestWithSleep(req2, time.Millisecond*600), }, }, wantErr: false,