Skip to content

Commit c01d05f

Browse files
committed
std: Add 2 timer stress tests
1 parent caab575 commit c01d05f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/libstd/timer.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,47 @@ mod test {
141141
sleep(1u);
142142
}
143143

144+
#[test]
145+
fn test_gl_timer_sleep_stress1() {
146+
iter::repeat(500u) {||
147+
sleep(1u);
148+
}
149+
}
150+
151+
#[test]
152+
fn test_gl_timer_sleep_stress2() {
153+
let po = comm::port();
154+
let ch = comm::chan(po);
155+
156+
let repeat = 100u;
157+
let spec = {
158+
159+
[(1u, 100u),
160+
(10u, 10u),
161+
(100u, 2u)]
162+
163+
};
164+
165+
iter::repeat(repeat) {||
166+
167+
for spec.each {|spec|
168+
let (times, maxms) = spec;
169+
task::spawn {||
170+
import rand::*;
171+
let rng = rng();
172+
iter::repeat(times) {||
173+
sleep(rng.next() as uint % maxms);
174+
}
175+
comm::send(ch, ());
176+
}
177+
}
178+
}
179+
180+
iter::repeat(repeat * spec.len()) {||
181+
comm::recv(po)
182+
}
183+
}
184+
144185
#[test]
145186
fn test_gl_timer_recv_timeout_before_time_passes() {
146187
let expected = rand::rng().gen_str(16u);

0 commit comments

Comments
 (0)