@@ -151,6 +151,11 @@ impl Select {
151
151
/// event could either be that data is available or the corresponding
152
152
/// channel has been closed.
153
153
pub fn wait ( & self ) -> uint {
154
+ self . wait2 ( false )
155
+ }
156
+
157
+ /// Helper method for skipping the preflight checks during testing
158
+ fn wait2 ( & self , do_preflight_checks : bool ) -> uint {
154
159
// Note that this is currently an inefficient implementation. We in
155
160
// theory have knowledge about all ports in the set ahead of time, so
156
161
// this method shouldn't really have to iterate over all of them yet
@@ -175,7 +180,7 @@ impl Select {
175
180
let mut amt = 0 ;
176
181
for p in self . iter ( ) {
177
182
amt += 1 ;
178
- if ( * p) . packet . can_recv ( ) {
183
+ if do_preflight_checks && ( * p) . packet . can_recv ( ) {
179
184
return ( * p) . id ;
180
185
}
181
186
}
@@ -507,7 +512,7 @@ mod test {
507
512
let ( p2, c2) = Chan :: <( ) >:: new( ) ;
508
513
let ( p, c) = Chan :: new( ) ;
509
514
spawn( proc( ) {
510
- let mut s = Select :: new( ) ;
515
+ let s = Select :: new( ) ;
511
516
let mut h1 = s. handle( & p1) ;
512
517
let mut h2 = s. handle( & p2) ;
513
518
unsafe { h2. add( ) ; }
@@ -521,4 +526,91 @@ mod test {
521
526
c2. send( ( ) ) ;
522
527
p. recv( ) ;
523
528
} )
529
+
530
+ test ! ( fn preflight1( ) {
531
+ let ( p, c) = Chan :: new( ) ;
532
+ c. send( ( ) ) ;
533
+ select!(
534
+ ( ) = p. recv( ) => { } ,
535
+ )
536
+ } )
537
+
538
+ test ! ( fn preflight2( ) {
539
+ let ( p, c) = Chan :: new( ) ;
540
+ c. send( ( ) ) ;
541
+ c. send( ( ) ) ;
542
+ select!(
543
+ ( ) = p. recv( ) => { } ,
544
+ )
545
+ } )
546
+
547
+ test ! ( fn preflight3( ) {
548
+ let ( p, c) = Chan :: new( ) ;
549
+ drop( c. clone( ) ) ;
550
+ c. send( ( ) ) ;
551
+ select!(
552
+ ( ) = p. recv( ) => { } ,
553
+ )
554
+ } )
555
+
556
+ test ! ( fn preflight4( ) {
557
+ let ( p, c) = Chan :: new( ) ;
558
+ c. send( ( ) ) ;
559
+ let s = Select :: new( ) ;
560
+ let mut h = s. handle( & p) ;
561
+ unsafe { h. add( ) ; }
562
+ assert_eq!( s. wait2( false ) , h. id) ;
563
+ } )
564
+
565
+ test ! ( fn preflight5( ) {
566
+ let ( p, c) = Chan :: new( ) ;
567
+ c. send( ( ) ) ;
568
+ c. send( ( ) ) ;
569
+ let s = Select :: new( ) ;
570
+ let mut h = s. handle( & p) ;
571
+ unsafe { h. add( ) ; }
572
+ assert_eq!( s. wait2( false ) , h. id) ;
573
+ } )
574
+
575
+ test ! ( fn preflight6( ) {
576
+ let ( p, c) = Chan :: new( ) ;
577
+ drop( c. clone( ) ) ;
578
+ c. send( ( ) ) ;
579
+ let s = Select :: new( ) ;
580
+ let mut h = s. handle( & p) ;
581
+ unsafe { h. add( ) ; }
582
+ assert_eq!( s. wait2( false ) , h. id) ;
583
+ } )
584
+
585
+ test ! ( fn preflight7( ) {
586
+ let ( p, c) = Chan :: <( ) >:: new( ) ;
587
+ drop( c) ;
588
+ let s = Select :: new( ) ;
589
+ let mut h = s. handle( & p) ;
590
+ unsafe { h. add( ) ; }
591
+ assert_eq!( s. wait2( false ) , h. id) ;
592
+ } )
593
+
594
+ test ! ( fn preflight8( ) {
595
+ let ( p, c) = Chan :: new( ) ;
596
+ c. send( ( ) ) ;
597
+ drop( c) ;
598
+ p. recv( ) ;
599
+ let s = Select :: new( ) ;
600
+ let mut h = s. handle( & p) ;
601
+ unsafe { h. add( ) ; }
602
+ assert_eq!( s. wait2( false ) , h. id) ;
603
+ } )
604
+
605
+ test ! ( fn preflight9( ) {
606
+ let ( p, c) = Chan :: new( ) ;
607
+ drop( c. clone( ) ) ;
608
+ c. send( ( ) ) ;
609
+ drop( c) ;
610
+ p. recv( ) ;
611
+ let s = Select :: new( ) ;
612
+ let mut h = s. handle( & p) ;
613
+ unsafe { h. add( ) ; }
614
+ assert_eq!( s. wait2( false ) , h. id) ;
615
+ } )
524
616
}
0 commit comments