Skip to content

Commit c5a16db

Browse files
committed
Fix dtls tests
There's a reason static mut is unsafe...
1 parent 483e0b1 commit c5a16db

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

openssl/src/ssl/tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ use ssl::SslMethod::Dtlsv1;
2929
#[cfg(feature="dtlsv1")]
3030
use connected_socket::Connect;
3131

32-
#[cfg(test)]
32+
#[cfg(feature = "dtlsv1")]
3333
mod udp {
34-
static mut udp_port:u16 = 15410;
34+
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
35+
36+
static UDP_PORT: AtomicUsize = ATOMIC_USIZE_INIT;
3537

3638
pub fn next_server<'a>() -> String {
37-
unsafe {
38-
udp_port += 1;
39-
format!("127.0.0.1:{}", udp_port)
40-
}
39+
let diff = UDP_PORT.fetch_add(1, Ordering::SeqCst);
40+
format!("127.0.0.1:{}", 15411 + diff)
4141
}
4242
}
4343

@@ -60,13 +60,13 @@ macro_rules! run_test(
6060
use crypto::hash::Type::SHA256;
6161
use x509::X509StoreContext;
6262
use serialize::hex::FromHex;
63-
63+
6464
#[test]
6565
fn sslv23() {
6666
let stream = TcpStream::connect("127.0.0.1:15418").unwrap();
6767
$blk(SslMethod::Sslv23, stream);
6868
}
69-
69+
7070
#[test]
7171
#[cfg(feature="dtlsv1")]
7272
fn dtlsv1() {

0 commit comments

Comments
 (0)