Commit a1064b2a authored by Michael de Hoog's avatar Michael de Hoog

Lint

parent 7996695f
...@@ -201,6 +201,7 @@ func TestSend(t *testing.T) { ...@@ -201,6 +201,7 @@ func TestSend(t *testing.T) {
metr: &metrics.NoopTxMetrics{}, metr: &metrics.NoopTxMetrics{},
} }
// track the nonces, and return any expected errors from tx sending
var nonces []uint64 var nonces []uint64
sendTx := func(ctx context.Context, tx *types.Transaction) error { sendTx := func(ctx context.Context, tx *types.Transaction) error {
index := int(tx.Data()[0]) index := int(tx.Data()[0])
...@@ -218,9 +219,7 @@ func TestSend(t *testing.T) { ...@@ -218,9 +219,7 @@ func TestSend(t *testing.T) {
} }
backend.setTxSender(sendTx) backend.setTxSender(sendTx)
ctx := context.Background() // for each factory call, create a candidate from the given test case's tx data
queue := NewQueue[int](mgr, test.max, func(uint64) {})
txIndex := 0 txIndex := 0
factory := TxFactory[int](func(ctx context.Context) (TxCandidate, int, error) { factory := TxFactory[int](func(ctx context.Context) (TxCandidate, int, error) {
var testTx *testTx var testTx *testTx
...@@ -237,6 +236,10 @@ func TestSend(t *testing.T) { ...@@ -237,6 +236,10 @@ func TestSend(t *testing.T) {
}, txIndex - 1, nil }, txIndex - 1, nil
}) })
ctx := context.Background()
queue := NewQueue[int](mgr, test.max, func(uint64) {})
// make all the queue calls given in the test case
start := time.Now() start := time.Now()
for i, c := range test.calls { for i, c := range test.calls {
msg := fmt.Sprintf("Call %d", i) msg := fmt.Sprintf("Call %d", i)
...@@ -258,13 +261,17 @@ func TestSend(t *testing.T) { ...@@ -258,13 +261,17 @@ func TestSend(t *testing.T) {
} }
}() }()
} }
// wait for the queue to drain (all txs complete or failed)
queue.Wait() queue.Wait()
duration := time.Now().Sub(start) duration := time.Since(start)
require.Greater(t, duration, test.total) // expect the execution time within a certain window
require.Less(t, duration, test.total+500*time.Millisecond) require.Greater(t, duration, test.total, "test was faster than expected")
require.Less(t, duration, test.total+500*time.Millisecond, "test was slower than expected")
// check that the nonces match
slices.Sort(nonces) slices.Sort(nonces)
require.Equal(t, test.nonces, nonces) require.Equal(t, test.nonces, nonces, "expected nonces do not match")
require.Equal(t, len(test.txs), txIndex) // check
require.Equal(t, len(test.txs), txIndex, "number of transactions sent does not match")
}) })
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment