Skip to content

Commit

Permalink
WIP: See if we can make dist happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Apr 12, 2021
1 parent 0ba7a78 commit 0c6ea8b
Showing 1 changed file with 8 additions and 35 deletions.
43 changes: 8 additions & 35 deletions tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl DistSystem {
wait_for_http(scheduler_url, Duration::from_millis(100), MAX_STARTUP_WAIT);
wait_for(
|| {
let status = self.scheduler_status().wait();
let status = self.scheduler_status();
if matches!(
status,
SchedulerStatusResult {
Expand Down Expand Up @@ -436,7 +436,7 @@ impl DistSystem {
wait_for_http(url, Duration::from_millis(100), MAX_STARTUP_WAIT);
wait_for(
|| {
let status = self.scheduler_status().wait();
let status = self.scheduler_status();
if matches!(
status,
SchedulerStatusResult {
Expand All @@ -461,16 +461,13 @@ impl DistSystem {
HTTPUrl::from_url(reqwest::Url::parse(&url).unwrap())
}

async fn scheduler_status(&self) -> SchedulerStatusResult {
use bytes::buf::BufExt;
let res = reqwest::get(dist::http::urls::scheduler_status(
fn scheduler_status(&self) -> SchedulerStatusResult {
let res = reqwest::blocking::get(dist::http::urls::scheduler_status(
&self.scheduler_url().to_url(),
))
.await
.unwrap();
assert!(res.status().is_success());
let bytes = res.bytes().await.unwrap();
bincode::deserialize_from(bytes.reader()).unwrap()
bincode::deserialize_from(res).unwrap()
}

fn container_ip(&self, name: &str) -> IpAddr {
Expand Down Expand Up @@ -649,11 +646,9 @@ fn check_output(output: &Output) {
fn wait_for_http(url: HTTPUrl, interval: Duration, max_wait: Duration) {
wait_for(
|| {
let client = reqwest::blocking::Client::builder()
.danger_accept_invalid_certs(true)
.build()
.unwrap();
match client.get(url.to_url()).send() {
let url = url.to_url();
let url = url.socket_addrs(|| None).unwrap();
match net::TcpStream::connect(url.as_slice()) {
Ok(_) => Ok(()),
Err(e) => Err(e.to_string()),
}
Expand All @@ -678,25 +673,3 @@ fn wait_for<F: Fn() -> Result<(), String>>(f: F, interval: Duration, max_wait: D
}
panic!("wait timed out, last error result: {}", lasterr)
}

/// An add on trait, to allow calling `.wait()` for `futures::Future`
/// as it was possible for `futures` at `0.1`.
///
/// Intended for test only!
pub(crate) trait Waiter<R> {
fn wait(self) -> R;
}

impl<T, O> Waiter<O> for T
where
T: Future<Output = O>,
{
fn wait(self) -> O {
let mut rt = tokio::runtime::Builder::new()
.enable_all()
.basic_scheduler()
.build()
.unwrap();
rt.block_on(self)
}
}

0 comments on commit 0c6ea8b

Please sign in to comment.