Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flaky LibTest/isolate/Isolate/ping_A03_t02.dart test. #1095

Closed
mkustermann opened this issue Jun 4, 2021 · 2 comments
Closed

Flaky LibTest/isolate/Isolate/ping_A03_t02.dart test. #1095

mkustermann opened this issue Jun 4, 2021 · 2 comments
Assignees

Comments

@mkustermann
Copy link
Member

This test looks as follows:

entryPoint(message) {
  Random random = new Random();
  int s = 0;
  while (true) {
    s = -s + random.nextInt(100);
  }
}

Future test(List<Object?> values) async {
  ReceivePort onExit = new ReceivePort();
  Isolate isolate = await Isolate.spawn(entryPoint, null, // message
      onExit: onExit.sendPort,
      errorsAreFatal: true);
  // check
  List<Future> pingResponses = [];
  for (Object? value in values) {
    ReceivePort pingPort = new ReceivePort();
    isolate.ping(pingPort.sendPort,
        response: value, priority: Isolate.beforeNextEvent);
    Future pingResponse =
        pingPort.first.timeout(TWO_SECONDS, onTimeout: () {
      pingPort.close();
      return "timeout";
    });
    pingResponses.add(pingResponse);
  }
  for (var response in await Future.wait(pingResponses)) {
    Expect.equals("timeout", response);
  }
  // clean up
  isolate.kill(priority: Isolate.immediate);
  await onExit.first;
  asyncEnd();
}

Sometimes one of the pings doesn't result in a timeout, the reason for that is that this test is racy: await Isolate.spawn() returns when the isolate was created, not when the isolate's entrypoint function has been invoked. Therefore there is a small time window when the isolate is created, receives a ping, responds to the ping and then invokes the entrypoint, which can make this test fail.

A more robust test would make the entrypoint send a message inside it's main function that it's ready to do the synchronous loop, then the main isolate can expect pings to timeout. Since the isolate is in an infinite synchronous loop.

@aam
Copy link
Contributor

aam commented Jun 5, 2021

see dart-lang/sdk#45111.
I raised it with assumption that vm isolate message processing is racy, not that there is anything wrong the test.

@aam
Copy link
Contributor

aam commented Jun 27, 2023

Please fix corresponding co19_2 tests as they continue to be flaky.

@aam aam reopened this Jun 27, 2023
sgrekhov added a commit to sgrekhov/co19 that referenced this issue Jun 28, 2023
copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Jul 6, 2023
2023-06-28 sgrekhov22@gmail.com Fixes dart-lang/co19#1095. Wait for entryPoint is invoked before doing the test (dart-lang/co19#2102)

Change-Id: I91e3fd3a76c09ecf17dc39930fd03a380de91fda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312260
Reviewed-by: William Hesse <whesse@google.com>
Commit-Queue: William Hesse <whesse@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants