Skip to content

Commit 5d0dd92

Browse files
committed
Issue-185 - Fix hanging tests
1 parent a948731 commit 5d0dd92

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

extension/tests/lambda_service.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -796,15 +796,15 @@ async fn test_lambda_service_loop_100_valid_get_requests() {
796796
});
797797

798798
// Let the router run wild
799-
tokio::spawn(async move {
799+
for _ in 0..100 {
800800
mock_router_server
801801
.release_request_tx
802802
.lock()
803803
.await
804804
.send(())
805805
.await
806806
.unwrap();
807-
});
807+
}
808808

809809
let mut options = Options::default();
810810

@@ -882,19 +882,18 @@ async fn test_lambda_service_loop_100_valid_post_requests() {
882882
.mount(&mock_app_server)
883883
.await;
884884

885-
// Let the router run wild
886-
tokio::spawn(async move {
885+
// Push 100 messages into the channel (it's limit)
886+
for _ in 0..100 {
887887
mock_router_server
888888
.release_request_tx
889889
.lock()
890890
.await
891891
.send(())
892892
.await
893893
.unwrap();
894-
});
894+
}
895895

896896
let mut options = Options::default();
897-
898897
options.port = mock_app_server.address().port();
899898
let initialized = true;
900899

@@ -1549,16 +1548,15 @@ async fn test_lambda_service_loop_100_requests_contained_app_connection_close_he
15491548
.body("Bananas");
15501549
});
15511550

1552-
// Let the router run wild
1553-
tokio::spawn(async move {
1551+
for _ in 0..100 {
15541552
mock_router_server
15551553
.release_request_tx
15561554
.lock()
15571555
.await
15581556
.send(())
15591557
.await
15601558
.unwrap();
1561-
});
1559+
}
15621560

15631561
let mut options = Options::default();
15641562

@@ -2117,7 +2115,6 @@ async fn test_lambda_service_router_connects_app_crashes_graceful_close() {
21172115

21182116
#[tokio::test]
21192117
async fn test_lambda_service_router_closes_quickly_when_no_requests() {
2120-
env_logger::init();
21212118
// Start router server
21222119
let mock_router_server =
21232120
mock_router::setup_router(mock_router::RouterParamsBuilder::new().build());

extension/tests/router_channel.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,17 +456,17 @@ async fn test_channel_invalid_request_headers_should_continue() {
456456
});
457457
let app_endpoint: Endpoint = mock_app_server.base_url().parse().unwrap();
458458

459-
// Release the request after a few seconds
460-
tokio::spawn(async move {
461-
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
459+
for _ in 0..2 {
460+
// Release the request after a few seconds
461+
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
462462
mock_router_server
463463
.release_request_tx
464464
.lock()
465465
.await
466466
.send(())
467467
.await
468468
.unwrap();
469-
});
469+
}
470470

471471
let app_client = create_app_client();
472472
let router_client = create_router_client();

extension/tests/support/mock_router.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,6 @@ pub fn setup_router(params: RouterParams) -> RouterResult {
313313

314314
// Send static request to extension
315315
if request_method == RequestMethod::ShutdownWithoutResponse {
316-
release_request_rx.lock().await.recv().await;
317-
318316
// Close the body stream
319317
tx.shutdown().await.unwrap();
320318
return;
@@ -343,7 +341,7 @@ pub fn setup_router(params: RouterParams) -> RouterResult {
343341
let data = b"GET /bananas_query_unencoded_brackets?cat=[dog]&cat=log&cat=cat HTTP/1.1\r\nHost: localhost\r\nTest-Header: foo\r\n\r\n";
344342
tx.write_all(data).await.unwrap();
345343
} else if request_method == RequestMethod::GetGoAwayOnBody {
346-
println!("Sending GoAway on body");
344+
println!("{} Sending GoAway on body, request_count: {}", chrono::Local::now().format("%Y-%m-%d %H:%M:%S%.3f"), request_count);
347345
let data = b"GET /_lambda_dispatch/goaway HTTP/1.1\r\nHost: localhost\r\nTest-Header: foo\r\n\r\n";
348346
tx.write_all(data).await.unwrap();
349347
} else if request_method == RequestMethod::GetInvalidHeaders {

0 commit comments

Comments
 (0)