From 8bf4761fb65e74690a061eb3878c3e19f72dd409 Mon Sep 17 00:00:00 2001 From: Richard Myers Date: Tue, 10 Oct 2023 14:28:22 +0200 Subject: [PATCH] Fix a flaky async payment triggerer test Sometimes the notifier for node A has not been killed before node A connects. This causes an extra GetPeerInfo message to be sent to the switchboard and the `assert(request3.remoteNodeId == remoteNodeId2)` check to fail when the GetPeerInfo for node A comes first. Just waiting to receive the `AsyncPaymentTimeout` message is not enough. If node A connects after node B then this race does not occur. --- .../main/scala/fr/acinq/eclair/io/PeerReadyNotifier.scala | 2 +- .../eclair/payment/relay/AsyncPaymentTriggererSpec.scala | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/eclair-core/src/main/scala/fr/acinq/eclair/io/PeerReadyNotifier.scala b/eclair-core/src/main/scala/fr/acinq/eclair/io/PeerReadyNotifier.scala index b5812fbb78..81d6c71b5c 100644 --- a/eclair-core/src/main/scala/fr/acinq/eclair/io/PeerReadyNotifier.scala +++ b/eclair-core/src/main/scala/fr/acinq/eclair/io/PeerReadyNotifier.scala @@ -126,7 +126,7 @@ object PeerReadyNotifier { context.log.debug("waiting for peer to connect at block {}", currentBlockHeight) Behaviors.same case Timeout => - context.log.info("timed out waiting for peer to be ready") + context.log.info("timed out waiting for peer to connect") replyTo ! PeerUnavailable(remoteNodeId) Behaviors.stopped } diff --git a/eclair-core/src/test/scala/fr/acinq/eclair/payment/relay/AsyncPaymentTriggererSpec.scala b/eclair-core/src/test/scala/fr/acinq/eclair/payment/relay/AsyncPaymentTriggererSpec.scala index 116a225e43..223b7af750 100644 --- a/eclair-core/src/test/scala/fr/acinq/eclair/payment/relay/AsyncPaymentTriggererSpec.scala +++ b/eclair-core/src/test/scala/fr/acinq/eclair/payment/relay/AsyncPaymentTriggererSpec.scala @@ -176,9 +176,6 @@ class AsyncPaymentTriggererSpec extends ScalaTestWithActorTestKit(ConfigFactory. system.eventStream ! EventStream.Publish(CurrentBlockHeight(BlockHeight(100))) probe.expectMessage(AsyncPaymentTimeout) - // First remote node connects, but does not trigger expired watch - system.eventStream ! EventStream.Publish(PeerConnected(peer.ref.toClassic, remoteNodeId, null)) - // Second remote node connects and triggers watch system.eventStream ! EventStream.Publish(PeerConnected(peer.ref.toClassic, remoteNodeId2, null)) val request3 = switchboard.expectMessageType[Switchboard.GetPeerInfo] @@ -187,6 +184,10 @@ class AsyncPaymentTriggererSpec extends ScalaTestWithActorTestKit(ConfigFactory. peer.expectMessageType[Peer.GetPeerChannels].replyTo ! Peer.PeerChannels(remoteNodeId, Seq(Peer.ChannelInfo(null, NEGOTIATING, null))) probe.expectNoMessage(100 millis) probe2.expectMessage(AsyncPaymentTriggered) + + // First remote node connects, but does not trigger expired watch + system.eventStream ! EventStream.Publish(PeerConnected(peer.ref.toClassic, remoteNodeId, null)) + switchboard.expectNoMessage(100 millis) } test("triggerer treats an unexpected stop of the notifier as a cancel") { f =>