mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-06-04 22:30:37 +00:00
test: simplify postgres sqlness startup wait
This commit is contained in:
committed by
GitHub
parent
92d42acf6c
commit
1521acd858
@@ -352,36 +352,8 @@ pub fn setup_pg(pg_port: u16, pg_version: Option<&str>) {
|
||||
}
|
||||
}
|
||||
|
||||
// Wait until PostgreSQL is ready to accept connections. The container
|
||||
// accepts TCP connections before the database system has finished
|
||||
// initializing, so a plain TCP port check is not sufficient. Use
|
||||
// `pg_isready` (bundled in the official postgres image) instead.
|
||||
wait_for_pg_ready("greptimedb_pg", pg_user, Duration::from_secs(60));
|
||||
}
|
||||
|
||||
/// Poll `pg_isready` inside the named container until it reports that the
|
||||
/// server is accepting connections, or until `timeout` is reached.
|
||||
fn wait_for_pg_ready(container_name: &str, user: &str, timeout: Duration) {
|
||||
let deadline = std::time::Instant::now() + timeout;
|
||||
println!("Waiting for PostgreSQL container \"{container_name}\" to be ready...");
|
||||
loop {
|
||||
let ready = std::process::Command::new("docker")
|
||||
.args(["exec", container_name, "pg_isready", "-U", user])
|
||||
.status()
|
||||
.map(|s| s.success())
|
||||
.unwrap_or(false);
|
||||
if ready {
|
||||
println!("PostgreSQL is ready");
|
||||
return;
|
||||
}
|
||||
if std::time::Instant::now() >= deadline {
|
||||
panic!(
|
||||
"PostgreSQL container \"{container_name}\" did not become ready within {:?}",
|
||||
timeout
|
||||
);
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(500));
|
||||
}
|
||||
// Docker of PostgreSQL starts slowly, so we need to wait for a while.
|
||||
std::thread::sleep(Duration::from_secs(10));
|
||||
}
|
||||
|
||||
/// Set up a MySql server in docker.
|
||||
|
||||
Reference in New Issue
Block a user