@@ -64,9 +64,11 @@ fn shared_close_sender_does_not_lose_messages_iter() {
6464
6565#[ test]  
6666fn  shared_close_sender_does_not_lose_messages ( )  { 
67-     for  _ in  0 ..10000  { 
68-         shared_close_sender_does_not_lose_messages_iter ( ) ; 
69-     } 
67+     with_minimum_timer_resolution ( || { 
68+         for  _ in  0 ..10000  { 
69+             shared_close_sender_does_not_lose_messages_iter ( ) ; 
70+         } 
71+     } ) ; 
7072} 
7173
7274
@@ -96,17 +98,11 @@ fn concurrent_recv_timeout_and_upgrade_iter() {
9698
9799#[ test]  
98100fn  concurrent_recv_timeout_and_upgrade ( )  { 
99-     // FIXME: fix and enable 
100-     if  true  {  return  } 
101- 
102-     // at the moment of writing this test fails like this: 
103-     // thread '<unnamed>' panicked at 'assertion failed: `(left == right)` 
104-     //  left: `4561387584`, 
105-     // right: `0`', libstd/sync/mpsc/shared.rs:253:13 
106- 
107-     for  _ in  0 ..10000  { 
108-         concurrent_recv_timeout_and_upgrade_iter ( ) ; 
109-     } 
101+     with_minimum_timer_resolution ( || { 
102+         for  _ in  0 ..10000  { 
103+             concurrent_recv_timeout_and_upgrade_iter ( ) ; 
104+         } 
105+     } ) ; 
110106} 
111107
112108
@@ -159,7 +155,46 @@ fn concurrent_writes_iter() {
159155
160156#[ test]  
161157fn  concurrent_writes ( )  { 
162-     for  _ in  0 ..100  { 
163-         concurrent_writes_iter ( ) ; 
158+     with_minimum_timer_resolution ( || { 
159+         for  _ in  0 ..100  { 
160+             concurrent_writes_iter ( ) ; 
161+         } 
162+     } ) ; 
163+ } 
164+ 
165+ #[ cfg( windows) ]  
166+ pub  mod  timeapi { 
167+     #![ allow( non_snake_case) ]  
168+     use  std:: ffi:: c_uint; 
169+ 
170+     pub  const  TIMERR_NOERROR :  c_uint  = 0 ; 
171+ 
172+     #[ link( name = "winmm" ) ]  
173+     extern  "system"  { 
174+         pub  fn  timeBeginPeriod ( uPeriod :  c_uint )  -> c_uint ; 
175+         pub  fn  timeEndPeriod ( uPeriod :  c_uint )  -> c_uint ; 
176+     } 
177+ } 
178+ 
179+ /// Window's minimum sleep time can be as much as 16ms. 
180+ // This function evaluates the closure with this resolution 
181+ // set as low as possible. 
182+ /// 
183+ /// This takes the above test's duration from 10000*16/1000/60=2.67 minutes to ~16 seconds. 
184+ fn  with_minimum_timer_resolution ( f :  impl  Fn ( ) )  { 
185+     #[ cfg( windows) ]  
186+     unsafe  { 
187+         let  ret = timeapi:: timeBeginPeriod ( 1 ) ; 
188+         assert_eq ! ( ret,  timeapi:: TIMERR_NOERROR ) ; 
189+ 
190+         f ( ) ; 
191+ 
192+         let  ret = timeapi:: timeEndPeriod ( 1 ) ; 
193+         assert_eq ! ( ret,  timeapi:: TIMERR_NOERROR ) ; 
194+     } 
195+ 
196+     #[ cfg( not( windows) ) ]  
197+     { 
198+         f ( ) ; 
164199    } 
165200} 
0 commit comments