@@ -2,6 +2,7 @@ use crate::database::InferConnection;
2
2
use crate :: infer_schema_internals:: * ;
3
3
use std:: error:: Error ;
4
4
use std:: io:: Write ;
5
+ use std:: thread;
5
6
6
7
mod print_helper;
7
8
use self :: print_helper:: * ;
@@ -311,41 +312,51 @@ mod tests {
311
312
std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) ;
312
313
313
314
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
-
325
315
let mutation = r#"{"query":"mutation CreateUser {\n CreateUser(NewUser: {name: \"Max\"}) {\n id\n name\n }\n}","variables":null,"operationName":"CreateUser"}"# ;
316
+ let t1 = request_test ( & client, & listen_url, query) ;
317
+ let t2 = request_test ( & client, & listen_url, mutation) ;
318
+ let t3 = request_test ( & client, & listen_url, query) ;
319
+
320
+ child. kill ( ) . unwrap ( ) ;
321
+ child. wait ( ) . unwrap ( ) ;
322
+
323
+ if !t1 || !t2 || !t3 {
324
+ panic ! ( "round_trip failed" )
325
+ }
326
+ }
327
+
328
+ fn request_test (
329
+ client : & reqwest:: Client ,
330
+ listen_url : & str ,
331
+ body : & ' static str ,
332
+ ) -> bool {
326
333
let mut r = client
327
334
. post ( & format ! ( "http://{}/graphql" , listen_url) )
328
- . body ( mutation )
335
+ . body ( body )
329
336
. header (
330
337
reqwest:: header:: CONTENT_TYPE ,
331
338
reqwest:: header:: HeaderValue :: from_static ( "application/json" ) ,
332
339
)
333
340
. send ( )
334
341
. unwrap ( ) ;
335
- insta:: assert_json_snapshot!( r. json:: <serde_json:: Value >( ) . unwrap( ) ) ;
336
342
337
- let mut r = client
338
- . post ( & format ! ( "http://{}/graphql" , listen_url) )
339
- . body ( query)
340
- . header (
341
- reqwest:: header:: CONTENT_TYPE ,
342
- reqwest:: header:: HeaderValue :: from_static ( "application/json" ) ,
343
- )
344
- . send ( )
343
+ let builder =
344
+ thread:: Builder :: new ( ) . name ( "insta-assert-json-snapshot" . into ( ) ) ;
345
+ let handler = builder
346
+ . spawn ( move || {
347
+ let js = r. json :: < serde_json:: Value > ( ) . unwrap ( ) ;
348
+ insta:: assert_json_snapshot!( js. clone( ) )
349
+ } )
345
350
. unwrap ( ) ;
346
- insta:: assert_json_snapshot!( r. json:: <serde_json:: Value >( ) . unwrap( ) ) ;
347
351
348
- child. kill ( ) . unwrap ( ) ;
349
- child. wait ( ) . unwrap ( ) ;
352
+ match handler. join ( ) {
353
+ Err ( e) => {
354
+ if cfg ! ( feature = "debug" ) {
355
+ println ! ( "{:?}" , e)
356
+ }
357
+ false
358
+ }
359
+ _ => true ,
360
+ }
350
361
}
351
362
}
0 commit comments