Skip to content

Commit 22f492a

Browse files
committed
Linked failure: add {un,}linked {un,}parented fail-{up,down} tests.
1 parent 20831d3 commit 22f492a

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

src/libcore/task.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,83 @@ fn test_spawn_raw_unsupervise() {
11531153
}
11541154
}
11551155

1156+
// The following 8 tests test the following 2^3 combinations:
1157+
// {un,}linked {un,}supervised failure propagation {up,down}wards.
1158+
1159+
#[test] #[ignore(cfg(windows))]
1160+
fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
1161+
let po = comm::port();
1162+
let ch = comm::chan(po);
1163+
let builder = task::builder();
1164+
task::unsupervise(builder);
1165+
do task::run(builder) {
1166+
let builder = task::builder();
1167+
task::unsupervise(builder);
1168+
do task::run(builder) {
1169+
// Give middle task a chance to fail-but-not-kill-us.
1170+
for iter::repeat(8192) { task::yield(); }
1171+
comm::send(ch, ()); // If killed first, grandparent hangs.
1172+
}
1173+
fail; // Shouldn't kill either (grand)parent or (grand)child.
1174+
}
1175+
comm::recv(po);
1176+
}
1177+
#[test] #[ignore(cfg(windows))]
1178+
fn test_spawn_unlinked_unsup_no_fail_up() { // child unlinked fails
1179+
let builder = task::builder();
1180+
task::unsupervise(builder);
1181+
do task::run(builder) { fail; }
1182+
}
1183+
#[test] #[ignore(cfg(windows))]
1184+
fn test_spawn_unlinked_sup_no_fail_up() { // child unlinked fails
1185+
let builder = task::builder();
1186+
task::unsupervise(builder);
1187+
task::parent(builder);
1188+
do task::run(builder) { fail; }
1189+
// Give child a chance to fail-but-not-kill-us.
1190+
for iter::repeat(8192) { task::yield(); }
1191+
}
1192+
#[test] #[should_fail] #[ignore(cfg(windows))]
1193+
fn test_spawn_unlinked_sup_fail_down() {
1194+
let builder = task::builder();
1195+
task::unsupervise(builder);
1196+
task::parent(builder);
1197+
do task::run(builder) { loop { task::yield(); } }
1198+
fail; // Shouldn't leave a child hanging around.
1199+
}
1200+
1201+
#[test] #[should_fail] #[ignore(cfg(windows))]
1202+
fn test_spawn_linked_sup_fail_up() { // child fails; parent fails
1203+
let po = comm::port::<()>();
1204+
let _ch = comm::chan(po);
1205+
let builder = task::builder();
1206+
task::parent(builder);
1207+
// Unidirectional "parenting" shouldn't override bidirectional linked.
1208+
do task::run(builder) { fail; }
1209+
comm::recv(po); // We should get punted awake
1210+
}
1211+
#[test] #[should_fail] #[ignore(cfg(windows))]
1212+
fn test_spawn_linked_sup_fail_down() { // parent fails; child fails
1213+
let builder = task::builder();
1214+
task::parent(builder);
1215+
do task::run(builder) { loop { task::yield(); } }
1216+
fail; // *both* mechanisms would be wrong if this didn't kill the child...
1217+
}
1218+
#[test] #[should_fail] #[ignore(cfg(windows))]
1219+
fn test_spawn_linked_unsup_fail_up() { // child fails; parent fails
1220+
let po = comm::port::<()>();
1221+
let _ch = comm::chan(po);
1222+
// Default options are to spawn linked & unsupervised.
1223+
do task::spawn { fail; }
1224+
comm::recv(po); // We should get punted awake
1225+
}
1226+
#[test] #[should_fail] #[ignore(cfg(windows))]
1227+
fn test_spawn_linked_unsup_fail_down() { // parent fails; child fails
1228+
// Default options are to spawn linked & unsupervised.
1229+
do task::spawn { loop { task::yield(); } }
1230+
fail;
1231+
}
1232+
11561233
#[test]
11571234
#[ignore(cfg(windows))]
11581235
fn test_spawn_raw_notify() {

0 commit comments

Comments
 (0)