Unverified Commit baecbdfe authored by Alexander Dahlberg's avatar Alexander Dahlberg Committed by GitHub

Fixed order dependency and removed no-shuffle tag in flutter_driver_test (#89477)

parent 51588ab8
...@@ -25,7 +25,10 @@ class VMServiceFlutterDriver extends FlutterDriver { ...@@ -25,7 +25,10 @@ class VMServiceFlutterDriver extends FlutterDriver {
bool logCommunicationToFile = true, bool logCommunicationToFile = true,
}) : _printCommunication = printCommunication, }) : _printCommunication = printCommunication,
_logCommunicationToFile = logCommunicationToFile, _logCommunicationToFile = logCommunicationToFile,
_driverId = _nextDriverId++; _driverId = _nextDriverId++
{
_logFilePathName = p.join(testOutputsDirectory, 'flutter_driver_commands_$_driverId.log');
}
/// Connects to a Flutter application. /// Connects to a Flutter application.
/// ///
...@@ -287,6 +290,12 @@ class VMServiceFlutterDriver extends FlutterDriver { ...@@ -287,6 +290,12 @@ class VMServiceFlutterDriver extends FlutterDriver {
/// Whether to log communication between host and app to `flutter_driver_commands.log`. /// Whether to log communication between host and app to `flutter_driver_commands.log`.
final bool _logCommunicationToFile; final bool _logCommunicationToFile;
/// Logs are written here when _logCommunicationToFile is true.
late final String _logFilePathName;
/// Getter for file pathname where logs are written when _logCommunicationToFile is true.
String get logFilePathName => _logFilePathName;
@override @override
Future<Map<String, dynamic>> sendCommand(Command command) async { Future<Map<String, dynamic>> sendCommand(Command command) async {
...@@ -321,7 +330,8 @@ class VMServiceFlutterDriver extends FlutterDriver { ...@@ -321,7 +330,8 @@ class VMServiceFlutterDriver extends FlutterDriver {
if (_printCommunication) if (_printCommunication)
_log(message); _log(message);
if (_logCommunicationToFile) { if (_logCommunicationToFile) {
final f.File file = fs.file(p.join(testOutputsDirectory, 'flutter_driver_commands_$_driverId.log')); assert(_logFilePathName != null);
final f.File file = fs.file(_logFilePathName);
file.createSync(recursive: true); // no-op if file exists file.createSync(recursive: true); // no-op if file exists
file.writeAsStringSync('${DateTime.now()} $message\n', mode: f.FileMode.append, flush: true); file.writeAsStringSync('${DateTime.now()} $message\n', mode: f.FileMode.append, flush: true);
} }
......
...@@ -35,7 +35,11 @@ class WebFlutterDriver extends FlutterDriver { ...@@ -35,7 +35,11 @@ class WebFlutterDriver extends FlutterDriver {
}) : _printCommunication = printCommunication, }) : _printCommunication = printCommunication,
_logCommunicationToFile = logCommunicationToFile, _logCommunicationToFile = logCommunicationToFile,
_startTime = DateTime.now(), _startTime = DateTime.now(),
_driverId = _nextDriverId++; _driverId = _nextDriverId++
{
_logFilePathName = path.join(testOutputsDirectory, 'flutter_driver_commands_$_driverId.log');
}
final FlutterWebConnection _connection; final FlutterWebConnection _connection;
DateTime _startTime; DateTime _startTime;
...@@ -63,6 +67,12 @@ class WebFlutterDriver extends FlutterDriver { ...@@ -63,6 +67,12 @@ class WebFlutterDriver extends FlutterDriver {
/// Whether to log communication between host and app to `flutter_driver_commands.log`. /// Whether to log communication between host and app to `flutter_driver_commands.log`.
final bool _logCommunicationToFile; final bool _logCommunicationToFile;
/// Logs are written here when _logCommunicationToFile is true.
late final String _logFilePathName;
/// Getter for file pathname where logs are written when _logCommunicationToFile is true
String get logFilePathName => _logFilePathName;
/// Creates a driver that uses a connection provided by the given /// Creates a driver that uses a connection provided by the given
/// [hostUrl] which would fallback to environment variable VM_SERVICE_URL. /// [hostUrl] which would fallback to environment variable VM_SERVICE_URL.
/// Driver also depends on environment variables DRIVER_SESSION_ID, /// Driver also depends on environment variables DRIVER_SESSION_ID,
...@@ -128,7 +138,8 @@ class WebFlutterDriver extends FlutterDriver { ...@@ -128,7 +138,8 @@ class WebFlutterDriver extends FlutterDriver {
driverLog('WebFlutterDriver', message); driverLog('WebFlutterDriver', message);
} }
if (_logCommunicationToFile) { if (_logCommunicationToFile) {
final File file = fs.file(path.join(testOutputsDirectory, 'flutter_driver_commands_$_driverId.log')); assert(_logFilePathName != null);
final File file = fs.file(_logFilePathName);
file.createSync(recursive: true); // no-op if file exists file.createSync(recursive: true); // no-op if file exists
file.writeAsStringSync('${DateTime.now()} $message\n', mode: FileMode.append, flush: true); file.writeAsStringSync('${DateTime.now()} $message\n', mode: FileMode.append, flush: true);
} }
......
...@@ -2,12 +2,6 @@ ...@@ -2,12 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// TODO(gspencergoog): Remove this tag once this test's state leaks/test
// dependencies have been fixed.
// https://github.com/flutter/flutter/issues/85160
// Fails with "flutter test --test-randomize-ordering-seed=20210721"
@Tags(<String>['no-shuffle'])
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
...@@ -17,10 +11,8 @@ import 'package:flutter_driver/src/common/error.dart'; ...@@ -17,10 +11,8 @@ import 'package:flutter_driver/src/common/error.dart';
import 'package:flutter_driver/src/common/health.dart'; import 'package:flutter_driver/src/common/health.dart';
import 'package:flutter_driver/src/common/layer_tree.dart'; import 'package:flutter_driver/src/common/layer_tree.dart';
import 'package:flutter_driver/src/common/wait.dart'; import 'package:flutter_driver/src/common/wait.dart';
import 'package:flutter_driver/src/driver/common.dart';
import 'package:flutter_driver/src/driver/driver.dart'; import 'package:flutter_driver/src/driver/driver.dart';
import 'package:flutter_driver/src/driver/timeline.dart'; import 'package:flutter_driver/src/driver/timeline.dart';
import 'package:path/path.dart' as path;
import 'package:vm_service/vm_service.dart' as vms; import 'package:vm_service/vm_service.dart' as vms;
import '../../common.dart'; import '../../common.dart';
...@@ -44,15 +36,12 @@ void main() { ...@@ -44,15 +36,12 @@ void main() {
late FakeIsolate fakeIsolate; late FakeIsolate fakeIsolate;
late VMServiceFlutterDriver driver; late VMServiceFlutterDriver driver;
late File logFile; late File logFile;
int driverId = -1;
setUp(() { setUp(() {
fakeIsolate = FakeIsolate(); fakeIsolate = FakeIsolate();
fakeVM = FakeVM(fakeIsolate); fakeVM = FakeVM(fakeIsolate);
fakeClient = FakeVmService(fakeVM); fakeClient = FakeVmService(fakeVM);
fakeClient.responses['waitFor'] = makeFakeResponse(<String, dynamic>{'status':'ok'}); fakeClient.responses['waitFor'] = makeFakeResponse(<String, dynamic>{'status':'ok'});
driverId += 1;
logFile = File(path.join(testOutputsDirectory, 'flutter_driver_commands_$driverId.log'));
}); });
tearDown(() { tearDown(() {
...@@ -64,6 +53,7 @@ void main() { ...@@ -64,6 +53,7 @@ void main() {
group('logCommunicationToFile', () { group('logCommunicationToFile', () {
test('logCommunicationToFile = true', () async { test('logCommunicationToFile = true', () async {
driver = VMServiceFlutterDriver.connectedTo(fakeClient, fakeIsolate); driver = VMServiceFlutterDriver.connectedTo(fakeClient, fakeIsolate);
logFile = File(driver.logFilePathName);
await driver.waitFor(find.byTooltip('foo'), timeout: _kTestTimeout); await driver.waitFor(find.byTooltip('foo'), timeout: _kTestTimeout);
...@@ -80,12 +70,22 @@ void main() { ...@@ -80,12 +70,22 @@ void main() {
test('logCommunicationToFile = false', () async { test('logCommunicationToFile = false', () async {
driver = VMServiceFlutterDriver.connectedTo(fakeClient, fakeIsolate, logCommunicationToFile: false); driver = VMServiceFlutterDriver.connectedTo(fakeClient, fakeIsolate, logCommunicationToFile: false);
logFile = File(driver.logFilePathName);
// clear log file if left in filetree from previous run
if (logFile.existsSync()) {
logFile.deleteSync();
}
await driver.waitFor(find.byTooltip('foo'), timeout: _kTestTimeout); await driver.waitFor(find.byTooltip('foo'), timeout: _kTestTimeout);
final bool exists = logFile.existsSync(); final bool exists = logFile.existsSync();
expect(exists, false, reason: 'because ${logFile.path} exists'); expect(exists, false, reason: 'because ${logFile.path} exists');
}); });
test('logFilePathName was set when a new driver was created', () {
driver = VMServiceFlutterDriver.connectedTo(fakeClient, fakeIsolate, logCommunicationToFile: true);
logFile = File(driver.logFilePathName);
expect(logFile.path, endsWith('.log'));
});
}); });
}); });
...@@ -720,14 +720,11 @@ void main() { ...@@ -720,14 +720,11 @@ void main() {
late FakeFlutterWebConnection fakeConnection; late FakeFlutterWebConnection fakeConnection;
late WebFlutterDriver driver; late WebFlutterDriver driver;
late File logFile; late File logFile;
int driverId = -1;
setUp(() { setUp(() {
fakeConnection = FakeFlutterWebConnection(); fakeConnection = FakeFlutterWebConnection();
fakeConnection.supportsTimelineAction = true; fakeConnection.supportsTimelineAction = true;
fakeConnection.responses['waitFor'] = jsonEncode(makeFakeResponse(<String, dynamic>{'status': 'ok'})); fakeConnection.responses['waitFor'] = jsonEncode(makeFakeResponse(<String, dynamic>{'status': 'ok'}));
driverId += 1;
logFile = File(path.join(testOutputsDirectory, 'flutter_driver_commands_$driverId.log'));
}); });
tearDown(() { tearDown(() {
...@@ -738,6 +735,7 @@ void main() { ...@@ -738,6 +735,7 @@ void main() {
test('logCommunicationToFile = true', () async { test('logCommunicationToFile = true', () async {
driver = WebFlutterDriver.connectedTo(fakeConnection); driver = WebFlutterDriver.connectedTo(fakeConnection);
logFile = File(driver.logFilePathName);
await driver.waitFor(find.byTooltip('logCommunicationToFile test'), timeout: _kTestTimeout); await driver.waitFor(find.byTooltip('logCommunicationToFile test'), timeout: _kTestTimeout);
final bool exists = logFile.existsSync(); final bool exists = logFile.existsSync();
...@@ -753,6 +751,11 @@ void main() { ...@@ -753,6 +751,11 @@ void main() {
test('logCommunicationToFile = false', () async { test('logCommunicationToFile = false', () async {
driver = WebFlutterDriver.connectedTo(fakeConnection, logCommunicationToFile: false); driver = WebFlutterDriver.connectedTo(fakeConnection, logCommunicationToFile: false);
logFile = File(driver.logFilePathName);
// clear log file if left in filetree from previous run
if (logFile.existsSync()) {
logFile.deleteSync();
}
await driver.waitFor(find.byTooltip('logCommunicationToFile test'), timeout: _kTestTimeout); await driver.waitFor(find.byTooltip('logCommunicationToFile test'), timeout: _kTestTimeout);
final bool exists = logFile.existsSync(); final bool exists = logFile.existsSync();
expect(exists, false, reason: 'because ${logFile.path} exists'); expect(exists, false, reason: 'because ${logFile.path} exists');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment