mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 10:33:03 +00:00
[Tests] : port remaining isolate tests for null safety.
- Some of the package config tests for isolates were not ported in the initial round, this CL ports these tests. - lib_2/isolate/isolate_stress_test.dart is not ported as it is currently skipped for the VM and was probably intended to be a dart2js test. Change-Id: I53c3641d2a83f2661ecdb8cd57a8c381234b06d3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152940 Reviewed-by: Alexander Aprelev <aam@google.com> Commit-Queue: Siva Annamalai <asiva@google.com>
This commit is contained in:
parent
22da8934ac
commit
b8adfa4ffc
|
@ -0,0 +1,51 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
final PACKAGE_URI = "package:foo/bar.dart";
|
||||
|
||||
main([args, port]) async {
|
||||
if (port != null) {
|
||||
testPackageResolution(port);
|
||||
return;
|
||||
}
|
||||
var p = new RawReceivePort();
|
||||
Isolate.spawnUri(Platform.script, [], p.sendPort,
|
||||
automaticPackageResolution: true);
|
||||
p.handler = (msg) {
|
||||
p.close();
|
||||
if (msg is! List) {
|
||||
print(msg.runtimeType);
|
||||
throw "Failure return from spawned isolate:\n\n$msg";
|
||||
}
|
||||
if (msg[0] != null) {
|
||||
throw "Bad package root in child isolate: ${msg[0]}.\n"
|
||||
"Expected: null";
|
||||
}
|
||||
if (msg[1] != null) {
|
||||
throw "Package path not matching: ${msg[1]}\n"
|
||||
"Expected: null";
|
||||
}
|
||||
print("SUCCESS");
|
||||
};
|
||||
print("Spawning isolate's package root: ${await Isolate.packageRoot}");
|
||||
}
|
||||
|
||||
testPackageResolution(port) async {
|
||||
try {
|
||||
var packageRootStr = Platform.packageRoot;
|
||||
var packageConfigStr = Platform.packageConfig;
|
||||
var packageRoot = await Isolate.packageRoot;
|
||||
var resolvedPkg = await Isolate.resolvePackageUri(Uri.parse(PACKAGE_URI));
|
||||
print("Spawned isolate's package root flag: $packageRootStr");
|
||||
print("Spawned isolate's package config flag: $packageConfigStr");
|
||||
print("Spawned isolate's loaded package root: $packageRoot");
|
||||
print("Spawned isolate's resolved package path: $resolvedPkg");
|
||||
port.send([packageRoot?.toString(), resolvedPkg?.toString()]);
|
||||
} catch (e, s) {
|
||||
port.send("$e\n$s\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
foo:file:///no/such/directory/
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
final PACKAGE_URI = "package:foo/bar.dart";
|
||||
final PACKAGE_PATH = "file:///no/such/directory/bar.dart";
|
||||
|
||||
main([args, port]) async {
|
||||
if (port != null) {
|
||||
testPackageResolution(port);
|
||||
return;
|
||||
}
|
||||
var p = new RawReceivePort();
|
||||
Isolate.spawnUri(Platform.script, [], p.sendPort,
|
||||
automaticPackageResolution: true);
|
||||
p.handler = (msg) {
|
||||
p.close();
|
||||
if (msg is! List) {
|
||||
print(msg.runtimeType);
|
||||
throw "Failure return from spawned isolate:\n\n$msg";
|
||||
}
|
||||
var child_pkg_config = Platform.script.resolve(".packages");
|
||||
if (msg[0] != child_pkg_config.toString()) {
|
||||
throw "Bad package config in child isolate: ${msg[0]}\n"
|
||||
"Expected: $child_pkg_config";
|
||||
}
|
||||
if (msg[1] != PACKAGE_PATH) {
|
||||
throw "Package path not matching: ${msg[1]}";
|
||||
}
|
||||
print("SUCCESS");
|
||||
};
|
||||
print("Spawning isolate's package root: ${await Isolate.packageRoot}");
|
||||
}
|
||||
|
||||
testPackageResolution(port) async {
|
||||
try {
|
||||
var packageRootStr = Platform.packageRoot;
|
||||
var packageConfigStr = Platform.packageConfig;
|
||||
var packageConfig = await Isolate.packageConfig;
|
||||
var resolvedPkg = await Isolate.resolvePackageUri(Uri.parse(PACKAGE_URI));
|
||||
print("Spawned isolate's package root flag: $packageRootStr");
|
||||
print("Spawned isolate's package config flag: $packageConfigStr");
|
||||
print("Spawned isolate's loaded package config: $packageConfig");
|
||||
print("Spawned isolate's resolved package path: $resolvedPkg");
|
||||
port.send([packageConfig?.toString(), resolvedPkg?.toString()]);
|
||||
} catch (e, s) {
|
||||
port.send("$e\n$s\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Packages=none
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
main([args, port]) async {
|
||||
if (port != null) {
|
||||
testBadResolvePackage(port);
|
||||
return;
|
||||
}
|
||||
var p = new RawReceivePort();
|
||||
Isolate.spawnUri(Platform.script, [], p.sendPort);
|
||||
p.handler = (msg) {
|
||||
p.close();
|
||||
if (msg is! List) {
|
||||
print(msg.runtimeType);
|
||||
throw "Failure return from spawned isolate:\n\n$msg";
|
||||
}
|
||||
// Expecting a null resolution for inexistent package mapping.
|
||||
if (msg[0] != null) {
|
||||
throw "Bad package config in child isolate: ${msg[0]}\n"
|
||||
"Expected: 'Foo'";
|
||||
}
|
||||
print("SUCCESS");
|
||||
};
|
||||
}
|
||||
|
||||
testBadResolvePackage(port) async {
|
||||
try {
|
||||
var packageRootStr = Platform.packageRoot;
|
||||
var packageConfigStr = Platform.packageConfig;
|
||||
var packageConfig = await Isolate.packageConfig;
|
||||
var badPackageUri = Uri.parse("package:asdf/qwerty.dart");
|
||||
var resolvedPkg = await Isolate.resolvePackageUri(badPackageUri);
|
||||
print("Spawned isolate's package root flag: $packageRootStr");
|
||||
print("Spawned isolate's package config flag: $packageConfigStr");
|
||||
print("Spawned isolate's loaded package config: $packageConfig");
|
||||
print("Spawned isolate's resolved package path: $resolvedPkg");
|
||||
port.send([resolvedPkg]);
|
||||
} catch (e, s) {
|
||||
port.send("$e\n$s\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// VMOptions=--enable-isolate-groups
|
||||
// VMOptions=--no-enable-isolate-groups
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
final packageUriToResolve = "package:foo/bar.dart";
|
||||
final packageResolvedUri = "file:///no/such/directory/lib/bar.dart";
|
||||
|
||||
final dotPackages = """
|
||||
# This is the content of a .packages file.
|
||||
foo:file:///no/such/directory/lib/
|
||||
""";
|
||||
|
||||
final packageConfigJson = """
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "file:///no/such/directory",
|
||||
"packageUri": "lib/",
|
||||
"languageVersion": "2.7"
|
||||
}
|
||||
]
|
||||
}
|
||||
""";
|
||||
|
||||
main([args, port]) async {
|
||||
if (port != null) {
|
||||
testPackageResolution(port);
|
||||
return;
|
||||
}
|
||||
await runTest(dotPackages);
|
||||
await runTest(packageConfigJson);
|
||||
}
|
||||
|
||||
Future runTest(String packageConfig) async {
|
||||
final data = Uri.dataFromString(packageConfig);
|
||||
final port = ReceivePort();
|
||||
await Isolate.spawnUri(Platform.script, [], port.sendPort,
|
||||
packageConfig: data);
|
||||
final msg = await port.first;
|
||||
if (msg is! List) {
|
||||
print(msg.runtimeType);
|
||||
throw "Failure return from spawned isolate:\n\n$msg";
|
||||
}
|
||||
if (msg[0] != data.toString()) {
|
||||
throw "Bad package config in child isolate: ${msg[0]}\n"
|
||||
"Expected: $data";
|
||||
}
|
||||
if (msg[1] != packageResolvedUri) {
|
||||
throw "Package path not matching: ${msg[1]}";
|
||||
}
|
||||
print("SUCCESS");
|
||||
}
|
||||
|
||||
testPackageResolution(port) async {
|
||||
try {
|
||||
var packageConfigStr = Platform.packageConfig;
|
||||
var packageConfig = await Isolate.packageConfig;
|
||||
var resolvedPkg =
|
||||
await Isolate.resolvePackageUri(Uri.parse(packageUriToResolve));
|
||||
print("Spawned isolate's package config flag: $packageConfigStr");
|
||||
print("Spawned isolate's loaded package config: $packageConfig");
|
||||
print("Spawned isolate's resolved package path: $resolvedPkg");
|
||||
port.send([packageConfig?.toString(), resolvedPkg?.toString()]);
|
||||
} catch (e, s) {
|
||||
port.send("$e\n$s\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../packages/foo",
|
||||
"languageVersion": "2.9"
|
||||
},
|
||||
{
|
||||
"name": "bar",
|
||||
"rootUri": "../packages/bar",
|
||||
"languageVersion": "2.9"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Packages=none
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import "package:foo/foo.dart";
|
||||
import "package:bar/bar.dart";
|
||||
|
||||
var CONFIG_URI = "package:bar/spawned_packages/";
|
||||
|
||||
main([args, port]) async {
|
||||
if (port != null) {
|
||||
testCorrectBarPackage(port);
|
||||
return;
|
||||
}
|
||||
var p = new RawReceivePort();
|
||||
Isolate.spawnUri(Platform.script, [], p.sendPort,
|
||||
packageRoot: Uri.parse(CONFIG_URI));
|
||||
p.handler = (msg) {
|
||||
p.close();
|
||||
if (msg is! List) {
|
||||
print(msg.runtimeType);
|
||||
throw "Failure return from spawned isolate:\n\n$msg";
|
||||
}
|
||||
if (msg[0] != "Foo") {
|
||||
throw "Bad package config in child isolate: ${msg[0]}\n"
|
||||
"Expected: 'Foo'";
|
||||
}
|
||||
if (msg[1] != "Bar1") {
|
||||
throw "Package path not matching: ${msg[1]}\n"
|
||||
"Expected: 'Bar1'";
|
||||
}
|
||||
print("SUCCESS");
|
||||
};
|
||||
if (Bar.value != "Bar1") {
|
||||
throw "Spawning isolate package:bar invalid.";
|
||||
}
|
||||
print("Spawned isolate resolved $CONFIG_URI to: "
|
||||
"${await Isolate.resolvePackageUri(Uri.parse(CONFIG_URI))}");
|
||||
}
|
||||
|
||||
testCorrectBarPackage(port) async {
|
||||
try {
|
||||
var packageRootStr = Platform.packageRoot;
|
||||
var packageConfigStr = Platform.packageConfig;
|
||||
var packageConfig = await Isolate.packageConfig;
|
||||
var resolvedPkg = await Isolate.resolvePackageUri(Uri.parse(CONFIG_URI));
|
||||
print("Spawned isolate's package root flag: $packageRootStr");
|
||||
print("Spawned isolate's package config flag: $packageConfigStr");
|
||||
print("Spawned isolate's loaded package config: $packageConfig");
|
||||
print("Spawned isolate's resolved package path: $resolvedPkg");
|
||||
port.send([Foo.value, Bar.value]);
|
||||
} catch (e, s) {
|
||||
port.send("$e\n$s\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Bar {
|
||||
static var value = "Bar1";
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Bar {
|
||||
static var value = "Bar2";
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Foo {
|
||||
static var value = "Foo";
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Foo {
|
||||
static var value = "Foo";
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../foo_package",
|
||||
"languageVersion": "2.9"
|
||||
},
|
||||
{
|
||||
"name": "bar",
|
||||
"rootUri": "../bar1_package",
|
||||
"languageVersion": "2.9"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Bar {
|
||||
static var value = "Bar1";
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../foo_package",
|
||||
"languageVersion": "2.9"
|
||||
},
|
||||
{
|
||||
"name": "bar",
|
||||
"rootUri": "../bar2_package",
|
||||
"languageVersion": "2.9"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Bar {
|
||||
static var value = "Bar2";
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Foo {
|
||||
static var value = "Foo";
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Packages=none
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import "package:foo/foo.dart";
|
||||
import "package:bar/bar.dart";
|
||||
|
||||
var CONFIG_URI = "package:bar/package.config";
|
||||
|
||||
main([args, port]) async {
|
||||
if (port != null) {
|
||||
testCorrectBarPackage(port);
|
||||
return;
|
||||
}
|
||||
var p = new RawReceivePort();
|
||||
Isolate.spawnUri(Platform.script, [], p.sendPort,
|
||||
packageConfig: Uri.parse(CONFIG_URI));
|
||||
p.handler = (msg) {
|
||||
p.close();
|
||||
if (msg is! List) {
|
||||
print(msg.runtimeType);
|
||||
throw "Failure return from spawned isolate:\n\n$msg";
|
||||
}
|
||||
if (msg[0] != "Foo") {
|
||||
throw "Bad package config in child isolate: ${msg[0]}\n"
|
||||
"Expected: 'Foo'";
|
||||
}
|
||||
if (msg[1] != "Bar2") {
|
||||
throw "Package path not matching: ${msg[1]}\n"
|
||||
"Expected: 'Bar2'";
|
||||
}
|
||||
print("SUCCESS");
|
||||
};
|
||||
if (Bar.value != "Bar1") {
|
||||
throw "Spawning isolate package:bar invalid.";
|
||||
}
|
||||
print("Spawned isolate resolved $CONFIG_URI to: "
|
||||
"${await Isolate.resolvePackageUri(Uri.parse(CONFIG_URI))}");
|
||||
}
|
||||
|
||||
testCorrectBarPackage(port) async {
|
||||
try {
|
||||
var packageRootStr = Platform.packageRoot;
|
||||
var packageConfigStr = Platform.packageConfig;
|
||||
var packageConfig = await Isolate.packageConfig;
|
||||
var resolvedPkg = await Isolate.resolvePackageUri(Uri.parse(CONFIG_URI));
|
||||
print("Spawned isolate's package root flag: $packageRootStr");
|
||||
print("Spawned isolate's package config flag: $packageConfigStr");
|
||||
print("Spawned isolate's loaded package config: $packageConfig");
|
||||
print("Spawned isolate's resolved package path: $resolvedPkg");
|
||||
port.send([Foo.value, Bar.value]);
|
||||
} catch (e, s) {
|
||||
port.send("$e\n$s\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "flu",
|
||||
"rootUri": "../flu_package",
|
||||
"languageVersion": "2.9"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Flu {
|
||||
static var value = "Flu";
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Bar
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Packages=none
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import "package:flu/flu.dart";
|
||||
|
||||
var PACKAGE_FLU = "package:flu";
|
||||
var FLU_TEXT = "flu.text";
|
||||
|
||||
testShortResolution(package_uri) async {
|
||||
var fluPackage = await Isolate.resolvePackageUri(Uri.parse(package_uri));
|
||||
print("Resolved $package_uri to $fluPackage");
|
||||
if (fluPackage == null) {
|
||||
throw "Package resolves to null for $package_uri.\n";
|
||||
}
|
||||
var fluText = fluPackage.resolve(FLU_TEXT);
|
||||
print("Resolved $FLU_TEXT from $package_uri to $fluText");
|
||||
var fluFile = new File.fromUri(fluText);
|
||||
var fluString = await fluFile.readAsString();
|
||||
if (fluString != "Bar") {
|
||||
throw "Contents of $FLU_TEXT not matching.\n"
|
||||
"Got: $fluString\n"
|
||||
"Expected: Bar";
|
||||
}
|
||||
}
|
||||
|
||||
main([args, port]) async {
|
||||
if (Flu.value != "Flu") {
|
||||
throw "Import of wrong Flu package.";
|
||||
}
|
||||
// await testShortResolution(PACKAGE_FLU);
|
||||
await testShortResolution(PACKAGE_FLU + "/");
|
||||
await testShortResolution(PACKAGE_FLU + "/abc.def");
|
||||
print("SUCCESS");
|
||||
}
|
Loading…
Reference in a new issue