Skip to content

Commit 5182402

Browse files
authored
Fix flaky channel integration tests (#1879)
Our test suite is putting a lot of strain on our CI machines, and we start hitting some timeouts. There were places where we would put a 60 seconds timeout on an `awaitCond` but inside we'd still use the default 15 seconds timeout.
1 parent 3bb7ee8 commit 5182402

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

eclair-core/src/test/scala/fr/acinq/eclair/integration/ChannelIntegrationSpec.scala

+25-21
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ abstract class ChannelIntegrationSpec extends IntegrationSpec {
176176
sender.send(nodes("C").register, Register.Forward(sender.ref, htlc.channelId, CMD_FORCECLOSE(sender.ref)))
177177
sender.expectMsgType[RES_SUCCESS[CMD_FORCECLOSE]]
178178
// we then wait for F to detect the unilateral close and go to CLOSING state
179-
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged].currentState == CLOSING, max = 60 seconds)
179+
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSING, max = 60 seconds)
180180
// we generate a few blocks to get the commit tx confirmed
181181
generateBlocks(3, Some(minerAddress))
182182
// we then fulfill the htlc, which will make F redeem it on-chain
@@ -196,8 +196,8 @@ abstract class ChannelIntegrationSpec extends IntegrationSpec {
196196
// we generate blocks to make txs confirm
197197
generateBlocks(2, Some(minerAddress))
198198
// and we wait for the channel to close
199-
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged].currentState == CLOSED, max = 60 seconds)
200-
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged].currentState == CLOSED, max = 60 seconds)
199+
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSED, max = 60 seconds)
200+
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSED, max = 60 seconds)
201201
awaitAnnouncements(1)
202202
}
203203

@@ -212,8 +212,8 @@ abstract class ChannelIntegrationSpec extends IntegrationSpec {
212212
// then we have F unilaterally close the channel
213213
sender.send(nodes("F").register, Register.Forward(sender.ref, htlc.channelId, CMD_FORCECLOSE(sender.ref)))
214214
sender.expectMsgType[RES_SUCCESS[CMD_FORCECLOSE]]
215-
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged].currentState == CLOSING, max = 60 seconds)
216-
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged].currentState == CLOSING, max = 60 seconds)
215+
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSING, max = 60 seconds)
216+
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSING, max = 60 seconds)
217217
// we generate a few blocks to get the commit tx confirmed
218218
generateBlocks(3, Some(minerAddress))
219219
// we then fulfill the htlc (it won't be sent to C, and will be used to pull funds on-chain)
@@ -233,8 +233,8 @@ abstract class ChannelIntegrationSpec extends IntegrationSpec {
233233
// we generate blocks to make txs confirm
234234
generateBlocks(2, Some(minerAddress))
235235
// and we wait for the channel to close
236-
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged].currentState == CLOSED, max = 60 seconds)
237-
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged].currentState == CLOSED, max = 60 seconds)
236+
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSED, max = 60 seconds)
237+
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSED, max = 60 seconds)
238238
awaitAnnouncements(1)
239239
}
240240

@@ -250,8 +250,8 @@ abstract class ChannelIntegrationSpec extends IntegrationSpec {
250250
disconnectCF(htlc.channelId, sender)
251251
// we generate enough blocks to reach the htlc timeout
252252
generateBlocks((htlc.cltvExpiry.toLong - getBlockCount).toInt, Some(minerAddress))
253-
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged].currentState == CLOSING, max = 60 seconds)
254-
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged].currentState == CLOSING, max = 60 seconds)
253+
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSING, max = 60 seconds)
254+
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSING, max = 60 seconds)
255255
sender.send(nodes("C").register, Register.Forward(sender.ref, htlc.channelId, CMD_GETSTATEDATA(ActorRef.noSender)))
256256
val Some(localCommit) = sender.expectMsgType[RES_GETSTATEDATA[DATA_CLOSING]].data.localCommitPublished
257257
// we wait until the commit tx has been broadcast
@@ -282,8 +282,8 @@ abstract class ChannelIntegrationSpec extends IntegrationSpec {
282282
// we generate blocks to make txs confirm
283283
generateBlocks(2, Some(minerAddress))
284284
// and we wait for the channel to close
285-
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged].currentState == CLOSED, max = 60 seconds)
286-
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged].currentState == CLOSED, max = 60 seconds)
285+
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSED, max = 60 seconds)
286+
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSED, max = 60 seconds)
287287
awaitAnnouncements(1)
288288
}
289289

@@ -334,8 +334,8 @@ abstract class ChannelIntegrationSpec extends IntegrationSpec {
334334
// we generate blocks to make tx confirm
335335
generateBlocks(2, Some(minerAddress))
336336
// and we wait for the channel to close
337-
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged].currentState == CLOSED, max = 60 seconds)
338-
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged].currentState == CLOSED, max = 60 seconds)
337+
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSED, max = 60 seconds)
338+
awaitCond(stateListenerF.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSED, max = 60 seconds)
339339
awaitAnnouncements(1)
340340
}
341341

@@ -568,12 +568,16 @@ class StandardChannelIntegrationSpec extends ChannelIntegrationSpec {
568568
fundee.register ! Register.Forward(sender.ref, channelId, CMD_CLOSE(sender.ref, Some(finalPubKeyScriptF)))
569569
sender.expectMsgType[RES_SUCCESS[CMD_CLOSE]]
570570
// we then wait for C and F to negotiate the closing fee
571-
awaitCond(stateListener.expectMsgType[ChannelStateChanged].currentState == CLOSING, max = 60 seconds)
571+
awaitCond(stateListener.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSING, max = 60 seconds)
572572
// and close the channel
573-
generateBlocks(2)
574-
awaitCond(stateListener.expectMsgType[ChannelStateChanged].currentState == CLOSED, max = 60 seconds)
575-
576573
val bitcoinClient = new ExtendedBitcoinClient(bitcoinrpcclient)
574+
awaitCond({
575+
bitcoinClient.getMempool().pipeTo(sender.ref)
576+
sender.expectMsgType[Seq[Transaction]].exists(_.txIn.head.outPoint.txid === fundingOutpoint.txid)
577+
}, max = 20 seconds, interval = 1 second)
578+
generateBlocks(3)
579+
awaitCond(stateListener.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSED, max = 60 seconds)
580+
577581
bitcoinClient.lookForSpendingTx(None, fundingOutpoint.txid, fundingOutpoint.index.toInt).pipeTo(sender.ref)
578582
val closingTx = sender.expectMsgType[Transaction]
579583
assert(closingTx.txOut.map(_.publicKeyScript).toSet === Set(finalPubKeyScriptC, finalPubKeyScriptF))
@@ -619,7 +623,7 @@ class StandardChannelIntegrationSpec extends ChannelIntegrationSpec {
619623
// we generate blocks to make txs confirm
620624
generateBlocks(2)
621625
// and we wait for C's channel to close
622-
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged].currentState == CLOSED, max = 60 seconds)
626+
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSED, max = 60 seconds)
623627
awaitAnnouncements(1)
624628
}
625629

@@ -717,7 +721,7 @@ class AnchorOutputChannelIntegrationSpec extends ChannelIntegrationSpec {
717721
sender.send(nodes("F").register, Register.Forward(sender.ref, channelId, CMD_FORCECLOSE(sender.ref)))
718722
sender.expectMsgType[RES_SUCCESS[CMD_FORCECLOSE]]
719723
// we then wait for C to detect the unilateral close and go to CLOSING state
720-
awaitCond(stateListener.expectMsgType[ChannelStateChanged].currentState == CLOSING, max = 60 seconds)
724+
awaitCond(stateListener.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSING, max = 60 seconds)
721725

722726
val bitcoinClient = new ExtendedBitcoinClient(bitcoinrpcclient)
723727
awaitCond({
@@ -736,7 +740,7 @@ class AnchorOutputChannelIntegrationSpec extends ChannelIntegrationSpec {
736740

737741
// get the claim-remote-output confirmed, then the channel can go to the CLOSED state
738742
generateBlocks(2)
739-
awaitCond(stateListener.expectMsgType[ChannelStateChanged].currentState == CLOSED, max = 60 seconds)
743+
awaitCond(stateListener.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSED, max = 60 seconds)
740744
awaitAnnouncements(1)
741745
}
742746

@@ -781,7 +785,7 @@ class AnchorOutputChannelIntegrationSpec extends ChannelIntegrationSpec {
781785
// we generate blocks to make txs confirm
782786
generateBlocks(2)
783787
// and we wait for C's channel to close
784-
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged].currentState == CLOSED, max = 60 seconds)
788+
awaitCond(stateListenerC.expectMsgType[ChannelStateChanged](max = 60 seconds).currentState == CLOSED, max = 60 seconds)
785789
awaitAnnouncements(1)
786790
}
787791

0 commit comments

Comments
 (0)