e2e: add defer to ensure waitgroup is finished. (#9822)

* defer wait group completion

* generate correct number of tx
This commit is contained in:
William Banfield
2022-12-02 13:19:10 -05:00
committed by GitHub
parent 0952a99f45
commit 654e5652e4

View File

@@ -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()
}