Skip to content

Commit

Permalink
Refactor integration tests (#1494)
Browse files Browse the repository at this point in the history
We don't need one node per force-close scenario, we can use different
channels to the same node which makes the spec simpler.

Force-close tests now have better isolation: they create the channel at
the beginning of the test, and the test ends with that channel closed.

Common parts have been refactored as well, which will make it easier to
add more tests for anchor outputs without duplicating too much code.

These tests have been heavily enriched and refactored; they previously
relied on many unwritten assumptions about event ordering that appeared
as soon as I tried updating them (e.g. to use push_msat to ensure both
sides had an output in the commit tx).
  • Loading branch information
t-bast committed Sep 1, 2020
1 parent 2c43742 commit 153f82c
Show file tree
Hide file tree
Showing 4 changed files with 368 additions and 339 deletions.
Expand Up @@ -24,5 +24,7 @@ import akka.event.DiagnosticLoggingAdapter
* Simple handler that forwards all messages to an actor
*/
class ForwardHandler(actor: ActorRef) extends ReceiveHandler {
override def handle(implicit ctx: ActorContext, log: DiagnosticLoggingAdapter): Receive = { case msg => actor forward msg}
override def handle(implicit ctx: ActorContext, log: DiagnosticLoggingAdapter): Receive = {
case msg => actor forward msg
}
}
Expand Up @@ -36,13 +36,28 @@ class PaymentHandler(nodeParams: NodeParams, register: ActorRef) extends Actor w

override def receive: Receive = normal(defaultHandler.handle(context, log))

def normal(handle: Receive): Receive = handle orElse {
private def addReceiveHandler(handle: Receive): Receive = {
case handler: ReceiveHandler =>
log.info(s"registering handler of type=${handler.getClass.getSimpleName}")
// NB: the last handler that was added will be the first called
context become normal(handler.handle(context, log) orElse handle)
}

/**
* This is a bit subtle because we want handlers to be as generic as possible, but we also want to catch a particular
* type of message (the [[ReceiveHandler]]s themselves) to update the list of handlers.
*
* That's why we *prepend* new handlers, but after a first special handler (addReceiveHandler):
*
* {{{
* paymentHandler ! handler1
* paymentHandler ! handler2
* paymentHandler ! handler3
* // the current handler is now addReceiveHandler :: handler3 :: handler2 :: handler1
* }}}
*/
def normal(handle: Receive): Receive = addReceiveHandler(handle) orElse handle

override def mdc(currentMessage: Any): MDC = Logs.mdc(category_opt = Some(Logs.LogCategory.PAYMENT))
}

Expand Down
6 changes: 3 additions & 3 deletions eclair-core/src/test/resources/logback-test.xml
Expand Up @@ -50,9 +50,9 @@
<logger name="fr.acinq.eclair.db.FileBackupHandler" level="OFF"/>

<root level="INFO">
<!--appender-ref ref="FILE"/>
<appender-ref ref="CONSOLEWARN"/>
<appender-ref ref="CONSOLE"/-->
<!--<appender-ref ref="FILE"/>-->
<!--<appender-ref ref="CONSOLEWARN"/>-->
<!--<appender-ref ref="CONSOLE"/>-->
</root>

</configuration>

0 comments on commit 153f82c

Please sign in to comment.