8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ // ignore-macos osx really doesn't like cycling through large numbers of
12
+ // sockets as calls to connect() will start returning EADDRNOTAVAIL
13
+ // quite quickly and it takes a few seconds for the sockets to get
14
+ // recycled.
15
+
11
16
#![ feature( phase) ]
12
17
13
18
#[ phase( plugin) ]
@@ -20,7 +25,7 @@ use std::task::TaskBuilder;
20
25
use native:: NativeTaskBuilder ;
21
26
22
27
static N : uint = 8 ;
23
- static M : uint = 100 ;
28
+ static M : uint = 20 ;
24
29
25
30
green_start ! ( main)
26
31
@@ -40,11 +45,12 @@ fn test() {
40
45
let mut a = l. listen ( ) . unwrap ( ) ;
41
46
let cnt = Arc :: new ( atomic:: AtomicUint :: new ( 0 ) ) ;
42
47
43
- let ( tx, rx) = channel ( ) ;
48
+ let ( srv_tx, srv_rx) = channel ( ) ;
49
+ let ( cli_tx, cli_rx) = channel ( ) ;
44
50
for _ in range ( 0 , N ) {
45
51
let a = a. clone ( ) ;
46
52
let cnt = cnt. clone ( ) ;
47
- let tx = tx . clone ( ) ;
53
+ let srv_tx = srv_tx . clone ( ) ;
48
54
spawn ( proc ( ) {
49
55
let mut a = a;
50
56
loop {
@@ -58,33 +64,36 @@ fn test() {
58
64
Err ( e) => fail ! ( "{}" , e) ,
59
65
}
60
66
}
61
- tx . send ( ( ) ) ;
67
+ srv_tx . send ( ( ) ) ;
62
68
} ) ;
63
69
}
64
70
65
71
for _ in range ( 0 , N ) {
66
- let tx = tx . clone ( ) ;
72
+ let cli_tx = cli_tx . clone ( ) ;
67
73
spawn ( proc ( ) {
68
74
for _ in range ( 0 , M ) {
69
75
let _s = TcpStream :: connect ( addr. ip . to_string ( ) . as_slice ( ) ,
70
76
addr. port ) . unwrap ( ) ;
71
77
}
72
- tx . send ( ( ) ) ;
78
+ cli_tx . send ( ( ) ) ;
73
79
} ) ;
74
80
}
75
- drop ( tx ) ;
81
+ drop ( ( cli_tx , srv_tx ) ) ;
76
82
77
83
// wait for senders
78
- assert_eq ! ( rx. iter( ) . take( N ) . count( ) , N ) ;
84
+ if cli_rx. iter ( ) . take ( N ) . count ( ) != N {
85
+ a. close_accept ( ) . unwrap ( ) ;
86
+ fail ! ( "clients failed" ) ;
87
+ }
79
88
80
89
// wait for one acceptor to die
81
- let _ = rx . recv ( ) ;
90
+ let _ = srv_rx . recv ( ) ;
82
91
83
92
// Notify other receivers should die
84
93
a. close_accept ( ) . unwrap ( ) ;
85
94
86
95
// wait for receivers
87
- assert_eq ! ( rx . iter( ) . take( N - 1 ) . count( ) , N - 1 ) ;
96
+ assert_eq ! ( srv_rx . iter( ) . take( N - 1 ) . count( ) , N - 1 ) ;
88
97
89
98
// Everything should have been accepted.
90
99
assert_eq ! ( cnt. load( atomic:: SeqCst ) , N * M ) ;
0 commit comments