Skip to content

Commit 76bd05b

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 2617f76 commit 76bd05b

File tree

1 file changed

+32
-29
lines changed
  • wundergraph_cli/src/print_schema

1 file changed

+32
-29
lines changed

wundergraph_cli/src/print_schema/mod.rs

+32-29
Original file line numberDiff line numberDiff line change
@@ -311,41 +311,44 @@ 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.is_err() || t2.is_err() || t3.is_err() {
323+
panic!("round_trip failed")
324+
}
325+
}
326+
327+
fn request_test(client: &reqwest::Client, listen_url: &str, body: &'static str) -> Result<(), std::string::String> {
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());
347-
348-
child.kill().unwrap();
349-
child.wait().unwrap();
335+
.send();
336+
337+
match r {
338+
Ok(mut r) => {
339+
let builder = std::thread::Builder::new().name("round_trip".into());
340+
let handler = builder
341+
.spawn(move || {
342+
insta::assert_json_snapshot!(r.json::<serde_json::Value>().unwrap())
343+
})
344+
.unwrap();
345+
346+
match handler.join() {
347+
Err(e) => Err(format!("{:?}", e)),
348+
_ => Ok(()),
349+
}
350+
}
351+
Err(e) => Err(format!("{:?}", e)),
352+
}
350353
}
351354
}

0 commit comments

Comments
 (0)