test: Detect if talking to the wrong test server
Closes #952 A pragmatic fix for #952: since we already set the server id in `wait_until_ready`, let's start a test server without an ID (by not passing `INFLUXDB_IOX_ID`) and use the property of already having an ID as an indication that we're talking to a server instance that we didn't just start. It doesn't necessarily mean we're talking to the right server, but the main point of #952 was to avoid confusing error messages like "DatabaseAlreadyExists"; with this PR, the only way for that error to confuse developers is if we "unset" the writer ID of a server fixture and leave it there hanging, with in-memory side effects but no ID. Possible but unlikely, I think.pull/24376/head
parent
d33ddcbe9e
commit
5434846250
|
@ -225,9 +225,8 @@ impl TestServer {
|
||||||
|
|
||||||
let server_process = Command::cargo_bin("influxdb_iox")
|
let server_process = Command::cargo_bin("influxdb_iox")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
// Can enable for debbugging
|
// Can enable for debugging
|
||||||
//.arg("-vv")
|
//.arg("-vv")
|
||||||
.env("INFLUXDB_IOX_ID", "1")
|
|
||||||
.env("INFLUXDB_IOX_BIND_ADDR", &addrs.http_bind_addr)
|
.env("INFLUXDB_IOX_BIND_ADDR", &addrs.http_bind_addr)
|
||||||
.env("INFLUXDB_IOX_GRPC_BIND_ADDR", &addrs.grpc_bind_addr)
|
.env("INFLUXDB_IOX_GRPC_BIND_ADDR", &addrs.grpc_bind_addr)
|
||||||
// redirect output to log file
|
// redirect output to log file
|
||||||
|
@ -250,10 +249,9 @@ impl TestServer {
|
||||||
self.server_process.wait().unwrap();
|
self.server_process.wait().unwrap();
|
||||||
self.server_process = Command::cargo_bin("influxdb_iox")
|
self.server_process = Command::cargo_bin("influxdb_iox")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
// Can enable for debbugging
|
// Can enable for debugging
|
||||||
//.arg("-vv")
|
//.arg("-vv")
|
||||||
.env("INFLUXDB_IOX_DB_DIR", self.dir.path())
|
.env("INFLUXDB_IOX_DB_DIR", self.dir.path())
|
||||||
.env("INFLUXDB_IOX_ID", "1")
|
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -336,12 +334,26 @@ impl TestServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the writer id, if requested
|
// Set the writer id, if requested; otherwise default to the default writer id:
|
||||||
match initial_config {
|
// 1.
|
||||||
|
let id = match initial_config {
|
||||||
InitialConfig::SetWriterId => {
|
InitialConfig::SetWriterId => {
|
||||||
|
NonZeroU32::new(42).expect("42 is non zero, among its other properties")
|
||||||
|
}
|
||||||
|
InitialConfig::None => {
|
||||||
|
NonZeroU32::new(1).expect("1 is non zero; the first one to be so, moreover")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let channel = self.grpc_channel().await.expect("gRPC should be running");
|
let channel = self.grpc_channel().await.expect("gRPC should be running");
|
||||||
let mut management_client = influxdb_iox_client::management::Client::new(channel);
|
let mut management_client = influxdb_iox_client::management::Client::new(channel);
|
||||||
let id = NonZeroU32::new(42).expect("42 is non zero, among its other properties");
|
|
||||||
|
if let Ok(id) = management_client.get_writer_id().await {
|
||||||
|
// tell others that this server had some problem
|
||||||
|
*ready = ServerState::Error;
|
||||||
|
std::mem::drop(ready);
|
||||||
|
panic!("Server already has an ID ({}); possibly a stray/orphan server from another test run.", id);
|
||||||
|
}
|
||||||
|
|
||||||
management_client
|
management_client
|
||||||
.update_writer_id(id)
|
.update_writer_id(id)
|
||||||
|
@ -349,11 +361,6 @@ impl TestServer {
|
||||||
.expect("set ID failed");
|
.expect("set ID failed");
|
||||||
println!("Set writer_id to {:?}", id);
|
println!("Set writer_id to {:?}", id);
|
||||||
}
|
}
|
||||||
InitialConfig::None => {
|
|
||||||
println!("Leaving database unconfigured");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a connection channel for the gRPR endpoing
|
/// Create a connection channel for the gRPR endpoing
|
||||||
async fn grpc_channel(
|
async fn grpc_channel(
|
||||||
|
|
Loading…
Reference in New Issue