|
| 1 | +#[cfg(test)] |
| 2 | +mod override_subgraph_urls_e2e_tests { |
| 3 | + use ntex::web::test; |
| 4 | + use sonic_rs::{from_slice, json, Value}; |
| 5 | + |
| 6 | + use crate::testkit::{ |
| 7 | + init_graphql_request, init_router_from_config_file, wait_for_readiness, SubgraphsServer, |
| 8 | + }; |
| 9 | + |
| 10 | + #[ntex::test] |
| 11 | + async fn should_not_deadlock_when_overriding_subgraph_timeout_statically() { |
| 12 | + let _subgraphs_server = SubgraphsServer::start().await; |
| 13 | + let app = init_router_from_config_file("configs/timeout_per_subgraph_static.router.yaml") |
| 14 | + .await |
| 15 | + .unwrap(); |
| 16 | + wait_for_readiness(&app.app).await; |
| 17 | + |
| 18 | + let req1 = init_graphql_request("{ users { id } }", None); |
| 19 | + let req2 = init_graphql_request("{ users { id } }", None); |
| 20 | + let req3 = init_graphql_request("{ users { id } }", None); |
| 21 | + let req4 = init_graphql_request("{ users { id } }", None); |
| 22 | + |
| 23 | + let (resp1, resp2, resp3, resp4) = tokio::join!( |
| 24 | + test::call_service(&app.app, req1.to_request()), |
| 25 | + test::call_service(&app.app, req2.to_request()), |
| 26 | + test::call_service(&app.app, req3.to_request()), |
| 27 | + test::call_service(&app.app, req4.to_request()) |
| 28 | + ); |
| 29 | + |
| 30 | + assert!(resp1.status().is_success(), "Expected 200 OK"); |
| 31 | + assert!(resp2.status().is_success(), "Expected 200 OK"); |
| 32 | + assert!(resp3.status().is_success(), "Expected 200 OK"); |
| 33 | + assert!(resp4.status().is_success(), "Expected 200 OK"); |
| 34 | + |
| 35 | + let expected_json = json!({ |
| 36 | + "data": { |
| 37 | + "users": [ |
| 38 | + { |
| 39 | + "id": "1" |
| 40 | + }, |
| 41 | + { |
| 42 | + "id": "2" |
| 43 | + }, |
| 44 | + { |
| 45 | + "id": "3" |
| 46 | + }, |
| 47 | + { |
| 48 | + "id": "4" |
| 49 | + }, |
| 50 | + { |
| 51 | + "id": "5" |
| 52 | + }, |
| 53 | + { |
| 54 | + "id": "6" |
| 55 | + } |
| 56 | + ] |
| 57 | + } |
| 58 | + }); |
| 59 | + |
| 60 | + for resp in [resp1, resp2, resp3, resp4] { |
| 61 | + let body = test::read_body(resp).await; |
| 62 | + let json_body: Value = from_slice(&body).unwrap(); |
| 63 | + assert_eq!(json_body, expected_json); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + #[ntex::test] |
| 68 | + async fn should_not_deadlock_when_overriding_subgraph_timeout_dynamically() { |
| 69 | + let _subgraphs_server = SubgraphsServer::start().await; |
| 70 | + let app = init_router_from_config_file("configs/timeout_per_subgraph_dynamic.router.yaml") |
| 71 | + .await |
| 72 | + .unwrap(); |
| 73 | + wait_for_readiness(&app.app).await; |
| 74 | + |
| 75 | + // We want to ensure that concurrent requests with different timeout settings |
| 76 | + // do not cause deadlocks. We are not testing the actual timeout duration here. |
| 77 | + let req1 = init_graphql_request("{ users { id } }", None).header("x-timeout", "short"); |
| 78 | + let req2 = init_graphql_request("{ users { id } }", None).header("x-timeout", "long"); |
| 79 | + let req3 = init_graphql_request("{ users { id } }", None).header("x-timeout", "short"); |
| 80 | + let req4 = init_graphql_request("{ users { id } }", None).header("x-timeout", "long"); |
| 81 | + |
| 82 | + let (resp1, resp2, resp3, resp4) = tokio::join!( |
| 83 | + test::call_service(&app.app, req1.to_request()), |
| 84 | + test::call_service(&app.app, req2.to_request()), |
| 85 | + test::call_service(&app.app, req3.to_request()), |
| 86 | + test::call_service(&app.app, req4.to_request()) |
| 87 | + ); |
| 88 | + |
| 89 | + assert!(resp1.status().is_success(), "Expected 200 OK"); |
| 90 | + assert!(resp2.status().is_success(), "Expected 200 OK"); |
| 91 | + assert!(resp3.status().is_success(), "Expected 200 OK"); |
| 92 | + assert!(resp4.status().is_success(), "Expected 200 OK"); |
| 93 | + |
| 94 | + let expected_json = json!({ |
| 95 | + "data": { |
| 96 | + "users": [ |
| 97 | + { |
| 98 | + "id": "1" |
| 99 | + }, |
| 100 | + { |
| 101 | + "id": "2" |
| 102 | + }, |
| 103 | + { |
| 104 | + "id": "3" |
| 105 | + }, |
| 106 | + { |
| 107 | + "id": "4" |
| 108 | + }, |
| 109 | + { |
| 110 | + "id": "5" |
| 111 | + }, |
| 112 | + { |
| 113 | + "id": "6" |
| 114 | + } |
| 115 | + ] |
| 116 | + } |
| 117 | + }); |
| 118 | + |
| 119 | + for resp in [resp1, resp2, resp3, resp4] { |
| 120 | + let body = test::read_body(resp).await; |
| 121 | + let json_body: Value = from_slice(&body).unwrap(); |
| 122 | + assert_eq!(json_body, expected_json); |
| 123 | + } |
| 124 | + } |
| 125 | +} |
0 commit comments