Skip to content

Commit 51c5e0c

Browse files
committed
Fix payment counts in metrics end-to-end test
The test expected exactly one successful payment after sending the Lightning payment. However, the successful-payment count also includes the deposit and channel funding transaction. Depending on timing, the test could pass because an onchain payment succeeded, or time out because the count had already exceeded one. Confirm both onchain payments and wait for their metrics before sending the Lightning payment. Then require three successful payments with none pending or failed, and include current metrics in the timeout diagnostic. AI assistance: OpenAI Codex.
1 parent 58b5ce7 commit 51c5e0c

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎e2e-tests/tests/e2e.rs‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,18 +1855,22 @@ async fn test_metrics_endpoint() {
18551855
assert!(metrics.contains("ldk_server_total_anchor_channels_reserve_sats 0"));
18561856
assert!(metrics.contains("ldk_server_total_lightning_balance_sats 0"));
18571857

1858-
// Set up channel and make a payment to trigger metrics update
1858+
// Set up the channel and confirm the wallet deposit and channel funding transaction.
18591859
setup_funded_channel(&bitcoind, &server_a, &server_b, 100_000).await;
1860+
mine_and_sync(&bitcoind, &[&server_a, &server_b], 6).await;
18601861

1861-
// Poll for channel, peer and balance metrics.
1862+
// Wait for both onchain payments and the channel, peer and balance metrics.
18621863
let timeout = Duration::from_secs(10);
18631864
let start = std::time::Instant::now();
18641865
loop {
18651866
let metrics = client.get_metrics().await.unwrap();
18661867
if metrics.contains("ldk_server_total_peers_count 1")
18671868
&& metrics.contains("ldk_server_total_channels_count 1")
18681869
&& metrics.contains("ldk_server_total_public_channels_count 1")
1869-
&& metrics.contains("ldk_server_total_payments_count 2")
1870+
&& metrics.contains("ldk_server_total_payments_count 2\n")
1871+
&& metrics.contains("ldk_server_total_successful_payments_count 2\n")
1872+
&& metrics.contains("ldk_server_total_pending_payments_count 0\n")
1873+
&& metrics.contains("ldk_server_total_failed_payments_count 0\n")
18701874
&& !metrics.contains("ldk_server_total_lightning_balance_sats 0")
18711875
&& !metrics.contains("ldk_server_total_onchain_balance_sats 0")
18721876
&& !metrics.contains("ldk_server_spendable_onchain_balance_sats 0")
@@ -1887,12 +1891,15 @@ async fn test_metrics_endpoint() {
18871891

18881892
send_bolt11_payment(&server_a, &server_b, 10_000_000).await;
18891893

1890-
// Wait to receive the PaymentSuccessful event and update metrics
1894+
// The deposit, channel funding and BOLT11 payment must all be counted as successful.
18911895
let timeout = Duration::from_secs(30);
18921896
let start = std::time::Instant::now();
18931897
loop {
18941898
let metrics = client.get_metrics().await.unwrap();
1895-
if metrics.contains("ldk_server_total_successful_payments_count 1")
1899+
if metrics.contains("ldk_server_total_payments_count 3\n")
1900+
&& metrics.contains("ldk_server_total_successful_payments_count 3\n")
1901+
&& metrics.contains("ldk_server_total_pending_payments_count 0\n")
1902+
&& metrics.contains("ldk_server_total_failed_payments_count 0\n")
18961903
&& !metrics.contains("ldk_server_total_lightning_balance_sats 0")
18971904
&& !metrics.contains("ldk_server_total_onchain_balance_sats 0")
18981905
&& !metrics.contains("ldk_server_spendable_onchain_balance_sats 0")
@@ -1901,7 +1908,7 @@ async fn test_metrics_endpoint() {
19011908
break;
19021909
}
19031910
if start.elapsed() > timeout {
1904-
panic!("Timed out waiting for payment metrics to update");
1911+
panic!("Timed out waiting for payment metrics to update. Current metrics:\n{metrics}");
19051912
}
19061913
tokio::time::sleep(Duration::from_millis(500)).await;
19071914
}

0 commit comments

Comments
 (0)