Skip to content

Commit 58cf07e

Browse files
committed
test: Fix flakes
1 parent 6c57d8a commit 58cf07e

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

plugin/evm/atomic/vm/gossiper_atomic_gossiping_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ func TestMempoolAtmTxsAppGossipHandlingDiscardedTx(t *testing.T) {
121121
}()
122122

123123
var (
124-
txGossiped int
125-
txGossipedLock sync.Mutex
126-
txRequested bool
124+
txGossiped int
125+
txGossipedLock sync.Mutex
126+
txRequested bool
127+
txRequestedLock sync.Mutex
127128
)
128129
tvm.AppSender.CantSendAppGossip = false
129130
tvm.AppSender.SendAppGossipF = func(context.Context, commonEng.SendConfig, []byte) error {
@@ -134,6 +135,9 @@ func TestMempoolAtmTxsAppGossipHandlingDiscardedTx(t *testing.T) {
134135
return nil
135136
}
136137
tvm.AppSender.SendAppRequestF = func(context.Context, set.Set[ids.NodeID], uint32, []byte) error {
138+
txRequestedLock.Lock()
139+
defer txRequestedLock.Unlock()
140+
137141
txRequested = true
138142
return nil
139143
}
@@ -177,13 +181,16 @@ func TestMempoolAtmTxsAppGossipHandlingDiscardedTx(t *testing.T) {
177181
// Conflicting tx must be submitted over the API to be included in push gossip.
178182
// (i.e., txs received via p2p are not included in push gossip)
179183
// This test adds it directly to the mempool + gossiper to simulate that.
180-
vm.AtomicMempool.AddRemoteTx(conflictingTx)
184+
require.NoError(vm.AtomicMempool.AddRemoteTx(conflictingTx))
181185
vm.AtomicTxPushGossiper.Add(conflictingTx)
182-
time.Sleep(500 * time.Millisecond)
186+
vm.AtomicTxPushGossiper.Gossip(context.Background()) // We don't want to wait to gossip.
183187

184188
vm.Ctx.Lock.Lock()
185189

190+
txRequestedLock.Lock()
186191
require.False(txRequested, "tx shouldn't be requested")
192+
txRequestedLock.Unlock()
193+
187194
txGossipedLock.Lock()
188195
require.Equal(1, txGossiped, "conflicting tx should have been gossiped")
189196
txGossipedLock.Unlock()

plugin/evm/gossiper_eth_gossiping_test.go

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,21 @@ func TestMempoolEthTxsAppGossipHandling(t *testing.T) {
9393
vm.txPool.SetMinFee(common.Big0)
9494

9595
var (
96-
wg sync.WaitGroup
9796
txRequested bool
97+
txResponded bool
98+
statusLock sync.Mutex
9899
)
99100
tvm.AppSender.CantSendAppGossip = false
100101
tvm.AppSender.SendAppRequestF = func(context.Context, set.Set[ids.NodeID], uint32, []byte) error {
102+
statusLock.Lock()
103+
defer statusLock.Unlock()
101104
txRequested = true
102105
return nil
103106
}
104-
wg.Add(1)
105107
tvm.AppSender.SendAppGossipF = func(context.Context, commonEng.SendConfig, []byte) error {
106-
wg.Done()
108+
statusLock.Lock()
109+
defer statusLock.Unlock()
110+
txResponded = true
107111
return nil
108112
}
109113

@@ -113,26 +117,9 @@ func TestMempoolEthTxsAppGossipHandling(t *testing.T) {
113117
// Txs must be submitted over the API to be included in push gossip.
114118
// (i.e., txs received via p2p are not included in push gossip)
115119
require.NoError(vm.eth.APIBackend.SendTx(context.Background(), tx))
120+
require.NoError(vm.ethTxPushGossiper.Get().Gossip(context.Background()))
121+
statusLock.Lock()
116122
require.False(txRequested, "tx should not be requested")
117-
118-
// wait for transaction to be re-gossiped
119-
attemptAwait(t, &wg, 5*time.Second)
120-
}
121-
122-
func attemptAwait(t *testing.T, wg *sync.WaitGroup, delay time.Duration) {
123-
ticker := make(chan struct{})
124-
125-
// Wait for [wg] and then close [ticket] to indicate that
126-
// the wait group has finished.
127-
go func() {
128-
wg.Wait()
129-
close(ticker)
130-
}()
131-
132-
select {
133-
case <-time.After(delay):
134-
require.FailNow(t, "Timed out waiting for wait group to complete")
135-
case <-ticker:
136-
// The wait group completed without issue
137-
}
123+
require.True(txResponded, "expected tx to be gossiped")
124+
statusLock.Unlock()
138125
}

scripts/known_flakes.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
TestClientCancelWebsocket
22
TestClientWebsocketLargeMessage
33
TestGolangBindings
4-
TestMempoolAtmTxsAppGossipHandlingDiscardedTx
5-
TestMempoolEthTxsAppGossipHandling
64
TestResumeSyncAccountsTrieInterrupted
75
TestResyncNewRootAfterDeletes
86
TestTransactionSkipIndexing
9-
TestUpdatedKeyfileContents
107
TestWaitDeployedCornerCases
118
TestWebsocketLargeRead

0 commit comments

Comments
 (0)