mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 05:46:32 +00:00
e2e: add defer to ensure waitgroup is finished. (#9822)
* defer wait group completion * generate correct number of tx
This commit is contained in:
@@ -92,10 +92,12 @@ func loadGenerate(ctx context.Context, txCh chan<- types.Tx, testnet *e2e.Testne
|
||||
// is canceled.
|
||||
func createTxBatch(ctx context.Context, txCh chan<- types.Tx, testnet *e2e.Testnet, id []byte) {
|
||||
wg := &sync.WaitGroup{}
|
||||
genCh := make(chan struct{})
|
||||
for i := 0; i < workerPoolSize; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
for i := 0; i < testnet.LoadTxBatchSize; i++ {
|
||||
defer wg.Done()
|
||||
for range genCh {
|
||||
tx, err := payload.NewBytes(&payload.Payload{
|
||||
Id: id,
|
||||
Size: uint64(testnet.LoadTxSizeBytes),
|
||||
@@ -112,9 +114,16 @@ func createTxBatch(ctx context.Context, txCh chan<- types.Tx, testnet *e2e.Testn
|
||||
return
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
for i := 0; i < testnet.LoadTxBatchSize; i++ {
|
||||
select {
|
||||
case genCh <- struct{}{}:
|
||||
case <-ctx.Done():
|
||||
break
|
||||
}
|
||||
}
|
||||
close(genCh)
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user