Access to 'receive' and 'toSendPort()' needs to throw an exception when the used on a closed port #7548
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
closed-not-planned
Closed as we don't intend to take action on the reported issue
library-isolate
The following test does not result in any exceptions even though it
is accessing a closed port.
// Copyright (c) 2012, 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.
// PackageRoot=packages/
library package_isolate_test;
import 'package:shared.dart' as shared;
import 'dart:isolate';
import '../../../pkg/unittest/lib/unittest.dart';
expectResponse() {
port.receive(expectAsync2((msg, r) {
expect('isolate', msg);
expect('main', shared.output);
port.close();
print("In expectResponse reply $msg");
print("Value of port in reply = ${port.hashCode}");
}));
}
void main() {
test("package in spawnFunction()", () {
print("Set up expectResponse spawnFunction");
try {
print("Value of port1 = ${port.hashCode}");
expectResponse();
shared.output = 'main';
var sendPort = spawnFunction(isolate_main);
sendPort.send("sendPort", port.toSendPort());
} catch (e, trace) {
print(e);
print(trace);
}
});
test("package in spawnUri() of sibling file", () {
print("Set up expectResponse spawnUri1");
try {
print("Value of port1 = ${port.hashCode}");
expectResponse();
shared.output = 'main';
var sendPort = spawnUri('sibling_isolate.dart');
print("Value of port2 = ${port.hashCode}");
print("Value of send port = ${port.toSendPort()}");
sendPort.send('sendPort', port.toSendPort());
} catch (e, trace) {
print(e);
print(trace);
}
});
test("package in spawnUri() of file in folder", () {
print("Set up expectResponse spawnUri2");
try {
expectResponse();
shared.output = 'main';
var sendPort = spawnUri('test_folder/folder_isolate.dart');
sendPort.send('sendPort', port.toSendPort());
} catch (e, trace) {
print(e);
print(trace);
}
});
print("Done setting up xpectResponse");
}
void isolate_main() {
shared.output = 'isolate';
port.receive((msg, replyTo) {
replyTo.send(shared.output);
});
}
The text was updated successfully, but these errors were encountered: