mod common;
use common::TestServer;
use hyperdb_api_core::client::{AsyncClient, Config};
use hyperdb_api_core::types::oids;
#[tokio::test(flavor = "current_thread")]
async fn execute_prepared_after_abandoned_copy_in() {
let server = TestServer::new().expect("failed to create test server");
let config: Config = server.config();
let client = AsyncClient::connect(&config)
.await
.expect("failed to connect async client");
client
.exec("CREATE TABLE pstmt_target (id INT NOT NULL)")
.await
.expect("create pstmt_target");
client
.exec("CREATE TABLE copy_target (id INT NOT NULL)")
.await
.expect("create copy_target");
let stmt = client
.prepare_typed("INSERT INTO pstmt_target VALUES ($1)", &[oids::INT])
.await
.expect("prepare");
{
let _writer = client
.copy_in("copy_target", &["id"])
.await
.expect("start copy_in");
}
let affected = client
.execute_prepared_no_result(&stmt, [Some(vec![0, 0, 0, 42])].as_slice())
.await
.expect("execute_prepared_no_result after abandoned copy");
assert_eq!(
affected, 1,
"execute_prepared_no_result must report exactly one row inserted \
(this is the test signal that the drain fired and the wire was \
clean before Bind/Execute went out)",
);
let count: u64 = client
.exec("INSERT INTO pstmt_target VALUES (99)")
.await
.expect("plain exec after drained copy cancel");
assert_eq!(count, 1, "follow-up exec should affect one row");
let rows = client
.query("SELECT id FROM pstmt_target ORDER BY id")
.await
.expect("final select");
assert_eq!(rows.len(), 2, "expected two rows total");
}