@@ -11,7 +11,7 @@ async fn test_index_ok() {
11
11
assert_eq ! ( resp. status( ) , http:: StatusCode :: OK ) ;
12
12
let body = test:: read_body ( resp) . await ;
13
13
assert ! ( body. starts_with( b"<!DOCTYPE html>" ) ) ;
14
- // the body should contain the strint "It works!" and should not contain the string "error"
14
+ // the body should contain the string "It works!" and should not contain the string "error"
15
15
let body = String :: from_utf8 ( body. to_vec ( ) ) . unwrap ( ) ;
16
16
assert ! ( body. contains( "It works !" ) ) ;
17
17
assert ! ( !body. contains( "error" ) ) ;
@@ -43,6 +43,40 @@ async fn test_404() {
43
43
}
44
44
}
45
45
46
+ #[ actix_web:: test]
47
+ async fn test_concurrent_requests ( ) {
48
+ // send 32 requests (less than the default postgres pool size)
49
+ // at the same time to /tests/multiple_components.sql
50
+ let components = [
51
+ "table" , "form" , "card" , "datagrid" , "hero" , "list" , "timeline" ,
52
+ ] ;
53
+ let reqs = ( 0 ..32 )
54
+ . map ( |i| {
55
+ let component = components[ i % components. len ( ) ] ;
56
+ req_path ( format ! ( "/tests/any_component.sql?component={}" , component) )
57
+ } )
58
+ . collect :: < Vec < _ > > ( ) ;
59
+ // send all requests at the same time
60
+ let results = futures_util:: future:: join_all ( reqs) . await ;
61
+ // check that all requests succeeded
62
+ for result in results. into_iter ( ) {
63
+ let resp = result. unwrap ( ) ;
64
+ assert_eq ! ( resp. status( ) , http:: StatusCode :: OK ) ;
65
+ let body = test:: read_body ( resp) . await ;
66
+ assert ! (
67
+ body. starts_with( b"<!DOCTYPE html>" ) ,
68
+ "Expected html doctype"
69
+ ) ;
70
+ // the body should contain the string "It works!" and should not contain the string "error"
71
+ let body = String :: from_utf8 ( body. to_vec ( ) ) . unwrap ( ) ;
72
+ assert ! (
73
+ body. contains( "It works !" ) ,
74
+ "Expected to contain: It works !, but got: {body}"
75
+ ) ;
76
+ assert ! ( !body. contains( "error" ) ) ;
77
+ }
78
+ }
79
+
46
80
#[ actix_web:: test]
47
81
async fn test_files ( ) {
48
82
// Iterate over all the sql test files in the tests/ directory
@@ -59,7 +93,7 @@ async fn test_files() {
59
93
let resp = req_path ( & req_str) . await . unwrap ( ) ;
60
94
let body = test:: read_body ( resp) . await ;
61
95
assert ! ( body. starts_with( b"<!DOCTYPE html>" ) ) ;
62
- // the body should contain the strint "It works!" and should not contain the string "error"
96
+ // the body should contain the string "It works!" and should not contain the string "error"
63
97
let body = String :: from_utf8 ( body. to_vec ( ) ) . unwrap ( ) ;
64
98
let lowercase_body = body. to_lowercase ( ) ;
65
99
if stem. starts_with ( "it_works" ) {
@@ -148,8 +182,10 @@ async fn get_request_to(path: &str) -> actix_web::Result<TestRequest> {
148
182
Ok ( test:: TestRequest :: get ( ) . uri ( path) . app_data ( data) )
149
183
}
150
184
151
- async fn req_path ( path : & str ) -> Result < actix_web:: dev:: ServiceResponse , actix_web:: Error > {
152
- let req = get_request_to ( path)
185
+ async fn req_path (
186
+ path : impl AsRef < str > ,
187
+ ) -> Result < actix_web:: dev:: ServiceResponse , actix_web:: Error > {
188
+ let req = get_request_to ( path. as_ref ( ) )
153
189
. await ?
154
190
. insert_header ( ContentType :: plaintext ( ) )
155
191
. to_srv_request ( ) ;
0 commit comments