Skip to content

Commit dfbec9b

Browse files
authored
Merge pull request #22 from SolverForge/hotfix/ci-cross-platform-fetch-tests
test: stabilize cross-platform fetch cache tests
2 parents 5d48e5d + 77d3553 commit dfbec9b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/routing/fetch.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,14 +595,22 @@ mod tests {
595595
use std::net::TcpListener;
596596
use std::sync::atomic::{AtomicUsize, Ordering};
597597
use std::sync::Arc;
598+
use std::sync::OnceLock;
598599
use std::thread;
599600
use std::time::{Duration, Instant};
600601

602+
use tokio::sync::Mutex;
601603
use tokio::time::sleep;
602604

603605
use super::*;
604606
use crate::routing::BoundingBox;
605607

608+
static FETCH_TEST_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
609+
610+
fn fetch_test_lock() -> &'static Mutex<()> {
611+
FETCH_TEST_LOCK.get_or_init(|| Mutex::new(()))
612+
}
613+
606614
fn test_network() -> RoadNetwork {
607615
RoadNetwork::from_test_data(&[(0.0, 0.0), (0.0, 0.01)], &[(0, 1, 60.0, 1_000.0)])
608616
}
@@ -614,6 +622,7 @@ mod tests {
614622

615623
#[tokio::test]
616624
async fn load_or_insert_allows_different_keys_to_progress_concurrently() {
625+
let _guard = fetch_test_lock().lock().await;
617626
reset_test_state().await;
618627

619628
let start = Instant::now();
@@ -645,6 +654,7 @@ mod tests {
645654

646655
#[tokio::test]
647656
async fn load_or_insert_deduplicates_same_key_work() {
657+
let _guard = fetch_test_lock().lock().await;
648658
reset_test_state().await;
649659

650660
let loads = Arc::new(AtomicUsize::new(0));
@@ -725,6 +735,7 @@ mod tests {
725735

726736
#[tokio::test]
727737
async fn fetch_retries_same_endpoint_until_success() {
738+
let _guard = fetch_test_lock().lock().await;
728739
let (endpoint, requests, handle) = spawn_overpass_server(vec![
729740
("429 Too Many Requests", r#"{"elements":[]}"#),
730741
("200 OK", overpass_fixture_json()),
@@ -747,6 +758,7 @@ mod tests {
747758

748759
#[tokio::test]
749760
async fn fetch_falls_back_to_second_endpoint() {
761+
let _guard = fetch_test_lock().lock().await;
750762
let (primary, primary_requests, primary_handle) =
751763
spawn_overpass_server(vec![("503 Service Unavailable", r#"{"elements":[]}"#)]);
752764
let (secondary, secondary_requests, secondary_handle) =

0 commit comments

Comments
 (0)