Skip to content

Commit 37f385e

Browse files
bblumtoddaaro
authored andcommitted
Have linked failure tests run on the new scheduler instead of requiring RUST_NEWRT to test.
1 parent f7eed22 commit 37f385e

File tree

1 file changed

+152
-79
lines changed

1 file changed

+152
-79
lines changed

src/libstd/task/mod.rs

Lines changed: 152 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -677,121 +677,190 @@ fn block_forever() { let (po, _ch) = stream::<()>(); po.recv(); }
677677

678678
#[test] #[ignore(cfg(windows))]
679679
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);
684684
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.
688692
}
689-
fail!(); // Shouldn't kill either (grand)parent or (grand)child.
693+
po.recv();
690694
}
691-
po.recv();
692695
}
693696
#[test] #[ignore(cfg(windows))]
694697
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+
}
696702
}
697703
#[test] #[ignore(cfg(windows))]
698704
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+
}
702711
}
703-
#[test] #[should_fail] #[ignore(cfg(windows))]
712+
#[test] #[ignore(cfg(windows))]
704713
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+
}
707722
}
708723

709-
#[test] #[should_fail] #[ignore(cfg(windows))]
724+
#[test] #[ignore(cfg(windows))]
710725
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());
720742
}
721-
block_forever(); // We should get punted awake
722743
}
723-
#[test] #[should_fail] #[ignore(cfg(windows))]
744+
#[test] #[ignore(cfg(windows))]
724745
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+
}
732759
}
733-
#[test] #[should_fail] #[ignore(cfg(windows))]
760+
#[test] #[ignore(cfg(windows))]
734761
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+
}
738771
}
739-
#[test] #[should_fail] #[ignore(cfg(windows))]
772+
#[test] #[ignore(cfg(windows))]
740773
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+
}
744783
}
745-
#[test] #[should_fail] #[ignore(cfg(windows))]
784+
#[test] #[ignore(cfg(windows))]
746785
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+
}
752797
}
753798

754799
// A couple bonus linked failure tests - testing for failure propagation even
755800
// when the middle task exits successfully early before kill signals are sent.
756801

757-
#[test] #[should_fail] #[ignore(cfg(windows))]
802+
#[test] #[ignore(cfg(windows))]
758803
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());
762815
}
763-
do 16.times { task::yield(); }
764-
fail!();
765816
}
766817

767-
#[test] #[should_fail] #[ignore(cfg(windows))]
818+
#[test] #[ignore(cfg(windows))]
768819
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());
772831
}
773-
do 16.times { task::yield(); }
774-
fail!();
775832
}
776833

777-
#[test] #[should_fail] #[ignore(cfg(windows))]
834+
#[test] #[ignore(cfg(windows))]
778835
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());
782847
}
783-
do 16.times { task::yield(); }
784-
fail!();
785848
}
786849

787-
#[test] #[should_fail] #[ignore(cfg(windows))]
850+
#[test] #[ignore(cfg(windows))]
788851
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());
792863
}
793-
do 16.times { task::yield(); }
794-
fail!();
795864
}
796865

797866
#[test]
@@ -1149,11 +1218,15 @@ fn test_child_doesnt_ref_parent() {
11491218
fn child_no(x: uint) -> ~fn() {
11501219
return || {
11511220
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));
11531224
}
11541225
}
11551226
}
1156-
task::spawn(child_no(0));
1227+
let mut t = task();
1228+
t.unwatched();
1229+
t.spawn(child_no(0));
11571230
}
11581231

11591232
#[test]
@@ -1167,9 +1240,9 @@ fn test_simple_newsched_spawn() {
11671240

11681241
#[test] #[ignore(cfg(windows))]
11691242
fn test_spawn_watched() {
1170-
use rt::test::{run_in_newsched_task, spawntask_try};
1243+
use rt::test::run_in_newsched_task;
11711244
do run_in_newsched_task {
1172-
let result = do spawntask_try {
1245+
let result = do try {
11731246
let mut t = task();
11741247
t.unlinked();
11751248
t.watched();
@@ -1189,9 +1262,9 @@ fn test_spawn_watched() {
11891262

11901263
#[test] #[ignore(cfg(windows))]
11911264
fn test_indestructible() {
1192-
use rt::test::{run_in_newsched_task, spawntask_try};
1265+
use rt::test::run_in_newsched_task;
11931266
do run_in_newsched_task {
1194-
let result = do spawntask_try {
1267+
let result = do try {
11951268
let mut t = task();
11961269
t.watched();
11971270
t.supervised();

0 commit comments

Comments
 (0)