dart-sdk/tests/standalone/regress_42092_test.dart
Ben Konyi c40ebbc65e [ DartDev ] Ignore SIGINT in DartDev process
If a user program installs custom signal handling for SIGINT,
the DartDev instance may exit before its child, potentially causing
confusing behavior and 'zombie' children. By ignoring these signals in
DartDev, the DartDev instance will only exit once its child process
exits.

Fixes https://github.com/dart-lang/sdk/issues/42092

Change-Id: I04bf6d1f375b8bb3a4f7022f2c79ddde3bd5f414
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149643
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Jaime Wren <jwren@google.com>
2020-07-06 03:02:00 +00:00

52 lines
1.3 KiB
Dart

// Copyright (c) 2020, 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:async';
import 'dart:convert';
import 'dart:io';
import 'package:expect/expect.dart';
late Process process;
bool lastKill = false;
Future<void> sigint(int iterations) async {
for (int i = 0; i < iterations; ++i) {
if (i + 1 == iterations) {
lastKill = true;
}
process.kill(ProcessSignal.sigint);
// Yield to the event loop to allow for the signal to be sent.
await Future.value(null);
}
}
Future<void> main() async {
process = await Process.start(
Platform.resolvedExecutable,
[
Platform.script.resolve('regress_42092_script.dart').toString(),
],
);
final startCompleter = Completer<void>();
late StreamSubscription sub;
sub = process.stdout.transform(Utf8Decoder()).listen((event) {
if (event.contains('Waiting...')) {
startCompleter.complete();
sub.cancel();
}
});
// Wait for target script to setup its signal handling.
await startCompleter.future;
final exitCompleter = Completer<void>();
process.exitCode.then((code) {
Expect.isTrue(lastKill);
exitCompleter.complete();
});
await sigint(3);
await exitCompleter.future;
}