From c480c7beecc5082f154bee2e006d65c6a28e0262 Mon Sep 17 00:00:00 2001 From: Alan Knight Date: Wed, 25 Nov 2015 14:33:09 -0800 Subject: [PATCH] Fix tests that don't catch asynchronous errors from isolate spawning. Update co19 status. BUG= Review URL: https://codereview.chromium.org/1477043002 . --- tests/co19/co19-dartium.status | 14 ++-- .../issue_21398_parent_isolate1_test.dart | 76 +++++++++++-------- .../issue_21398_parent_isolate2_test.dart | 4 + .../issue_21398_parent_isolate_test.dart | 9 ++- tests/isolate/message_enum_test.dart | 4 +- tests/language/issue23244_test.dart | 4 +- .../typed_array_int64_uint64_test.dart | 25 ++++-- tests/standalone/typed_array_test.dart | 70 +++++++++++------ 8 files changed, 135 insertions(+), 71 deletions(-) diff --git a/tests/co19/co19-dartium.status b/tests/co19/co19-dartium.status index 97e699dda32..532bc564fad 100644 --- a/tests/co19/co19-dartium.status +++ b/tests/co19/co19-dartium.status @@ -827,24 +827,24 @@ LibTest/isolate/Isolate/spawn_A01_t04: RuntimeError # co19-roll r667: Please tri LibTest/isolate/Isolate/spawn_A01_t05: RuntimeError # co19-roll r667: Please triage this failure LibTest/isolate/RawReceivePort/RawReceivePort_A01_t01: RuntimeError # Issue 13921 LibTest/isolate/RawReceivePort/RawReceivePort_A01_t02: RuntimeError # Issue 13921 -LibTest/isolate/RawReceivePort/close_A01_t01: RuntimeError # Issue 13921 +LibTest/isolate/RawReceivePort/close_A01_t01: Pass # Issue 13921, co19 issue for false pass https://github.com/dart-lang/co19/issues/13 LibTest/isolate/RawReceivePort/handler_A01_t01: RuntimeError # Issue 13921 LibTest/isolate/RawReceivePort/sendPort_A01_t01: RuntimeError # Issue 13921 LibTest/isolate/ReceivePort/any_A01_t01: RuntimeError # Issue 13921 LibTest/isolate/ReceivePort/any_A01_t02: RuntimeError # Issue 13921 LibTest/isolate/ReceivePort/asBroadcastStream_A01_t01: RuntimeError # Issue 13921 -LibTest/isolate/ReceivePort/asBroadcastStream_A01_t02: RuntimeError # Issue 13921 +LibTest/isolate/ReceivePort/asBroadcastStream_A01_t02: Pass # Issue 13921, co19 issue for false pass https://github.com/dart-lang/co19/issues/13 LibTest/isolate/ReceivePort/asBroadcastStream_A01_t03: RuntimeError # Issue 13921 LibTest/isolate/ReceivePort/asBroadcastStream_A01_t04: RuntimeError # Issue 13921 LibTest/isolate/ReceivePort/asBroadcastStream_A02_t01: RuntimeError # Issue 13921 -LibTest/isolate/ReceivePort/asBroadcastStream_A03_t01: RuntimeError # Issue 13921 -LibTest/isolate/ReceivePort/asBroadcastStream_A03_t02: RuntimeError # Issue 13921 -LibTest/isolate/ReceivePort/asBroadcastStream_A03_t03: RuntimeError # Issue 13921 +LibTest/isolate/ReceivePort/asBroadcastStream_A03_t01: Pass, RuntimeError # Issue 13921, co19 issue for false pass https://github.com/dart-lang/co19/issues/13 +LibTest/isolate/ReceivePort/asBroadcastStream_A03_t02: Pass, RuntimeError # Issue 13921, co19 issue for false pass https://github.com/dart-lang/co19/issues/13 +LibTest/isolate/ReceivePort/asBroadcastStream_A03_t03: Pass, RuntimeError # Issue 13921, co19 issue for false pass https://github.com/dart-lang/co19/issues/13 LibTest/isolate/ReceivePort/asBroadcastStream_A04_t01: RuntimeError # Issue 13921 LibTest/isolate/ReceivePort/asBroadcastStream_A04_t02: RuntimeError # Issue 13921 LibTest/isolate/ReceivePort/asBroadcastStream_A04_t03: RuntimeError # Issue 13921 -LibTest/isolate/ReceivePort/close_A01_t01: RuntimeError # Issue 13921 -LibTest/isolate/ReceivePort/close_A02_t01: RuntimeError # Issue 13921 +LibTest/isolate/ReceivePort/close_A01_t01: Pass # Issue 13921, co19 issue for false pass https://github.com/dart-lang/co19/issues/13 +LibTest/isolate/ReceivePort/close_A02_t01: Pass # Issue 13921, co19 issue for false pass https://github.com/dart-lang/co19/issues/13 LibTest/isolate/ReceivePort/contains_A01_t01: RuntimeError # Issue 13921 LibTest/isolate/ReceivePort/distinct_A01_t01: RuntimeError # Issue 13921 LibTest/isolate/ReceivePort/distinct_A01_t02: RuntimeError # Issue 13921 diff --git a/tests/isolate/issue_21398_parent_isolate1_test.dart b/tests/isolate/issue_21398_parent_isolate1_test.dart index 1c3aeb88b88..6f036bd771a 100644 --- a/tests/isolate/issue_21398_parent_isolate1_test.dart +++ b/tests/isolate/issue_21398_parent_isolate1_test.dart @@ -10,6 +10,7 @@ import 'dart:isolate'; import 'dart:async'; import "package:expect/expect.dart"; +import 'package:async_helper/async_helper.dart'; class FromMainIsolate { String toString() => 'from main isolate'; @@ -25,6 +26,7 @@ func1Child(args) { Expect.isTrue(msg is FromMainIsolate); Expect.equals(10, msg.fld); receivePort.close(); + sendPort.send("done"); }, onError: (e) => print('$e') ); @@ -57,37 +59,44 @@ spawnFuncTest() { // create a receivePort and send it's sendPort back and then it will just // sit there listening for a message from the second isolate spawned // using spawnFunction. - Isolate.spawn(func1Child, [receive1.sendPort]).then( + asyncStart(); + return Isolate.spawn(func1Child, [receive1.sendPort]).then( (isolate) { receive1.listen( (msg) { - Expect.isTrue(msg is SendPort); - spawnFunctionIsolate1SendPort = msg; - receive1.close(); + if (msg is SendPort) { + spawnFunctionIsolate1SendPort = msg; - // Now spawn the second isolate using spawnFunction, this isolate - // will create a receivePort and send it's sendPort back and then - // wait for the third isolate spawned using spawnUri to send it - // a sendPort to which it will try and send a non "literal-like" - // object. - Isolate.spawn(func2Child, [receive2.sendPort]).then( - (isolate) { - receive2.listen( - (msg) { - spawnFunctionIsolate2SendPort = msg; - receive2.close(); + // Now spawn the second isolate using spawnFunction, this isolate + // will create a receivePort and send it's sendPort back and then + // wait for the third isolate spawned using spawnUri to send it + // a sendPort to which it will try and send a non "literal-like" + // object. + Isolate.spawn(func2Child, [receive2.sendPort]).then( + (isolate) { + receive2.listen( + (msg) { + spawnFunctionIsolate2SendPort = msg; + receive2.close(); - // Now spawn an isolate using spawnUri and send these send - // ports over to it. This isolate will send one of the - // sendports over to the other. - Isolate.spawnUri(Uri.parse('issue_21398_child_isolate1.dart'), - [spawnFunctionIsolate1SendPort, - spawnFunctionIsolate2SendPort], "no-msg"); - }, - onError: (e) => print('$e') - ); - } - ); + // Now spawn an isolate using spawnUri and send these send + // ports over to it. This isolate will send one of the + // sendports over to the other. + Isolate + .spawnUri(Uri.parse('issue_21398_child_isolate1.dart'), + [spawnFunctionIsolate1SendPort, + spawnFunctionIsolate2SendPort], "no-msg"); + }, + onError: (e) => print('$e') + ); + } + ); + } else if (msg == "done") { + receive1.close(); + asyncEnd(); + } else { + Expect.fail("Invalid message received: $msg"); + } }, onError: (e) => print('$e') ); @@ -105,6 +114,7 @@ uriChild(args) { Expect.isTrue(msg is String); Expect.equals("Invalid Argument(s).", msg); receivePort.close(); + sendPort.send("done"); }, onError: (e) => print('$e') ); @@ -122,13 +132,13 @@ spawnUriTest() { // create a receivePort and send it's sendPort back and then it will just // sit there listening for a message from the second isolate spawned // using spawnFunction. + asyncStart(); Isolate.spawn(uriChild, [receive1.sendPort]).then( (isolate) { receive1.listen( (msg) { - Expect.isTrue(msg is SendPort); - spawnFunctionIsolateSendPort = msg; - receive1.close(); + if (msg is SendPort) { + spawnFunctionIsolateSendPort = msg; // Now spawn the second isolate using spawnUri, this isolate // will create a receivePort and send it's sendPort back and then @@ -149,12 +159,18 @@ spawnUriTest() { // sendports over to the other. Isolate.spawnUri(Uri.parse('issue_21398_child_isolate1.dart'), [spawnFunctionIsolateSendPort, - spawnUriIsolateSendPort], "no-msg"); + spawnUriIsolateSendPort], "no-msg"); }, onError: (e) => print('$e') ); } ); + } else if (msg == "done") { + receive1.close(); + asyncEnd(); + } else { + Expect.fail("Invalid message received: $msg"); + } }, onError: (e) => print('$e') ); diff --git a/tests/isolate/issue_21398_parent_isolate2_test.dart b/tests/isolate/issue_21398_parent_isolate2_test.dart index 92754fd9058..da94b56c17c 100644 --- a/tests/isolate/issue_21398_parent_isolate2_test.dart +++ b/tests/isolate/issue_21398_parent_isolate2_test.dart @@ -9,6 +9,7 @@ import 'dart:isolate'; import 'dart:async'; import "package:expect/expect.dart"; +import 'package:async_helper/async_helper.dart'; import "deferred_loaded_lib.dart" deferred as lib; @@ -27,6 +28,7 @@ funcChild(args) { void helperFunction() { var receivePort = new ReceivePort(); + asyncStart(); // Spawn an isolate using spawnFunction. Isolate.spawn(funcChild, [receivePort.sendPort]).then( @@ -36,12 +38,14 @@ void helperFunction() { // We don't expect to receive any valid messages. Expect.fail("We don't expect to receive any valid messages"); receivePort.close(); + asyncEnd(); }, onError: (e) { // We don't expect to receive any error messages, per spec listen // does not receive an error object. Expect.fail("We don't expect to receive any error messages"); receivePort.close(); + asyncEnd(); } ); } diff --git a/tests/isolate/issue_21398_parent_isolate_test.dart b/tests/isolate/issue_21398_parent_isolate_test.dart index fb4b0fb6fd0..76e7e0d4436 100644 --- a/tests/isolate/issue_21398_parent_isolate_test.dart +++ b/tests/isolate/issue_21398_parent_isolate_test.dart @@ -9,6 +9,7 @@ import 'dart:isolate'; import 'dart:async'; import "package:expect/expect.dart"; +import 'package:async_helper/async_helper.dart'; class FromMainIsolate { String toString() => 'from main isolate'; @@ -29,13 +30,16 @@ main() { // First spawn an isolate using spawnURI and have it // send back a "non-literal" like object. + asyncStart(); Isolate.spawnUri(Uri.parse('issue_21398_child_isolate.dart'), [], [new FromMainIsolate(), receive1.sendPort]).catchError( (error) { Expect.isTrue(error is ArgumentError); + asyncEnd(); } ); + asyncStart(); Isolate.spawnUri(Uri.parse('issue_21398_child_isolate.dart'), [], receive1.sendPort).then( @@ -44,6 +48,7 @@ main() { (msg) { Expect.stringEquals(msg, "Invalid Argument(s)."); receive1.close(); + asyncEnd(); }, onError: (e) => print('$e') ); @@ -53,7 +58,8 @@ main() { // Now spawn an isolate using spawnFunction and send it a "non-literal" // like object and also have the child isolate send back a "non-literal" // like object. - Isolate.spawn(funcChild, + asyncStart(); + Isolate.spawn(funcChild, [new FromMainIsolate(), receive2.sendPort]).then( (isolate) { receive2.listen( @@ -61,6 +67,7 @@ main() { Expect.isTrue(msg is FromMainIsolate); Expect.equals(10, msg.fld); receive2.close(); + asyncEnd(); }, onError: (e) => print('$e') ); diff --git a/tests/isolate/message_enum_test.dart b/tests/isolate/message_enum_test.dart index 7dbaec3bb99..b06dfc34259 100644 --- a/tests/isolate/message_enum_test.dart +++ b/tests/isolate/message_enum_test.dart @@ -5,6 +5,7 @@ // SharedOptions=--enable-enum import 'package:expect/expect.dart'; +import 'package:async_helper/async_helper.dart'; import "dart:isolate"; enum Foo { BAR, BAZ } @@ -18,7 +19,8 @@ main() { Expect.equals(42, map[key]); p.close(); }); - Isolate.spawn(sendIt, p.sendPort); + asyncStart(); + Isolate.spawn(sendIt, p.sendPort).whenComplete(asyncEnd); } void sendIt(port) { diff --git a/tests/language/issue23244_test.dart b/tests/language/issue23244_test.dart index b15576995c1..f8a3f325961 100644 --- a/tests/language/issue23244_test.dart +++ b/tests/language/issue23244_test.dart @@ -5,6 +5,7 @@ // Regression test case for http://dartbug.com/23244 import 'dart:async'; import 'dart:isolate'; +import 'package:async_helper/async_helper.dart'; enum Fisk { torsk, @@ -27,6 +28,7 @@ isolate3(SendPort port) { main() async { var port = new ReceivePort(); + asyncStart(); await Isolate.spawn(isolate1, port.sendPort); Completer completer1 = new Completer(); port.listen((message) { @@ -53,6 +55,7 @@ main() async { port.close(); expectTorsk(message[0]); expectTorsk(message[1]); + asyncEnd(); }); } @@ -61,4 +64,3 @@ expectTorsk(Fisk fisk) { throw "$fisk isn't a ${Fisk.torsk}"; } } - diff --git a/tests/standalone/typed_array_int64_uint64_test.dart b/tests/standalone/typed_array_int64_uint64_test.dart index 3decb92749d..f62ab53bc7c 100644 --- a/tests/standalone/typed_array_int64_uint64_test.dart +++ b/tests/standalone/typed_array_int64_uint64_test.dart @@ -7,12 +7,19 @@ // Library tag to be able to run in html test framework. library TypedArray; import "package:expect/expect.dart"; +import 'package:async_helper/async_helper.dart'; +import 'dart:async'; import 'dart:isolate'; import 'dart:typed_data'; -void main() { - int64_receiver(); - uint64_receiver(); +main() { + test(int64_receiver); + test(uint64_receiver); +} + +test(f) { + asyncStart(); + return f().whenComplete(asyncEnd); } // Int64 array. @@ -24,15 +31,17 @@ Int64List initInt64() { } Int64List int64 = initInt64(); -void int64_receiver() { +int64_receiver() { var response = new ReceivePort(); var remote = Isolate.spawn(int64_sender, [int64.length, response.sendPort]); - response.first.then((a) { + asyncStart(); + return response.first.then((a) { Expect.equals(int64.length, a.length); for (int i = 0; i < a.length; i++) { Expect.equals(int64[i], a[i]); } print("int64_receiver"); + asyncEnd(); }); } @@ -57,15 +66,17 @@ Uint64List initUint64() { } Uint64List uint64 = initUint64(); -void uint64_receiver() { +uint64_receiver() { var response = new ReceivePort(); var remote = Isolate.spawn(uint64_sender, [uint64.length, response.sendPort]); - response.first.then((a) { + asyncStart(); + return response.first.then((a) { Expect.equals(uint64.length, a.length); for (int i = 0; i < a.length; i++) { Expect.equals(uint64[i], a[i]); } print("uint64_receiver"); + asyncEnd(); }); } diff --git a/tests/standalone/typed_array_test.dart b/tests/standalone/typed_array_test.dart index 9643e13e35a..0c4c2b1346f 100644 --- a/tests/standalone/typed_array_test.dart +++ b/tests/standalone/typed_array_test.dart @@ -8,19 +8,25 @@ // Library tag to be able to run in html test framework. library TypedArray; import "package:expect/expect.dart"; +import 'package:async_helper/async_helper.dart'; import 'dart:isolate'; import 'dart:typed_data'; void main() { - int8_receiver(); - uint8_receiver(); - int16_receiver(); - uint16_receiver(); - int32_receiver(); - uint32_receiver(); + test(int8_receiver); + test(uint8_receiver); + test(int16_receiver); + test(uint16_receiver); + test(int32_receiver); + test(uint32_receiver); // int64 and uint64 in separate test. - float32_receiver(); - float64_receiver(); + test(float32_receiver); + test(float64_receiver); +} + +test(f) { + asyncStart(); + return f().whenComplete(asyncEnd); } // Int8 array. @@ -32,15 +38,17 @@ Int8List initInt8() { } Int8List int8 = initInt8(); -void int8_receiver() { +int8_receiver() { var response = new ReceivePort(); var remote = Isolate.spawn(int8_sender, [int8.length, response.sendPort]); - response.first.then((a) { + asyncStart(); + return response.first.then((a) { Expect.equals(int8.length, a.length); for (int i = 0; i < a.length; i++) { Expect.equals(int8[i], a[i]); } print("int8_receiver"); + asyncEnd(); }); } @@ -65,15 +73,17 @@ Uint8List initUint8() { } Uint8List uint8 = initUint8(); -void uint8_receiver() { +uint8_receiver() { var response = new ReceivePort(); var remote = Isolate.spawn(uint8_sender, [uint8.length, response.sendPort]); - response.first.then((a) { + asyncStart(); + return response.first.then((a) { Expect.equals(uint8.length, a.length); for (int i = 0; i < a.length; i++) { Expect.equals(uint8[i], a[i]); } print("uint8_receiver"); + asyncEnd(); }); } @@ -98,15 +108,17 @@ Int16List initInt16() { } Int16List int16 = initInt16(); -void int16_receiver() { +int16_receiver() { var response = new ReceivePort(); var remote = Isolate.spawn(int16_sender, [int16.length, response.sendPort]); - response.first.then((a) { + asyncStart(); + return response.first.then((a) { Expect.equals(int16.length, a.length); for (int i = 0; i < a.length; i++) { Expect.equals(int16[i], a[i]); } print("int16_receiver"); + asyncEnd(); }); } @@ -131,15 +143,17 @@ Uint16List initUint16() { } Uint16List uint16 = initUint16(); -void uint16_receiver() { +uint16_receiver() { var response = new ReceivePort(); var remote = Isolate.spawn(uint16_sender, [uint16.length, response.sendPort]); - response.first.then((a) { + asyncStart(); + return response.first.then((a) { Expect.equals(uint16.length, a.length); for (int i = 0; i < a.length; i++) { Expect.equals(uint16[i], a[i]); } print("uint16_receiver"); + asyncEnd(); }); } @@ -164,15 +178,17 @@ Int32List initInt32() { } Int32List int32 = initInt32(); -void int32_receiver() { +int32_receiver() { var response = new ReceivePort(); var remote = Isolate.spawn(int32_sender, [int32.length, response.sendPort]); - response.first.then((a) { + asyncStart(); + return response.first.then((a) { Expect.equals(int32.length, a.length); for (int i = 0; i < a.length; i++) { Expect.equals(int32[i], a[i]); } print("int32_receiver"); + asyncEnd(); }); } @@ -197,15 +213,17 @@ Uint32List initUint32() { } Uint32List uint32 = initUint32(); -void uint32_receiver() { +uint32_receiver() { var response = new ReceivePort(); var remote = Isolate.spawn(uint32_sender, [uint32.length, response.sendPort]); - response.first.then((a) { + asyncStart(); + return response.first.then((a) { Expect.equals(uint32.length, a.length); for (int i = 0; i < a.length; i++) { Expect.equals(uint32[i], a[i]); } print("uint32_receiver"); + asyncEnd(); }); } @@ -230,16 +248,18 @@ Float32List initFloat32() { } Float32List float32 = initFloat32(); -void float32_receiver() { +float32_receiver() { var response = new ReceivePort(); var remote = Isolate.spawn(float32_sender, [float32.length, response.sendPort]); - response.first.then((a) { + asyncStart(); + return response.first.then((a) { Expect.equals(float32.length, a.length); for (int i = 0; i < a.length; i++) { Expect.equals(float32[i], a[i]); } print("float32_receiver"); + asyncEnd(); }); } @@ -264,16 +284,18 @@ Float64List initFloat64() { } Float64List float64 = initFloat64(); -void float64_receiver() { +float64_receiver() { var response = new ReceivePort(); var remote = Isolate.spawn(float64_sender, [float64.length, response.sendPort]); - response.first.then((a) { + asyncStart(); + return response.first.then((a) { Expect.equals(float64.length, a.length); for (int i = 0; i < a.length; i++) { Expect.equals(float64[i], a[i]); } print("float64_receiver"); + asyncEnd(); }); }