Skip to content

Commit

Permalink
[vm/cocurrency] Add simple spawn function test and test with/without …
Browse files Browse the repository at this point in the history
…isolate groups

This fixes also an issue when running without isolate groups.

Issue #36097

Change-Id: I0fb64b3f2b755ccab4c36c6a0fafee7edff239cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114204
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
  • Loading branch information
mkustermann authored and commit-bot@chromium.org committed Aug 23, 2019
1 parent 3c54aea commit 68e805f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
8 changes: 4 additions & 4 deletions runtime/bin/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,11 @@ static Dart_Isolate CreateIsolateGroupAndSetupHelper(
}

if (flags->copy_parent_code && callback_data) {
IsolateGroupData* parent_isolate_data =
reinterpret_cast<IsolateGroupData*>(callback_data);
parent_kernel_buffer = parent_isolate_data->kernel_buffer();
auto parent_isolate_group_data =
reinterpret_cast<IsolateData*>(callback_data)->isolate_group_data();
parent_kernel_buffer = parent_isolate_group_data->kernel_buffer();
kernel_buffer = parent_kernel_buffer.get();
kernel_buffer_size = parent_isolate_data->kernel_buffer_size();
kernel_buffer_size = parent_isolate_group_data->kernel_buffer_size();
}

if (kernel_buffer == NULL && !isolate_run_app_snapshot) {
Expand Down
32 changes: 32 additions & 0 deletions runtime/tests/vm/dart/isolates/spawn_function_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2019, 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:isolate';
import 'dart:async';

import 'package:expect/expect.dart';

void isolateEntry(args) {
final SendPort sendPort = args;
sendPort.send('hello world');
}

main() async {
final port = ReceivePort();
final exitPort = ReceivePort();

await Isolate.spawn(isolateEntry, port.sendPort, onExit: exitPort.sendPort);

final messages = StreamIterator(port);
Expect.isTrue(await messages.moveNext());
Expect.equals('hello world', messages.current);
await messages.cancel();

final exit = StreamIterator(exitPort);
Expect.isTrue(await exit.moveNext());
await exit.cancel();
}

0 comments on commit 68e805f

Please sign in to comment.