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

Add communication logging to Flutter Driver #7485

Merged
merged 1 commit into from Jan 17, 2017

Conversation

goderbauer
Copy link
Member

@goderbauer goderbauer commented Jan 13, 2017

This is handy for debugging a test. Communication is logged to:

  • flutter_driver_commands.log (enabled by default)
  • stdout (disabled by default)

fixes #7473

@@ -94,7 +97,9 @@ class FlutterDriver {
/// Creates a driver that uses a connection provided by the given
/// [_serviceClient], [_peer] and [_appIsolate].
@visibleForTesting
FlutterDriver.connectedTo(this._serviceClient, this._peer, this._appIsolate);
FlutterDriver.connectedTo(this._serviceClient, this._peer, this._appIsolate,
{bool printCommunication: false})
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: spaces around named args

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

///
/// [printCommunication] determines wheather the command communication between
/// the test and the app should be printed to stdout.
static Future<FlutterDriver> connect({String dartVmServiceUrl, bool printCommunication: false}) async {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: same

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

FlutterDriver driver = new FlutterDriver.connectedTo(client, connection.peer, isolate);
FlutterDriver driver = new FlutterDriver.connectedTo(
client, connection.peer, isolate,
printCommunication: printCommunication);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: if you have a newline after an open parenthesis, you should have a newline before the closing one

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

void _logCommunication(String message) {
if (_printCommunication)
_log.info(message);
f.File file = fs.file(p.join(testOutputsDirectory, 'flutter_driver_commands.log'));
Copy link
Contributor

Choose a reason for hiding this comment

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

if you have multiple flutter_driver instances running on the same filesystem, this will result in corruption. Should we attempt to flock() the file while we're writing to it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also this will result in failure if run against a read-only file system or a file system that has no more free disk space.

Maybe we should make saving to disk also optional?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you run multiple flutter_driver instances, you should provide them with different testOutputsDirectory. Otherwise, the output in there is meaningless anyways.

Added an option to disable logging to file, but I'll leave it turned on by default.

FlutterDriver.connectedTo(this._serviceClient, this._peer, this._appIsolate);
FlutterDriver.connectedTo(this._serviceClient, this._peer, this._appIsolate,
{ bool printCommunication: false, bool logCommunicationToFile: true })
: _printCommunication = printCommunication, _logCommunicationToFile = logCommunicationToFile;
Copy link
Contributor

Choose a reason for hiding this comment

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

How about instead of adding these options we publish a "stream" of log messages and provide utility functions to log them to stdout and files? This way the driver won't have to decide where the log messages go. I think producing log messages and logging them are separate concerns.

One use-case where this could be problematic is in multi-device testing. There you have multiple instances of FlutterDriver, each talking to its own device. If we have them write to the same file, things can get messy.

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed in person: debugging (especially when dealing with random flakes) will be a lot easier if the log is always produced.

To avoid the multi-device testing problem, I added an ID to each driver instance and each instance now logs to flutter_driver_commands_${driverId}.log.

This is handy for debugging a test. Communication is logged to:
* `flutter_driver_commands_{x}.log`, where {x} is an integer, and
* (if requested by user) to stdout

fixes flutter#7473
@goderbauer goderbauer merged commit ecc4972 into flutter:master Jan 17, 2017
@goderbauer goderbauer deleted the logDriverCmds branch February 24, 2017 01:43
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flutter_driver should log all commands executed
4 participants