@@ -677,121 +677,190 @@ fn block_forever() { let (po, _ch) = stream::<()>(); po.recv(); }
677
677
678
678
#[ test] #[ ignore( cfg( windows) ) ]
679
679
fn test_spawn_unlinked_unsup_no_fail_down ( ) { // grandchild sends on a port
680
- let ( po , ch ) = stream ( ) ;
681
- let ch = SharedChan :: new ( ch ) ;
682
- do spawn_unlinked {
683
- let ch = ch . clone ( ) ;
680
+ use rt :: test :: run_in_newsched_task ;
681
+ do run_in_newsched_task {
682
+ let ( po , ch ) = stream ( ) ;
683
+ let ch = SharedChan :: new ( ch ) ;
684
684
do spawn_unlinked {
685
- // Give middle task a chance to fail-but-not-kill-us.
686
- do 16 . times { task : : yield ( ) ; }
687
- ch. send ( ( ) ) ; // If killed first, grandparent hangs.
685
+ let ch = ch. clone ( ) ;
686
+ do spawn_unlinked {
687
+ // Give middle task a chance to fail-but-not-kill-us.
688
+ for 16 . times { task : : yield ( ) ; }
689
+ ch. send ( ( ) ) ; // If killed first, grandparent hangs.
690
+ }
691
+ fail ! ( ) ; // Shouldn't kill either (grand)parent or (grand)child.
688
692
}
689
- fail ! ( ) ; // Shouldn't kill either (grand)parent or (grand)child.
693
+ po . recv ( ) ;
690
694
}
691
- po. recv ( ) ;
692
695
}
693
696
#[ test] #[ ignore( cfg( windows) ) ]
694
697
fn test_spawn_unlinked_unsup_no_fail_up ( ) { // child unlinked fails
695
- do spawn_unlinked { fail!( ) ; }
698
+ use rt:: test:: run_in_newsched_task;
699
+ do run_in_newsched_task {
700
+ do spawn_unlinked { fail!( ) ; }
701
+ }
696
702
}
697
703
#[ test] #[ ignore( cfg( windows) ) ]
698
704
fn test_spawn_unlinked_sup_no_fail_up ( ) { // child unlinked fails
699
- do spawn_supervised { fail!( ) ; }
700
- // Give child a chance to fail-but-not-kill-us.
701
- do 16 . times { task:: yield ( ) ; }
705
+ use rt:: test:: run_in_newsched_task;
706
+ do run_in_newsched_task {
707
+ do spawn_supervised { fail!( ) ; }
708
+ // Give child a chance to fail-but-not-kill-us.
709
+ for 16 . times { task : : yield( ) ; }
710
+ }
702
711
}
703
- #[ test] #[ should_fail ] # [ ignore( cfg( windows) ) ]
712
+ #[ test] #[ ignore( cfg( windows) ) ]
704
713
fn test_spawn_unlinked_sup_fail_down( ) {
705
- do spawn_supervised { block_forever( ) ; }
706
- fail ! ( ) ; // Shouldn't leave a child hanging around.
714
+ use rt:: test:: run_in_newsched_task;
715
+ do run_in_newsched_task {
716
+ let result : Result <( ) , ( ) > = do try {
717
+ do spawn_supervised { block_forever( ) ; }
718
+ fail ! ( ) ; // Shouldn't leave a child hanging around.
719
+ } ;
720
+ assert ! ( result. is_err( ) ) ;
721
+ }
707
722
}
708
723
709
- #[ test] #[ should_fail ] # [ ignore( cfg( windows) ) ]
724
+ #[ test] #[ ignore( cfg( windows) ) ]
710
725
fn test_spawn_linked_sup_fail_up ( ) { // child fails; parent fails
711
- // Unidirectional "parenting" shouldn't override bidirectional linked.
712
- // We have to cheat with opts - the interface doesn't support them because
713
- // they don't make sense (redundant with task().supervised()).
714
- let mut b0 = task ( ) ;
715
- b0. opts . linked = true ;
716
- b0. opts . supervised = true ;
717
-
718
- do b0. spawn {
719
- fail ! ( ) ;
726
+ use rt:: test:: run_in_newsched_task;
727
+ do run_in_newsched_task {
728
+ let result : Result <( ) , ( ) > = do try {
729
+ // Unidirectional "parenting" shouldn't override bidirectional linked.
730
+ // We have to cheat with opts - the interface doesn't support them because
731
+ // they don't make sense (redundant with task().supervised()).
732
+ let mut b0 = task ( ) ;
733
+ b0. opts . linked = true ;
734
+ b0. opts . supervised = true ;
735
+
736
+ do b0. spawn {
737
+ fail ! ( ) ;
738
+ }
739
+ block_forever ( ) ; // We should get punted awake
740
+ } ;
741
+ assert ! ( result. is_err( ) ) ;
720
742
}
721
- block_forever ( ) ; // We should get punted awake
722
743
}
723
- #[ test] #[ should_fail ] # [ ignore( cfg( windows) ) ]
744
+ #[ test] #[ ignore( cfg( windows) ) ]
724
745
fn test_spawn_linked_sup_fail_down ( ) { // parent fails; child fails
725
- // We have to cheat with opts - the interface doesn't support them because
726
- // they don't make sense (redundant with task().supervised()).
727
- let mut b0 = task ( ) ;
728
- b0. opts . linked = true ;
729
- b0. opts . supervised = true ;
730
- do b0. spawn { block_forever ( ) ; }
731
- fail ! ( ) ; // *both* mechanisms would be wrong if this didn't kill the child
746
+ use rt:: test:: run_in_newsched_task;
747
+ do run_in_newsched_task {
748
+ let result : Result <( ) , ( ) > = do try {
749
+ // We have to cheat with opts - the interface doesn't support them because
750
+ // they don't make sense (redundant with task().supervised()).
751
+ let mut b0 = task ( ) ;
752
+ b0. opts . linked = true ;
753
+ b0. opts . supervised = true ;
754
+ do b0. spawn { block_forever ( ) ; }
755
+ fail ! ( ) ; // *both* mechanisms would be wrong if this didn't kill the child
756
+ } ;
757
+ assert ! ( result. is_err( ) ) ;
758
+ }
732
759
}
733
- #[ test] #[ should_fail ] # [ ignore( cfg( windows) ) ]
760
+ #[ test] #[ ignore( cfg( windows) ) ]
734
761
fn test_spawn_linked_unsup_fail_up ( ) { // child fails; parent fails
735
- // Default options are to spawn linked & unsupervised.
736
- do spawn { fail!( ) ; }
737
- block_forever ( ) ; // We should get punted awake
762
+ use rt:: test:: run_in_newsched_task;
763
+ do run_in_newsched_task {
764
+ let result : Result <( ) , ( ) > = do try {
765
+ // Default options are to spawn linked & unsupervised.
766
+ do spawn { fail!( ) ; }
767
+ block_forever ( ) ; // We should get punted awake
768
+ } ;
769
+ assert ! ( result. is_err( ) ) ;
770
+ }
738
771
}
739
- #[ test] #[ should_fail ] # [ ignore( cfg( windows) ) ]
772
+ #[ test] #[ ignore( cfg( windows) ) ]
740
773
fn test_spawn_linked_unsup_fail_down ( ) { // parent fails; child fails
741
- // Default options are to spawn linked & unsupervised.
742
- do spawn { block_forever( ) ; }
743
- fail ! ( ) ;
774
+ use rt:: test:: run_in_newsched_task;
775
+ do run_in_newsched_task {
776
+ let result : Result <( ) , ( ) > = do try {
777
+ // Default options are to spawn linked & unsupervised.
778
+ do spawn { block_forever( ) ; }
779
+ fail ! ( ) ;
780
+ } ;
781
+ assert ! ( result. is_err( ) ) ;
782
+ }
744
783
}
745
- #[ test] #[ should_fail ] # [ ignore( cfg( windows) ) ]
784
+ #[ test] #[ ignore( cfg( windows) ) ]
746
785
fn test_spawn_linked_unsup_default_opts ( ) { // parent fails; child fails
747
- // Make sure the above test is the same as this one.
748
- let mut builder = task ( ) ;
749
- builder. linked ( ) ;
750
- do builder. spawn { block_forever ( ) ; }
751
- fail ! ( ) ;
786
+ use rt:: test:: run_in_newsched_task;
787
+ do run_in_newsched_task {
788
+ let result : Result <( ) , ( ) > = do try {
789
+ // Make sure the above test is the same as this one.
790
+ let mut builder = task ( ) ;
791
+ builder. linked ( ) ;
792
+ do builder. spawn { block_forever ( ) ; }
793
+ fail ! ( ) ;
794
+ } ;
795
+ assert ! ( result. is_err( ) ) ;
796
+ }
752
797
}
753
798
754
799
// A couple bonus linked failure tests - testing for failure propagation even
755
800
// when the middle task exits successfully early before kill signals are sent.
756
801
757
- #[ test] #[ should_fail ] # [ ignore( cfg( windows) ) ]
802
+ #[ test] #[ ignore( cfg( windows) ) ]
758
803
fn test_spawn_failure_propagate_grandchild ( ) {
759
- // Middle task exits; does grandparent's failure propagate across the gap?
760
- do spawn_supervised {
761
- do spawn_supervised { block_forever( ) ; }
804
+ use rt:: test:: run_in_newsched_task;
805
+ do run_in_newsched_task {
806
+ let result : Result <( ) , ( ) > = do try {
807
+ // Middle task exits; does grandparent's failure propagate across the gap?
808
+ do spawn_supervised {
809
+ do spawn_supervised { block_forever( ) ; }
810
+ }
811
+ for 16 . times { task : : yield( ) ; }
812
+ fail ! ( ) ;
813
+ } ;
814
+ assert ! ( result. is_err( ) ) ;
762
815
}
763
- do 16 . times { task:: yield ( ) ; }
764
- fail ! ( ) ;
765
816
}
766
817
767
- #[ test] #[ should_fail ] # [ ignore( cfg( windows) ) ]
818
+ #[ test] #[ ignore( cfg( windows) ) ]
768
819
fn test_spawn_failure_propagate_secondborn( ) {
769
- // First-born child exits; does parent's failure propagate to sibling?
770
- do spawn_supervised {
771
- do spawn { block_forever( ) ; } // linked
820
+ use rt:: test:: run_in_newsched_task;
821
+ do run_in_newsched_task {
822
+ let result : Result <( ) , ( ) > = do try {
823
+ // First-born child exits; does parent's failure propagate to sibling?
824
+ do spawn_supervised {
825
+ do spawn { block_forever( ) ; } // linked
826
+ }
827
+ for 16 . times { task:: yield ( ) ; }
828
+ fail ! ( ) ;
829
+ } ;
830
+ assert ! ( result. is_err( ) ) ;
772
831
}
773
- do 16 . times { task:: yield ( ) ; }
774
- fail ! ( ) ;
775
832
}
776
833
777
- #[ test] #[ should_fail ] # [ ignore( cfg( windows) ) ]
834
+ #[ test] #[ ignore( cfg( windows) ) ]
778
835
fn test_spawn_failure_propagate_nephew_or_niece ( ) {
779
- // Our sibling exits; does our failure propagate to sibling's child?
780
- do spawn { // linked
781
- do spawn_supervised { block_forever( ) ; }
836
+ use rt:: test:: run_in_newsched_task;
837
+ do run_in_newsched_task {
838
+ let result : Result <( ) , ( ) > = do try {
839
+ // Our sibling exits; does our failure propagate to sibling's child?
840
+ do spawn { // linked
841
+ do spawn_supervised { block_forever( ) ; }
842
+ }
843
+ for 16 . times { task : : yield( ) ; }
844
+ fail ! ( ) ;
845
+ } ;
846
+ assert ! ( result. is_err( ) ) ;
782
847
}
783
- do 16 . times { task:: yield ( ) ; }
784
- fail ! ( ) ;
785
848
}
786
849
787
- #[ test] #[ should_fail ] # [ ignore( cfg( windows) ) ]
850
+ #[ test] #[ ignore( cfg( windows) ) ]
788
851
fn test_spawn_linked_sup_propagate_sibling( ) {
789
- // Middle sibling exits - does eldest's failure propagate to youngest?
790
- do spawn { // linked
791
- do spawn { block_forever( ) ; } // linked
852
+ use rt:: test:: run_in_newsched_task;
853
+ do run_in_newsched_task {
854
+ let result : Result <( ) , ( ) > = do try {
855
+ // Middle sibling exits - does eldest's failure propagate to youngest?
856
+ do spawn { // linked
857
+ do spawn { block_forever( ) ; } // linked
858
+ }
859
+ for 16 . times { task:: yield ( ) ; }
860
+ fail ! ( ) ;
861
+ } ;
862
+ assert ! ( result. is_err( ) ) ;
792
863
}
793
- do 16 . times { task:: yield ( ) ; }
794
- fail ! ( ) ;
795
864
}
796
865
797
866
#[ test]
@@ -1149,11 +1218,15 @@ fn test_child_doesnt_ref_parent() {
1149
1218
fn child_no( x: uint) -> ~fn ( ) {
1150
1219
return || {
1151
1220
if x < generations {
1152
- task:: spawn( child_no( x+1 ) ) ;
1221
+ let mut t = task( ) ;
1222
+ t. unwatched( ) ;
1223
+ t. spawn( child_no( x+1 ) ) ;
1153
1224
}
1154
1225
}
1155
1226
}
1156
- task:: spawn( child_no( 0 ) ) ;
1227
+ let mut t = task( ) ;
1228
+ t. unwatched( ) ;
1229
+ t. spawn( child_no( 0 ) ) ;
1157
1230
}
1158
1231
1159
1232
#[ test]
@@ -1167,9 +1240,9 @@ fn test_simple_newsched_spawn() {
1167
1240
1168
1241
#[ test] #[ ignore( cfg( windows) ) ]
1169
1242
fn test_spawn_watched( ) {
1170
- use rt:: test:: { run_in_newsched_task, spawntask_try } ;
1243
+ use rt:: test:: run_in_newsched_task;
1171
1244
do run_in_newsched_task {
1172
- let result = do spawntask_try {
1245
+ let result = do try {
1173
1246
let mut t = task( ) ;
1174
1247
t. unlinked( ) ;
1175
1248
t. watched( ) ;
@@ -1189,9 +1262,9 @@ fn test_spawn_watched() {
1189
1262
1190
1263
#[ test] #[ ignore( cfg( windows) ) ]
1191
1264
fn test_indestructible( ) {
1192
- use rt:: test:: { run_in_newsched_task, spawntask_try } ;
1265
+ use rt:: test:: run_in_newsched_task;
1193
1266
do run_in_newsched_task {
1194
- let result = do spawntask_try {
1267
+ let result = do try {
1195
1268
let mut t = task( ) ;
1196
1269
t. watched( ) ;
1197
1270
t. supervised( ) ;
0 commit comments