Commit ae24f01d authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-service: Remove txmgr queue timing test (#13032)

The tests in the txmgr queue were asserting that calls complete within a certain time window. This was causing flakes, particularly when the CI runner was under load. Generally we should avoid tests that use fixed durations as a way of asserting that code functions correctly.
parent 1c36df3e
...@@ -58,12 +58,11 @@ func (b *mockBackendWithNonce) NonceAt(ctx context.Context, account common.Addre ...@@ -58,12 +58,11 @@ func (b *mockBackendWithNonce) NonceAt(ctx context.Context, account common.Addre
func TestQueue_Send(t *testing.T) { func TestQueue_Send(t *testing.T) {
testCases := []struct { testCases := []struct {
name string // name of the test name string // name of the test
max uint64 // max concurrency of the queue max uint64 // max concurrency of the queue
calls []queueCall // calls to the queue calls []queueCall // calls to the queue
txs []testTx // txs to generate from the factory (and potentially error in send) txs []testTx // txs to generate from the factory (and potentially error in send)
nonces []uint64 // expected sent tx nonces after all calls are made nonces []uint64 // expected sent tx nonces after all calls are made
total time.Duration // approx. total time it should take to complete all queue calls
}{ }{
{ {
name: "success", name: "success",
...@@ -77,7 +76,6 @@ func TestQueue_Send(t *testing.T) { ...@@ -77,7 +76,6 @@ func TestQueue_Send(t *testing.T) {
{}, {},
}, },
nonces: []uint64{0, 1}, nonces: []uint64{0, 1},
total: 1 * time.Second,
}, },
{ {
name: "no limit", name: "no limit",
...@@ -91,7 +89,6 @@ func TestQueue_Send(t *testing.T) { ...@@ -91,7 +89,6 @@ func TestQueue_Send(t *testing.T) {
{}, {},
}, },
nonces: []uint64{0, 1}, nonces: []uint64{0, 1},
total: 1 * time.Second,
}, },
{ {
name: "single threaded", name: "single threaded",
...@@ -105,7 +102,6 @@ func TestQueue_Send(t *testing.T) { ...@@ -105,7 +102,6 @@ func TestQueue_Send(t *testing.T) {
{}, {},
}, },
nonces: []uint64{0}, nonces: []uint64{0},
total: 1 * time.Second,
}, },
{ {
name: "single threaded blocking", name: "single threaded blocking",
...@@ -122,7 +118,6 @@ func TestQueue_Send(t *testing.T) { ...@@ -122,7 +118,6 @@ func TestQueue_Send(t *testing.T) {
{}, {},
}, },
nonces: []uint64{0, 1, 2}, nonces: []uint64{0, 1, 2},
total: 3 * time.Second,
}, },
{ {
name: "dual threaded blocking", name: "dual threaded blocking",
...@@ -143,7 +138,6 @@ func TestQueue_Send(t *testing.T) { ...@@ -143,7 +138,6 @@ func TestQueue_Send(t *testing.T) {
{}, {},
}, },
nonces: []uint64{0, 1, 2, 3, 4}, nonces: []uint64{0, 1, 2, 3, 4},
total: 3 * time.Second,
}, },
{ {
name: "subsequent txs fail after tx failure", name: "subsequent txs fail after tx failure",
...@@ -159,7 +153,6 @@ func TestQueue_Send(t *testing.T) { ...@@ -159,7 +153,6 @@ func TestQueue_Send(t *testing.T) {
{}, {},
}, },
nonces: []uint64{0, 1}, nonces: []uint64{0, 1},
total: 1 * time.Second,
}, },
} }
for _, test := range testCases { for _, test := range testCases {
...@@ -209,7 +202,6 @@ func TestQueue_Send(t *testing.T) { ...@@ -209,7 +202,6 @@ func TestQueue_Send(t *testing.T) {
queue := NewQueue[int](ctx, mgr, test.max) queue := NewQueue[int](ctx, mgr, test.max)
// make all the queue calls given in the test case // make all the queue calls given in the test case
start := time.Now()
receiptChs := make([]chan TxReceipt[int], len(test.calls)) receiptChs := make([]chan TxReceipt[int], len(test.calls))
for i, c := range test.calls { for i, c := range test.calls {
msg := fmt.Sprintf("Call %d", i) msg := fmt.Sprintf("Call %d", i)
...@@ -223,10 +215,6 @@ func TestQueue_Send(t *testing.T) { ...@@ -223,10 +215,6 @@ func TestQueue_Send(t *testing.T) {
} }
// wait for the queue to drain (all txs complete or failed) // wait for the queue to drain (all txs complete or failed)
_ = queue.Wait() _ = queue.Wait()
duration := time.Since(start)
// expect the execution time within a certain window
now := time.Now()
require.WithinDuration(t, now.Add(test.total), now.Add(duration), 500*time.Millisecond, "unexpected queue transaction timing")
// check that the nonces match // check that the nonces match
slices.Sort(nonces) slices.Sort(nonces)
require.Equal(t, test.nonces, nonces, "expected nonces do not match") require.Equal(t, test.nonces, nonces, "expected nonces do 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