fix: broadcast to all rendezvous at once when spawn done

Change-Id: Ic04bc2f56aa40c2af42a1fdb3c261a10e8346033
This commit is contained in:
buyuxiang
2022-02-17 12:39:55 +08:00
parent 57519be92c
commit 22479e1598
4 changed files with 17 additions and 10 deletions
+11 -6
View File
@@ -26,6 +26,7 @@ type HRPBoomer struct {
plugins []common.Plugin // each task has its own plugin process
pluginsMutex *sync.RWMutex // avoid data race
debug bool
once sync.Once
}
// SetDebug configures whether to log HTTP request and response content.
@@ -57,7 +58,7 @@ func (b *HRPBoomer) Run(testcases ...ITestCase) {
panic(err)
}
rendezvousList := initRendezvous(testcase, int64(b.GetSpawnCount()))
task := b.convertBoomerTask(testcase)
task := b.convertBoomerTask(testcase, rendezvousList)
taskSlice = append(taskSlice, task)
waitRendezvous(rendezvousList)
}
@@ -74,7 +75,7 @@ func (b *HRPBoomer) 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)
config := testcase.Config
@@ -86,6 +87,14 @@ func (b *HRPBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
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{
Name: config.Name,
Weight: config.Weight,
@@ -149,10 +158,6 @@ func (b *HRPBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
} else if stepData.StepType == stepTypeRendezvous {
// rendezvous
// TODO: implement rendezvous in boomer
rendezvous := step.ToStruct().Rendezvous
if !rendezvous.isSpawnDone() && b.IsSpawnDone() {
rendezvous.setSpawnDone()
}
} else {
// request or testcase step
b.RecordSuccess(step.Type(), step.Name(), stepData.Elapsed, stepData.ContentSize)