Merge pull request #91 from bbx-winner/main

fix: broadcast to all rendezvous at once when spawn done
This commit is contained in:
debugtalk
2022-02-17 20:00:50 +08:00
committed by GitHub
4 changed files with 16 additions and 10 deletions

View File

@@ -57,7 +57,7 @@ func (b *HRPBoomer) Run(testcases ...ITestCase) {
panic(err) panic(err)
} }
rendezvousList := initRendezvous(testcase, int64(b.GetSpawnCount())) rendezvousList := initRendezvous(testcase, int64(b.GetSpawnCount()))
task := b.convertBoomerTask(testcase) task := b.convertBoomerTask(testcase, rendezvousList)
taskSlice = append(taskSlice, task) taskSlice = append(taskSlice, task)
waitRendezvous(rendezvousList) waitRendezvous(rendezvousList)
} }
@@ -74,7 +74,7 @@ func (b *HRPBoomer) Quit() {
b.Boomer.Quit() b.Boomer.Quit()
} }
func (b *HRPBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task { func (b *HRPBoomer) convertBoomerTask(testcase *TestCase, rendezvousList []*Rendezvous) *boomer.Task {
hrpRunner := NewRunner(nil).SetDebug(b.debug) hrpRunner := NewRunner(nil).SetDebug(b.debug)
config := testcase.Config config := testcase.Config
@@ -86,6 +86,14 @@ func (b *HRPBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
b.pluginsMutex.Unlock() b.pluginsMutex.Unlock()
} }
// broadcast to all rendezvous at once when spawn done
go func() {
<-b.GetSpawnDoneChan()
for _, rendezvous := range rendezvousList {
rendezvous.setSpawnDone()
}
}()
return &boomer.Task{ return &boomer.Task{
Name: config.Name, Name: config.Name,
Weight: config.Weight, Weight: config.Weight,
@@ -149,10 +157,6 @@ func (b *HRPBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
} else if stepData.StepType == stepTypeRendezvous { } else if stepData.StepType == stepTypeRendezvous {
// rendezvous // rendezvous
// TODO: implement rendezvous in boomer // TODO: implement rendezvous in boomer
rendezvous := step.ToStruct().Rendezvous
if !rendezvous.isSpawnDone() && b.IsSpawnDone() {
rendezvous.setSpawnDone()
}
} else { } else {
// request or testcase step // request or testcase step
b.RecordSuccess(step.Type(), step.Name(), stepData.Elapsed, stepData.ContentSize) b.RecordSuccess(step.Type(), step.Name(), stepData.Elapsed, stepData.ContentSize)

View File

@@ -3,6 +3,7 @@
## v0.6.1 (2022-02-11) ## v0.6.1 (2022-02-11)
- fix: assertion function errors and json number parse rule - fix: assertion function errors and json number parse rule
- fix: broadcast to all rendezvous at once when spawn done
## v0.6.0 (2022-02-08) ## v0.6.0 (2022-02-08)

View File

@@ -128,8 +128,8 @@ func (b *Boomer) Quit() {
b.localRunner.stop() b.localRunner.stop()
} }
func (b *Boomer) IsSpawnDone() bool { func (b *Boomer) GetSpawnDoneChan() chan struct{} {
return b.localRunner.isSpawnDone return b.localRunner.spawnDone
} }
func (b *Boomer) GetSpawnCount() int { func (b *Boomer) GetSpawnCount() int {

View File

@@ -63,7 +63,7 @@ type runner struct {
spawnCount int // target clients to spawn spawnCount int // target clients to spawn
spawnRate float64 spawnRate float64
loop *Loop // specify running cycles loop *Loop // specify running cycles
isSpawnDone bool spawnDone chan struct{}
outputs []Output outputs []Output
} }
@@ -194,7 +194,7 @@ func (r *localRunner) spawnWorkers(spawnCount int, spawnRate float64, quit chan
} }
} }
r.isSpawnDone = true close(r.spawnDone)
if spawnCompleteFunc != nil { if spawnCompleteFunc != nil {
spawnCompleteFunc() spawnCompleteFunc()
} }
@@ -256,6 +256,7 @@ func newLocalRunner(spawnCount int, spawnRate float64) *localRunner {
spawnCount: spawnCount, spawnCount: spawnCount,
stats: newRequestStats(), stats: newRequestStats(),
outputs: make([]Output, 0), outputs: make([]Output, 0),
spawnDone: make(chan struct{}),
}, },
stopChan: make(chan bool), stopChan: make(chan bool),
} }