Skip to content

Commit

Permalink
More test logs
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bast committed Jul 26, 2023
1 parent 4417d0f commit aa1c68d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class ElectrumClient(
// Sending to the mailbox suspends until the request is picked up and written to the TCP socket.
// We explicitly keep this out of the timeout, which lets us suspend until we're connected to an electrum server.
mailbox.send(Action.SendToServer(Pair(request, replyTo)))
println("request added to mailbox: $request")
// We don't need to catch exceptions thrown by await(): our code only completes it with valid results.
return withTimeoutOrNull(rpcTimeout) { replyTo.await() }
}
Expand Down Expand Up @@ -249,6 +250,7 @@ class ElectrumClient(
?: ServerError(request, JsonRPCError(0, "timeout"))
return when (result) {
is ServerError -> {
println("received error for ${request.method}: ${result.error.message}, disconnecting...")
logger.warning { "received error for ${request.method}: ${result.error.message}, disconnecting..." }
disconnect()
rpcCallMustSucceed(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@ class ElectrumClientTest : LightningTestSuite() {
@Test
fun `disconnect from slow servers on subscription attempts`() = runTest { client ->
// Set a very small timeout that the server won't be able to honor.
println { "setting low RPC timeout" }
println("setting low RPC timeout")
client.setRpcTimeout(1.milliseconds)
val subscriptionJob = async { client.startHeaderSubscription() }
// We automatically disconnect after timing out on the subscription request.
client.connectionStatus.first { it is ElectrumConnectionStatus.Closed }
println { "disconnected from previous electrum server" }
println("disconnected from previous electrum server")
// We reconnect to a healthy server.
client.setRpcTimeout(5.seconds)
client.connect(ElectrumMainnetServerAddress, TcpSocket.Builder())
println { "connected to new electrum server, retry should go through" }
println("connected to new electrum server, retry should go through")
// The subscription call will automatically be retried.
val response = subscriptionJob.await()
assertTrue(BlockHeader.checkProofOfWork(response.header))
Expand Down

0 comments on commit aa1c68d

Please sign in to comment.