Skip to content

Commit 0c86105

Browse files
author
lif
committed
wip: repalce sleep with timeout
1 parent 4aefe99 commit 0c86105

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

end-to-end-tests/src/instance_launch.rs

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,48 @@ async fn instance_launch() -> Result<()> {
196196

197197
// check that we saw it on the console
198198
eprintln!("waiting for serial console");
199-
sleep(Duration::from_secs(5)).await;
200-
let data = String::from_utf8_lossy(
201-
&ctx.client
202-
.instance_serial_console()
203-
.project(ctx.project_name.clone())
204-
.instance(instance.name.clone())
205-
.most_recent(1024 * 1024)
206-
.max_bytes(1024 * 1024)
207-
.send()
208-
.await?
209-
.data,
199+
200+
let data = wait_for_condition(
201+
|| async {
202+
type Error =
203+
CondCheckError<oxide_client::Error<oxide_client::types::Error>>;
204+
205+
let instance_state = ctx
206+
.client
207+
.instance_view()
208+
.project(ctx.project_name.clone())
209+
.instance(instance.name.clone())
210+
.send()
211+
.await?
212+
.run_state;
213+
214+
if instance_state == InstanceState::Starting {
215+
return Err(Error::NotYet);
216+
}
217+
218+
let data = String::from_utf8_lossy(
219+
&ctx.client
220+
.instance_serial_console()
221+
.project(ctx.project_name.clone())
222+
.instance(instance.name.clone())
223+
.most_recent(1024 * 1024)
224+
.max_bytes(1024 * 1024)
225+
.send()
226+
.await?
227+
.data,
228+
)
229+
.into_owned();
230+
if data.contains("-----END SSH HOST KEY KEYS-----") {
231+
Ok(data)
232+
} else {
233+
Err(Error::NotYet)
234+
}
235+
},
236+
&Duration::from_secs(5),
237+
&Duration::from_secs(300),
210238
)
211-
.into_owned();
239+
.await?;
240+
212241
ensure!(
213242
data.contains("Hello, Oxide!"),
214243
"string not seen on console\n{}",

0 commit comments

Comments
 (0)