Skip to content

Commit 375c03a

Browse files
author
Alexei Pastuchov
committed
run round_trip's assertions in separate threads
This approach ensures the test reachs killing of client's thread.
1 parent a008075 commit 375c03a

File tree

1 file changed

+40
-28
lines changed
  • wundergraph_cli/src/print_schema

1 file changed

+40
-28
lines changed

wundergraph_cli/src/print_schema/mod.rs

+40-28
Original file line numberDiff line numberDiff line change
@@ -311,41 +311,53 @@ mod tests {
311311
std::thread::sleep(std::time::Duration::from_secs(1));
312312

313313
let query = "{\"query\": \"{ Users { id name } } \"}";
314-
let mut r = client
315-
.post(&format!("http://{}/graphql", listen_url))
316-
.body(query)
317-
.header(
318-
reqwest::header::CONTENT_TYPE,
319-
reqwest::header::HeaderValue::from_static("application/json"),
320-
)
321-
.send()
322-
.unwrap();
323-
insta::assert_json_snapshot!(r.json::<serde_json::Value>().unwrap());
324-
325314
let mutation = r#"{"query":"mutation CreateUser {\n CreateUser(NewUser: {name: \"Max\"}) {\n id\n name\n }\n}","variables":null,"operationName":"CreateUser"}"#;
326-
let mut r = client
327-
.post(&format!("http://{}/graphql", listen_url))
328-
.body(mutation)
329-
.header(
330-
reqwest::header::CONTENT_TYPE,
331-
reqwest::header::HeaderValue::from_static("application/json"),
332-
)
333-
.send()
334-
.unwrap();
335-
insta::assert_json_snapshot!(r.json::<serde_json::Value>().unwrap());
315+
let t1 = request_test(&client, &listen_url, query);
316+
let t2 = request_test(&client, &listen_url, mutation);
317+
let t3 = request_test(&client, &listen_url, query);
336318

337-
let mut r = client
319+
child.kill().unwrap();
320+
child.wait().unwrap();
321+
322+
if !t1 || !t2 || !t3 {
323+
panic!("round_trip failed")
324+
}
325+
}
326+
327+
fn request_test(client: &reqwest::Client, listen_url: &str, body: &'static str) -> bool {
328+
let r = client
338329
.post(&format!("http://{}/graphql", listen_url))
339-
.body(query)
330+
.body(body)
340331
.header(
341332
reqwest::header::CONTENT_TYPE,
342333
reqwest::header::HeaderValue::from_static("application/json"),
343334
)
344-
.send()
345-
.unwrap();
346-
insta::assert_json_snapshot!(r.json::<serde_json::Value>().unwrap());
335+
.send();
347336

348-
child.kill().unwrap();
349-
child.wait().unwrap();
337+
let nok = |e| {
338+
if cfg!(feature = "debug") {
339+
println!("{}", e)
340+
}
341+
false
342+
};
343+
344+
match r {
345+
Ok(mut r) => {
346+
let builder = std::thread::Builder::new().name("round_trip".into());
347+
let handler = builder
348+
.spawn(move || {
349+
insta::assert_json_snapshot!(r
350+
.json::<serde_json::Value>()
351+
.unwrap())
352+
})
353+
.unwrap();
354+
355+
match handler.join() {
356+
Err(e) => nok(format!("{:?}", e)),
357+
_ => true,
358+
}
359+
}
360+
Err(e) => nok(format!("{:?}", e)),
361+
}
350362
}
351363
}

0 commit comments

Comments
 (0)