Skip to content

Fix race in cli_test_driver #221

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

Merged
merged 2 commits into from
Feb 5, 2019
Merged

Conversation

DanTup
Copy link
Contributor

@DanTup DanTup commented Feb 5, 2019

On Travis Windows we were hitting this race in cli_test_driver. We start a Dart process with --observe=0 but we don't start it paused so the first print statements sometimes came before the Observatory banner and the coed always assumed the first line output was the banner.

Running C:\Users\travis\build\DanTup\devtools\dart-sdk\bin\dart.exe --observe=0 test/fixtures/logging_app.dart
PID = 5036
5036: Got line: starting logging app
5036: Got line: Observatory listening on http://127.0.0.1:49855/

The result is that when the first line came through, we crashed:

01:15 +3 -1: test\integration_tests\integration_test.dart: integration app can switch pages [E]
  FormatException: Invalid radix-10 number (at character 1)
  starting logging ap
  ^
  
  dart:core                                 int.parse
  test\support\cli_test_driver.dart 103:26  CliAppFixture.create
  ===== asynchronous gap ===========================
  dart:async                                _AsyncAwaitCompleter.completeError
  test\support\cli_test_driver.dart         CliAppFixture.create
  ===== asynchronous gap ===========================
  dart:async                                _asyncThenWrapperHelper
  test\support\cli_test_driver.dart         CliAppFixture.create
  test\integration_tests\app.dart 15:38     appTests.<fn>

We could've just waited for the one that looked like the banner, but it seems more sensible to connect and unpause so that if in future we need tests to be able to collect the first actual line, we can do it by giving a hook before the unpause.

@@ -103,6 +103,9 @@ class CliAppFixture extends AppFixture {

final VM vm = await serviceConnection.getVM();

await Future.wait(
Copy link
Member

@devoncarew devoncarew Feb 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might be hitting a race here:

01:19 +4 -1: test/integration_tests/integration_test.dart: integration logging displays log data [E]
  Isolate must be runnable (105) from resume():
  Isolate must be runnable before this request is made.
  dart:async                                           _Completer.completeError
  package:vm_service_lib/vm_service_lib.dart 861:17    VmService._processResponse
  package:vm_service_lib/vm_service_lib.dart 848:7     VmService._processMessageStr
  package:vm_service_lib/vm_service_lib.dart 800:7     VmService._processMessage

The isolate might exist, but not yet be runnable (it goes through a small life cycle at startup).

We could continue re-requesting isolates until we got one that was in the paused-at-start state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, how ironic :-) Neither the original race nor this occurred locally so I had to debug-via-Travis (which is somewhat tedious!).

Yeah, I'll put a little loop in for now. The nicer fix would probably be to subscribe to the event stream, then check, and if it's not already ready then wait for the event on the stream, but it's probably overly complex for this, so I'll just use waitFor or similar.

@DanTup DanTup force-pushed the fix-cli-driver-race branch from f00f5dd to d24b618 Compare February 5, 2019 15:19
@DanTup
Copy link
Contributor Author

DanTup commented Feb 5, 2019

@devoncarew Green now - though no matter how I wrote this function it didn't seem very readable, so if you have any suggestions I'm happy to tweak!

Copy link
Member

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@DanTup DanTup merged commit 3e3f315 into flutter:master Feb 5, 2019
@DanTup DanTup deleted the fix-cli-driver-race branch February 5, 2019 17:11
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

Successfully merging this pull request may close these issues.

2 participants