Version 2.12.0-105.0.dev
Merge commit '4084271488753a828ec373258cf44a4301296dcd' into 'dev'
diff --git a/tests/standalone/io/shared_socket_test.dart b/tests/standalone/io/shared_socket_test.dart
index 7f70a14..2fb755f 100644
--- a/tests/standalone/io/shared_socket_test.dart
+++ b/tests/standalone/io/shared_socket_test.dart
@@ -12,11 +12,18 @@
import 'package:http/http.dart' as http;
void main() async {
- final workers = List<ServerWorker>.generate(4, (i) => ServerWorker(i));
- workers.forEach((w) => w.start());
+ // Start a server to obtain a randomly assigned, free port.
+ final mainServer = await HttpServer.bind('::1', 0, shared: true);
+ final sharedPort = mainServer.port;
+
+ final workers =
+ List<ServerWorker>.generate(4, (i) => ServerWorker(i, sharedPort));
+ await Future.wait(workers.map((w) => w.start()));
+ mainServer.close();
+
await Future.delayed(Duration(seconds: 1));
// spawn client isolate
- final clientisolate = await Isolate.spawn(client, 0);
+ final clientisolate = await Isolate.spawn(client, sharedPort);
// Wait for 20 secs. It used to crash within 10 seconds.
await Future.delayed(Duration(seconds: 20));
@@ -30,10 +37,11 @@
class ServerWorker {
final int workerid;
+ final int port;
Isolate? _isolate;
bool respawn = true;
- ServerWorker(this.workerid);
+ ServerWorker(this.workerid, this.port);
Future<void> start() async {
final onExit = ReceivePort();
@@ -42,8 +50,10 @@
// Respawn another isolate
if (respawn) start();
});
- _isolate = await Isolate.spawn(_main, workerid,
+ final ready = ReceivePort();
+ _isolate = await Isolate.spawn(_main, [workerid, port, ready.sendPort],
errorsAreFatal: true, onExit: onExit.sendPort);
+ await ready.first;
if (workerid == 0) terminate();
}
@@ -55,9 +65,13 @@
});
}
- static _main(int workerid) async {
- bool shared = true;
- final server = await HttpServer.bind('::1', 1234, shared: shared);
+ static _main(List args) async {
+ final workerid = args[0] as int;
+ final port = args[1] as int;
+ final readyPort = args[2] as SendPort;
+
+ final server = await HttpServer.bind('::1', port, shared: true);
+ readyPort.send(null);
server.listen((HttpRequest request) {
print('from worker ${workerid}');
final response = request.response;
@@ -77,12 +91,12 @@
}
}
-void client(int i) async {
+void client(int port) async {
while (true) {
final futures = <Future>[];
final numAtOnce = 16; // enough to keep the server busy
for (int i = 0; i < numAtOnce; ++i) {
- futures.add(get('http://localhost:1234').then((_) {}));
+ futures.add(get('http://localhost:$port').then((_) {}));
}
await Future.wait(futures);
}
diff --git a/tests/standalone_2/io/shared_socket_test.dart b/tests/standalone_2/io/shared_socket_test.dart
index 5f933bb..bd1a041 100644
--- a/tests/standalone_2/io/shared_socket_test.dart
+++ b/tests/standalone_2/io/shared_socket_test.dart
@@ -12,11 +12,18 @@
import 'package:http/http.dart' as http;
void main() async {
- final workers = List<ServerWorker>.generate(4, (i) => ServerWorker(i));
- workers.forEach((w) => w.start());
+ // Start a server to obtain a randomly assigned, free port.
+ final mainServer = await HttpServer.bind('::1', 0, shared: true);
+ final sharedPort = mainServer.port;
+
+ final workers =
+ List<ServerWorker>.generate(4, (i) => ServerWorker(i, sharedPort));
+ await Future.wait(workers.map((w) => w.start()));
+ mainServer.close();
+
await Future.delayed(Duration(seconds: 1));
// spawn client isolate
- final clientisolate = await Isolate.spawn(client, 0);
+ final clientisolate = await Isolate.spawn(client, sharedPort);
// Wait for 20 secs. It used to crash within 10 seconds.
await Future.delayed(Duration(seconds: 20));
@@ -30,10 +37,11 @@
class ServerWorker {
final int workerid;
+ final int port;
Isolate _isolate;
bool respawn = true;
- ServerWorker(this.workerid);
+ ServerWorker(this.workerid, this.port);
Future<void> start() async {
final onExit = ReceivePort();
@@ -42,8 +50,10 @@
// Respawn another isolate
if (respawn) start();
});
- _isolate = await Isolate.spawn(_main, workerid,
+ final ready = ReceivePort();
+ _isolate = await Isolate.spawn(_main, [workerid, port, ready.sendPort],
errorsAreFatal: true, onExit: onExit.sendPort);
+ await ready.first;
if (workerid == 0) terminate();
}
@@ -57,9 +67,13 @@
});
}
- static _main(int workerid) async {
- bool shared = true;
- final server = await HttpServer.bind('::1', 1234, shared: shared);
+ static _main(List args) async {
+ final workerid = args[0] as int;
+ final port = args[1] as int;
+ final readyPort = args[2] as SendPort;
+
+ final server = await HttpServer.bind('::1', port, shared: true);
+ readyPort.send(null);
server.listen((HttpRequest request) {
print('from worker ${workerid}');
final response = request.response;
@@ -79,12 +93,12 @@
}
}
-void client(int i) async {
+void client(int port) async {
while (true) {
final futures = <Future>[];
final numAtOnce = 16; // enough to keep the server busy
for (int i = 0; i < numAtOnce; ++i) {
- futures.add(get('http://localhost:1234').then((_) {}));
+ futures.add(get('http://localhost:$port').then((_) {}));
}
await Future.wait(futures);
}
diff --git a/tools/VERSION b/tools/VERSION
index ff6e07f..51f1ac0 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 12
PATCH 0
-PRERELEASE 104
+PRERELEASE 105
PRERELEASE_PATCH 0
\ No newline at end of file