From 5d5f5cb0e54f0631e128046e4e0ee0b032da18bc Mon Sep 17 00:00:00 2001 From: skudasov Date: Thu, 19 Dec 2024 07:07:52 +0100 Subject: [PATCH] naming --- wasp/wasp.go | 37 +++++++++++++++++-------------------- wasp/wasp_bench_test.go | 2 +- wasp/wasp_test.go | 12 ++++++------ 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/wasp/wasp.go b/wasp/wasp.go index b9edb1acd..fbb140ed2 100644 --- a/wasp/wasp.go +++ b/wasp/wasp.go @@ -350,26 +350,23 @@ func NewGenerator(cfg *Config) (*Generator, error) { return g, nil } -// runRPSLoop initiates the generator's RPS loop, noop if load type is VU. +// runGunLoop runs the generator's Gun loop // It manages request pacing for RPS after the first segment is loaded. -func (g *Generator) runRPSLoop() { - switch g.Cfg.LoadType { - case RPS: - g.ResponsesWaitGroup.Add(1) - // we run pacedCall controlled by stats.CurrentRPS - go func() { - for { - select { - case <-g.ResponsesCtx.Done(): - g.ResponsesWaitGroup.Done() - g.Log.Info().Msg("RPS generator has stopped") - return - default: - g.pacedCall() - } +func (g *Generator) runGunLoop() { + g.ResponsesWaitGroup.Add(1) + // we run pacedCall controlled by stats.CurrentRPS + go func() { + for { + select { + case <-g.ResponsesCtx.Done(): + g.ResponsesWaitGroup.Done() + g.Log.Info().Msg("RPS generator has stopped") + return + default: + g.pacedCall() } - }() - } + } + }() } // runSetupWithTimeout executes the VirtualUser's setup within the configured timeout. @@ -485,9 +482,9 @@ func (g *Generator) processSegment() bool { newRateLimit := ratelimit.New(int(g.currentSegment.From), ratelimit.Per(g.Cfg.RateLimitUnitDuration), ratelimit.WithoutSlack) g.rl.Store(&newRateLimit) g.stats.CurrentRPS.Store(g.currentSegment.From) - // start RPS loop once, in next segments we control it using g.rl ratelimiter + // start Gun loop once, in next segments we control it using g.rl ratelimiter g.rpsLoopOnce.Do(func() { - g.runRPSLoop() + g.runGunLoop() }) case VU: oldVUs := g.stats.CurrentVUs.Load() diff --git a/wasp/wasp_bench_test.go b/wasp/wasp_bench_test.go index 897a1fe39..88b66f137 100644 --- a/wasp/wasp_bench_test.go +++ b/wasp/wasp_bench_test.go @@ -21,7 +21,7 @@ func BenchmarkPacedCall(b *testing.B) { Gun: NewMockGun(&MockGunConfig{}), }) require.NoError(b, err) - gen.runRPSLoop() + gen.runGunLoop() b.ResetTimer() for i := 0; i < b.N; i++ { gen.pacedCall() diff --git a/wasp/wasp_test.go b/wasp/wasp_test.go index 38fe0d394..537bdeb9f 100644 --- a/wasp/wasp_test.go +++ b/wasp/wasp_test.go @@ -449,13 +449,13 @@ func TestSmokeStaticRPSSchedulePrecision(t *testing.T) { require.NoError(t, err) _, failed := gen.Run(true) require.Equal(t, false, failed) - require.GreaterOrEqual(t, gen.Stats().Success.Load(), int64(960)) + require.GreaterOrEqual(t, gen.Stats().Success.Load(), int64(950)) require.LessOrEqual(t, gen.Stats().Success.Load(), int64(1010)) require.Equal(t, gen.Stats().Failed.Load(), int64(0)) require.Equal(t, gen.Stats().CallTimeout.Load(), int64(0)) okData, _, failResponses := convertResponsesData(gen) - require.GreaterOrEqual(t, len(okData), 960) + require.GreaterOrEqual(t, len(okData), 950) require.LessOrEqual(t, len(okData), 1010) require.Empty(t, failResponses) require.Empty(t, gen.Errors()) @@ -475,14 +475,14 @@ func TestSmokeCustomUnitPrecision(t *testing.T) { _, failed := gen.Run(true) require.Equal(t, false, failed) stats := gen.Stats() - require.GreaterOrEqual(t, stats.Success.Load(), int64(4960)) + require.GreaterOrEqual(t, stats.Success.Load(), int64(4950)) require.LessOrEqual(t, stats.Success.Load(), int64(5010)) require.Equal(t, stats.Failed.Load(), int64(0)) require.Equal(t, stats.CallTimeout.Load(), int64(0)) require.Equal(t, stats.CurrentTimeUnit, gen.Cfg.RateLimitUnitDuration.Nanoseconds()) okData, _, failResponses := convertResponsesData(gen) - require.GreaterOrEqual(t, len(okData), 4960) + require.GreaterOrEqual(t, len(okData), 4950) require.LessOrEqual(t, len(okData), 5010) require.Empty(t, failResponses) require.Empty(t, gen.Errors()) @@ -501,13 +501,13 @@ func TestSmokeStaticRPSScheduleIsNotBlocking(t *testing.T) { require.NoError(t, err) _, failed := gen.Run(true) require.Equal(t, false, failed) - require.GreaterOrEqual(t, gen.Stats().Success.Load(), int64(960)) + require.GreaterOrEqual(t, gen.Stats().Success.Load(), int64(950)) require.LessOrEqual(t, gen.Stats().Success.Load(), int64(1010)) require.Equal(t, gen.Stats().Failed.Load(), int64(0)) require.Equal(t, gen.Stats().CallTimeout.Load(), int64(0)) okData, _, failResponses := convertResponsesData(gen) - require.GreaterOrEqual(t, len(okData), 960) + require.GreaterOrEqual(t, len(okData), 950) require.LessOrEqual(t, len(okData), 1010) require.Empty(t, failResponses) require.Empty(t, gen.Errors())