Merge pull request #3340 from influxdata/crepererum/set_server_id_twice
fix: allow setting the same server ID twicepull/24376/head
commit
95f907efd8
|
@ -129,7 +129,16 @@ async fn assert_set_get_server_id(server_fixture: ServerFixture) {
|
|||
let got = client.get_server_id().await.expect("get ID failed");
|
||||
assert_eq!(got, Some(test_id));
|
||||
|
||||
// setting server ID a second time should fail
|
||||
// setting server ID to same ID should be OK
|
||||
client
|
||||
.update_server_id(test_id)
|
||||
.await
|
||||
.expect("set ID again failed");
|
||||
|
||||
let got = client.get_server_id().await.expect("get ID failed");
|
||||
assert_eq!(got, Some(test_id));
|
||||
|
||||
// setting server ID to a different ID should fail
|
||||
let result = client
|
||||
.update_server_id(NonZeroU32::try_from(13).unwrap())
|
||||
.await;
|
||||
|
|
|
@ -470,6 +470,15 @@ impl Server {
|
|||
let mut state = self.shared.state.write();
|
||||
let startup = match &**state {
|
||||
ServerState::Startup(startup) => startup.clone(),
|
||||
state
|
||||
if state
|
||||
.server_id()
|
||||
.map(|existing| existing == server_id)
|
||||
.unwrap_or_default() =>
|
||||
{
|
||||
// already set to same ID
|
||||
return Ok(());
|
||||
}
|
||||
_ => return Err(Error::IdAlreadySet),
|
||||
};
|
||||
|
||||
|
@ -2459,4 +2468,20 @@ mod tests {
|
|||
])
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn set_server_id_twice() {
|
||||
test_helpers::maybe_start_logging();
|
||||
let server = make_server(make_application());
|
||||
|
||||
server.set_id(ServerId::try_from(1).unwrap()).unwrap();
|
||||
server.wait_for_init().await.unwrap();
|
||||
|
||||
server.set_id(ServerId::try_from(1).unwrap()).unwrap();
|
||||
|
||||
assert_error!(
|
||||
server.set_id(ServerId::try_from(2).unwrap()),
|
||||
Error::IdAlreadySet
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue