45 lines
1.3 KiB
Rust

//! Allocation lifecycle unit tests covering clamping and removal.
#[path = "../support/mod.rs"]
mod support;
mod helpers;
use helpers::*;
use niom_turn::alloc::AllocationManager;
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
use tokio::net::UdpSocket;
async fn allocate_sample(manager: &AllocationManager) -> SocketAddr {
let server = Arc::new(UdpSocket::bind("127.0.0.1:0").await.expect("udp bind"));
let client = sample_client();
manager
.allocate_for(client, server)
.await
.expect("allocate relay");
client
}
#[tokio::test(flavor = "current_thread")]
async fn refresh_clamps_to_minimum_lifetime() {
let manager = AllocationManager::new();
let client = allocate_sample(&manager).await;
let applied = manager
.refresh_allocation(client, Some(Duration::from_secs(30)))
.expect("refresh");
assert_eq!(applied, Duration::from_secs(60));
}
#[tokio::test(flavor = "current_thread")]
async fn zero_lifetime_removes_allocation() {
let manager = AllocationManager::new();
let client = allocate_sample(&manager).await;
let applied = manager
.refresh_allocation(client, Some(Duration::from_secs(0)))
.expect("refresh zero");
assert_eq!(applied, Duration::from_secs(0));
assert!(manager.get_allocation(&client).is_none());
}