Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions crates/fakecloud-e2e/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,34 @@ pub fn gunzip(data: &[u8]) -> Vec<u8> {
pub fn _path_buf_shim(p: PathBuf) -> PathBuf {
p
}

/// Poll DescribeDBInstances until the instance reports
/// `db_instance_status = "available"`, then return the populated
/// `DbInstance`. CreateDBInstance returns a `creating` placeholder
/// immediately; this helper bridges tests that need the endpoint.
pub async fn wait_for_db_available(
rds: &aws_sdk_rds::Client,
db_instance_identifier: &str,
max_secs: u64,
) -> aws_sdk_rds::types::DbInstance {
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(max_secs);
while std::time::Instant::now() < deadline {
if let Ok(resp) = rds
.describe_db_instances()
.db_instance_identifier(db_instance_identifier)
.send()
.await
{
for inst in resp.db_instances() {
if inst.db_instance_status() == Some("available") {
return inst.clone();
}
}
}
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
}
panic!(
"DB instance {} did not reach 'available' within {}s",
db_instance_identifier, max_secs
);
}
25 changes: 10 additions & 15 deletions crates/fakecloud-e2e/tests/rds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,7 @@ async fn rds_create_and_describe_db_instance() {
let created = create_response.db_instance().expect("created instance");
assert_eq!(created.db_instance_status(), Some("creating"));

let describe_response = client
.describe_db_instances()
.db_instance_identifier("orders-db")
.send()
.await
.unwrap();

let instances = describe_response.db_instances();
assert_eq!(instances.len(), 1);
let instance = &instances[0];
assert_eq!(instance.db_instance_status(), Some("available"));
let instance = helpers::wait_for_db_available(&client, "orders-db", 180).await;
assert_eq!(instance.engine(), Some("postgres"));

let endpoint = instance.endpoint().expect("endpoint");
Expand Down Expand Up @@ -612,7 +602,7 @@ async fn create_instance_with_deletion_protection(
db_instance_identifier: &str,
deletion_protection: bool,
) -> aws_sdk_rds::operation::create_db_instance::CreateDbInstanceOutput {
client
let resp = client
.create_db_instance()
.db_instance_identifier(db_instance_identifier)
.allocated_storage(20)
Expand All @@ -625,7 +615,11 @@ async fn create_instance_with_deletion_protection(
.db_name("appdb")
.send()
.await
.unwrap()
.unwrap();
// CreateDBInstance returns a `creating` placeholder; most callers
// need the DB to be ready before exercising downstream ops.
helpers::wait_for_db_available(client, db_instance_identifier, 180).await;
resp
}

async fn connect_with_retry(
Expand Down Expand Up @@ -766,8 +760,9 @@ async fn final_snapshot_on_delete() {
.await
.unwrap();

let instance = response.db_instance().expect("db instance");
let port = instance.endpoint().unwrap().port().unwrap();
let _instance = response.db_instance().expect("db instance");
let ready = helpers::wait_for_db_available(&client, "e2e-rds-final", 180).await;
let port = ready.endpoint().unwrap().port().unwrap();

// Wait for instance and insert test data
let (postgres, connection) =
Expand Down
9 changes: 3 additions & 6 deletions crates/fakecloud-e2e/tests/rds_aws_lambda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ async fn aws_lambda_extension_invoke_round_trip() {

// 2. Create the Postgres DB instance — triggers lazy fakecloud-postgres
// image build on first run, so this can take a while.
let create = rds
.create_db_instance()
rds.create_db_instance()
.db_instance_identifier("aws-lambda-ext-db")
.allocated_storage(20)
.db_instance_class("db.t3.micro")
Expand All @@ -98,10 +97,8 @@ async fn aws_lambda_extension_invoke_round_trip() {
.await
.expect("create postgres instance");

let endpoint = create
.db_instance()
.and_then(|i| i.endpoint())
.expect("endpoint");
let instance = helpers::wait_for_db_available(&rds, "aws-lambda-ext-db", 240).await;
let endpoint = instance.endpoint().expect("endpoint");
let host = endpoint.address().expect("address").to_string();
let port = endpoint.port().expect("port");

Expand Down
9 changes: 3 additions & 6 deletions crates/fakecloud-e2e/tests/rds_aws_s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ async fn aws_s3_extension_import_export_round_trip() {
// 2. Postgres instance — reuses the lazy fakecloud-postgres image
// that the aws_lambda e2e already exercises, so this run is fast
// when ordered after the lambda test on the same runner.
let create = rds
.create_db_instance()
rds.create_db_instance()
.db_instance_identifier("aws-s3-ext-db")
.allocated_storage(20)
.db_instance_class("db.t3.micro")
Expand All @@ -82,10 +81,8 @@ async fn aws_s3_extension_import_export_round_trip() {
.send()
.await
.expect("create postgres instance");
let endpoint = create
.db_instance()
.and_then(|i| i.endpoint())
.expect("endpoint");
let instance = helpers::wait_for_db_available(&rds, "aws-s3-ext-db", 240).await;
let endpoint = instance.endpoint().expect("endpoint");
let host = endpoint.address().expect("address").to_string();
let port = endpoint.port().expect("port");

Expand Down
5 changes: 5 additions & 0 deletions crates/fakecloud-e2e/tests/rds_heavy_engines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ async fn rds_oracle_create_describe_delete() {
.await
.expect("create oracle instance");

// Oracle Free can take up to ~4 minutes to bootstrap.
helpers::wait_for_db_available(&client, "oracle-smoke", 360).await;
let describe = client
.describe_db_instances()
.db_instance_identifier("oracle-smoke")
Expand Down Expand Up @@ -126,6 +128,7 @@ async fn rds_sqlserver_create_describe_delete() {
.await
.expect("create sqlserver instance");

helpers::wait_for_db_available(&client, "mssql-smoke", 300).await;
let describe = client
.describe_db_instances()
.db_instance_identifier("mssql-smoke")
Expand Down Expand Up @@ -167,6 +170,8 @@ async fn rds_db2_create_describe_delete() {
.await
.expect("create db2 instance");

// Db2 Community Edition's first boot can take ~6 minutes.
helpers::wait_for_db_available(&client, "db2-smoke", 480).await;
let describe = client
.describe_db_instances()
.db_instance_identifier("db2-smoke")
Expand Down
1 change: 1 addition & 0 deletions crates/fakecloud-e2e/tests/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ async fn sdk_rds_get_instances() {
.await
.unwrap();

helpers::wait_for_db_available(&rds, "sdk-rds-db", 240).await;
let instances = fc.rds().get_instances().await.expect("get rds instances");
let instance = instances
.instances
Expand Down
Loading
Loading