Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/routing/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,22 @@ mod tests {
use std::net::TcpListener;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::sync::OnceLock;
use std::thread;
use std::time::{Duration, Instant};

use tokio::sync::Mutex;
use tokio::time::sleep;

use super::*;
use crate::routing::BoundingBox;

static FETCH_TEST_LOCK: OnceLock<Mutex<()>> = OnceLock::new();

fn fetch_test_lock() -> &'static Mutex<()> {
FETCH_TEST_LOCK.get_or_init(|| Mutex::new(()))
}

fn test_network() -> RoadNetwork {
RoadNetwork::from_test_data(&[(0.0, 0.0), (0.0, 0.01)], &[(0, 1, 60.0, 1_000.0)])
}
Expand All @@ -614,6 +622,7 @@ mod tests {

#[tokio::test]
async fn load_or_insert_allows_different_keys_to_progress_concurrently() {
let _guard = fetch_test_lock().lock().await;
reset_test_state().await;

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

#[tokio::test]
async fn load_or_insert_deduplicates_same_key_work() {
let _guard = fetch_test_lock().lock().await;
reset_test_state().await;

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

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

#[tokio::test]
async fn fetch_falls_back_to_second_endpoint() {
let _guard = fetch_test_lock().lock().await;
let (primary, primary_requests, primary_handle) =
spawn_overpass_server(vec![("503 Service Unavailable", r#"{"elements":[]}"#)]);
let (secondary, secondary_requests, secondary_handle) =
Expand Down
Loading