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

* defer wait group completion

* generate correct number of tx

(cherry picked from commit 654e5652e4)

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
This commit is contained in:
mergify[bot]
2022-12-02 13:33:56 -05:00
committed by GitHub
parent 69d941ea3f
commit 20a2fe6691

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