Skip to content

Commit e6bb2e1

Browse files
committed
Clean integration tests code
1 parent a13cfc2 commit e6bb2e1

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

wait/tests/integration_test.rs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,7 @@ fn should_identify_the_open_port() {
8585
let mut fun = || { count.inc(); };
8686
assert_eq!(0, count.get());
8787

88-
thread::spawn(move || {
89-
loop {
90-
match tcpListener.accept() {
91-
Ok(_) => { println!("Connection received!"); }
92-
Err(_) => { println!("Error in received connection!"); }
93-
}
94-
}
95-
});
88+
listen_async(tcpListener);
9689

9790
thread::sleep(time::Duration::from_millis(250));
9891
wait::wait(&sleeper, &new_config(&hosts, timeout, wait_before, wait_after ), &mut fun);
@@ -119,23 +112,8 @@ fn should_wait_multiple_hosts() {
119112
let mut fun = || { count.inc(); };
120113
assert_eq!(0, count.get());
121114

122-
thread::spawn(move || {
123-
loop {
124-
match tcpListener1.accept() {
125-
Ok(_) => { println!("Connection received!"); }
126-
Err(_) => { println!("Error in received connection!"); }
127-
}
128-
}
129-
});
130-
131-
thread::spawn(move || {
132-
loop {
133-
match tcpListener2.accept() {
134-
Ok(_) => { println!("Connection received!"); }
135-
Err(_) => { println!("Error in received connection!"); }
136-
}
137-
}
138-
});
115+
listen_async(tcpListener1);
116+
listen_async(tcpListener2);
139117

140118
thread::sleep(time::Duration::from_millis(250));
141119
wait::wait(&sleeper, &new_config(&hosts, timeout, wait_before, wait_after ), &mut fun);
@@ -161,14 +139,7 @@ fn should_fail_if_not_all_hosts_are_available() {
161139
let mut fun = || { count.inc(); };
162140
assert_eq!(0, count.get());
163141

164-
thread::spawn(move || {
165-
loop {
166-
match tcpListener1.accept() {
167-
Ok(_) => { println!("Connection received!"); }
168-
Err(_) => { println!("Error in received connection!"); }
169-
}
170-
}
171-
});
142+
listen_async(tcpListener1);
172143

173144
thread::sleep(time::Duration::from_millis(250));
174145
wait::wait(&sleeper, &new_config(&hosts, timeout, wait_before, wait_after ), &mut fun);
@@ -196,6 +167,17 @@ fn newTcpListener() -> TcpListener {
196167
TcpListener::bind(socket).unwrap()
197168
}
198169

170+
fn listen_async(listener: TcpListener) {
171+
thread::spawn(move || {
172+
loop {
173+
match listener.accept() {
174+
Ok(_) => { println!("Connection received!"); }
175+
Err(_) => { println!("Error in received connection!"); }
176+
}
177+
}
178+
});
179+
}
180+
199181
fn free_port() -> u16 {
200182
newTcpListener().local_addr().unwrap().port()
201183
}

0 commit comments

Comments
 (0)