Skip to content

Commit e8f478b

Browse files
benthecarmanclaude
andcommitted
Clean up tables in PostgreSQL integration tests
Drop test tables at the start and end of each integration test to prevent stale data from prior runs causing WalletSetupFailed errors when seeds change between runs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f0e93be commit e8f478b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/integration_tests_postgres.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,19 @@ fn test_connection_string() -> String {
1818
.unwrap_or_else(|_| "host=localhost user=postgres password=postgres".to_string())
1919
}
2020

21+
async fn drop_table(table_name: &str) {
22+
let connection_string = format!("{} dbname=ldk_node", test_connection_string());
23+
let (client, connection) =
24+
tokio_postgres::connect(&connection_string, tokio_postgres::NoTls).await.unwrap();
25+
tokio::spawn(connection);
26+
let _ = client.execute(&format!("DROP TABLE IF EXISTS {table_name}"), &[]).await;
27+
}
28+
2129
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
2230
async fn channel_full_cycle_with_postgres_store() {
31+
drop_table("channel_cycle_a").await;
32+
drop_table("channel_cycle_b").await;
33+
2334
let (bitcoind, electrsd) = common::setup_bitcoind_and_electrsd();
2435
println!("== Node A ==");
2536
let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap());
@@ -62,10 +73,15 @@ async fn channel_full_cycle_with_postgres_store() {
6273
false,
6374
)
6475
.await;
76+
77+
drop_table("channel_cycle_a").await;
78+
drop_table("channel_cycle_b").await;
6579
}
6680

6781
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
6882
async fn postgres_node_restart() {
83+
drop_table("restart_test").await;
84+
6985
let (bitcoind, electrsd) = common::setup_bitcoind_and_electrsd();
7086
let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap());
7187
let connection_string = test_connection_string();
@@ -133,4 +149,6 @@ async fn postgres_node_restart() {
133149
assert_eq!(expected_balance_sats, node.list_balances().spendable_onchain_balance_sats);
134150

135151
node.stop().unwrap();
152+
153+
drop_table("restart_test").await;
136154
}

0 commit comments

Comments
 (0)