Fix dtls tests

There's a reason static mut is unsafe...
This commit is contained in:
Steven Fackler 2015-04-08 22:10:13 -07:00
parent 483e0b1f0a
commit c5a16db97e
1 changed files with 8 additions and 8 deletions

View File

@ -29,15 +29,15 @@ use ssl::SslMethod::Dtlsv1;
#[cfg(feature="dtlsv1")] #[cfg(feature="dtlsv1")]
use connected_socket::Connect; use connected_socket::Connect;
#[cfg(test)] #[cfg(feature = "dtlsv1")]
mod udp { mod udp {
static mut udp_port:u16 = 15410; use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
static UDP_PORT: AtomicUsize = ATOMIC_USIZE_INIT;
pub fn next_server<'a>() -> String { pub fn next_server<'a>() -> String {
unsafe { let diff = UDP_PORT.fetch_add(1, Ordering::SeqCst);
udp_port += 1; format!("127.0.0.1:{}", 15411 + diff)
format!("127.0.0.1:{}", udp_port)
}
} }
} }
@ -60,13 +60,13 @@ macro_rules! run_test(
use crypto::hash::Type::SHA256; use crypto::hash::Type::SHA256;
use x509::X509StoreContext; use x509::X509StoreContext;
use serialize::hex::FromHex; use serialize::hex::FromHex;
#[test] #[test]
fn sslv23() { fn sslv23() {
let stream = TcpStream::connect("127.0.0.1:15418").unwrap(); let stream = TcpStream::connect("127.0.0.1:15418").unwrap();
$blk(SslMethod::Sslv23, stream); $blk(SslMethod::Sslv23, stream);
} }
#[test] #[test]
#[cfg(feature="dtlsv1")] #[cfg(feature="dtlsv1")]
fn dtlsv1() { fn dtlsv1() {