Skip to content

Commit

Permalink
naming
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov committed Dec 19, 2024
1 parent 26b8602 commit 5d5f5cb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
37 changes: 17 additions & 20 deletions wasp/wasp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion wasp/wasp_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions wasp/wasp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand Down

0 comments on commit 5d5f5cb

Please sign in to comment.