Skip to content

Commit

Permalink
Merge pull request #2386 from jorgemmsilva/fix/spam-test
Browse files Browse the repository at this point in the history
tests: minor on-ledger spam cluster test fix
  • Loading branch information
jorgemmsilva authored Apr 24, 2023
2 parents dded57d + 9534fd8 commit 4bb86d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions tools/cluster/tests/inccounter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ func testIncCounterTimelock(t *testing.T, env *ChainEnv) {
e.checkWasmContractCounter(1)

e.postRequest(incHname, isc.Hn("incrementWithDelay"), 0, map[string]interface{}{
varDelay: int32(5), // 5s delay()
varDelay: int32(50), // 50s delay()
})

time.Sleep(300 * time.Millisecond) // equivalent of 3s
time.Sleep(3000 * time.Millisecond) // equivalent of 30s
e.checkWasmContractCounter(1)
time.Sleep(300 * time.Millisecond) // equivalent of 3s
time.Sleep(3000 * time.Millisecond) // equivalent of 30s
e.checkWasmContractCounter(2)
}
38 changes: 19 additions & 19 deletions tools/cluster/tests/spam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func testSpamOnledger(t *testing.T, env *ChainEnv) {
const numRequests = 10_000

// send requests from many different wallets to speed things up
numAccounts := 1000
numAccounts := numRequests / 10
numRequestsPerAccount := numRequests / numAccounts
errCh := make(chan error, numRequests)
txCh := make(chan iotago.Transaction, numRequests)
Expand All @@ -52,33 +52,33 @@ func testSpamOnledger(t *testing.T, env *ChainEnv) {
}
// wait and re-try
createWalletRetries++
i--
time.Sleep(1 * time.Second)
time.Sleep(200 * time.Millisecond)
continue
}

break
}
go func() {
chainClient := env.Chain.SCClient(isc.Hn(nativeIncCounterSCName), keyPair)
retries := 0
for i := 0; i < numRequestsPerAccount; i++ {
tx, err := chainClient.PostRequest(inccounter.FuncIncCounter.Name)
if err != nil {
if retries >= 5 {
errCh <- fmt.Errorf("failed to issue tx, an error 5 times, %w", err)
break
retries := 0
for {
tx, err := chainClient.PostRequest(inccounter.FuncIncCounter.Name)
if err != nil {
if retries >= 5 {
errCh <- fmt.Errorf("failed to issue tx, an error 5 times, %w", err)
break
}
// wait and retry the tx
retries++
time.Sleep(200 * time.Millisecond)
continue
}
// wait and re-try the tx
retries++
i--
time.Sleep(1 * time.Second)
continue
errCh <- err
txCh <- *tx
break
}
retries = 0
errCh <- err
txCh <- *tx
time.Sleep(1 * time.Second) // give time for the indexer to get the new UTXOs (so we don't issue conflicting txs)
time.Sleep(200 * time.Millisecond) // give time for the indexer to get the new UTXOs (so we don't issue conflicting txs)
}
}()
}
Expand All @@ -102,7 +102,7 @@ func testSpamOnledger(t *testing.T, env *ChainEnv) {
res, _, err := env.Chain.Cluster.WaspClient(0).CorecontractsApi.BlocklogGetEventsOfLatestBlock(context.Background(), env.Chain.ChainID.String()).Execute()
require.NoError(t, err)

println(res.Events)
require.Contains(t, res.Events[len(res.Events)-1], fmt.Sprintf("counter = %d", numRequests))
}

// executed in cluster_test.go
Expand Down

0 comments on commit 4bb86d5

Please sign in to comment.