Let flutter attach find the service port by looking through old logs again (#53153)
This commit is contained in:
@@ -97,12 +97,13 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('finds observatory port and forwards', () async {
|
||||
when(device.getLogReader()).thenAnswer((_) {
|
||||
// Now that the reader is used, start writing messages to it.
|
||||
mockLogReader.addLine('Foo');
|
||||
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
|
||||
return mockLogReader;
|
||||
});
|
||||
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
|
||||
.thenAnswer((_) {
|
||||
// Now that the reader is used, start writing messages to it.
|
||||
mockLogReader.addLine('Foo');
|
||||
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
|
||||
return mockLogReader;
|
||||
});
|
||||
testDeviceManager.addDevice(device);
|
||||
final Completer<void> completer = Completer<void>();
|
||||
final StreamSubscription<String> loggerSubscription = logger.stream.listen((String message) {
|
||||
@@ -134,12 +135,14 @@ void main() {
|
||||
..writeAsStringSync('{}');
|
||||
|
||||
when(device.name).thenReturn('MockAndroidDevice');
|
||||
when(device.getLogReader()).thenReturn(mockLogReader);
|
||||
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
|
||||
|
||||
final Process dartProcess = MockProcess();
|
||||
final StreamController<List<int>> compilerStdoutController = StreamController<List<int>>();
|
||||
.thenReturn(mockLogReader);
|
||||
|
||||
when(dartProcess.stdout).thenAnswer((_) => compilerStdoutController.stream);
|
||||
final Process dartProcess = MockProcess();
|
||||
final StreamController<List<int>> compilerStdoutController = StreamController<List<int>>();
|
||||
|
||||
when(dartProcess.stdout).thenAnswer((_) => compilerStdoutController.stream);
|
||||
when(dartProcess.stderr)
|
||||
.thenAnswer((_) => Stream<List<int>>.fromFuture(Future<List<int>>.value(const <int>[])));
|
||||
|
||||
@@ -232,13 +235,14 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('Fails with tool exit on bad Observatory uri', () async {
|
||||
when(device.getLogReader()).thenAnswer((_) {
|
||||
// Now that the reader is used, start writing messages to it.
|
||||
mockLogReader.addLine('Foo');
|
||||
mockLogReader.addLine('Observatory listening on http:/:/127.0.0.1:$devicePort');
|
||||
mockLogReader.dispose();
|
||||
return mockLogReader;
|
||||
});
|
||||
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
|
||||
.thenAnswer((_) {
|
||||
// Now that the reader is used, start writing messages to it.
|
||||
mockLogReader.addLine('Foo');
|
||||
mockLogReader.addLine('Observatory listening on http:/:/127.0.0.1:$devicePort');
|
||||
mockLogReader.dispose();
|
||||
return mockLogReader;
|
||||
});
|
||||
testDeviceManager.addDevice(device);
|
||||
expect(createTestCommandRunner(AttachCommand()).run(<String>['attach']),
|
||||
throwsToolExit());
|
||||
@@ -249,12 +253,13 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('accepts filesystem parameters', () async {
|
||||
when(device.getLogReader()).thenAnswer((_) {
|
||||
// Now that the reader is used, start writing messages to it.
|
||||
mockLogReader.addLine('Foo');
|
||||
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
|
||||
return mockLogReader;
|
||||
});
|
||||
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
|
||||
.thenAnswer((_) {
|
||||
// Now that the reader is used, start writing messages to it.
|
||||
mockLogReader.addLine('Foo');
|
||||
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
|
||||
return mockLogReader;
|
||||
});
|
||||
testDeviceManager.addDevice(device);
|
||||
|
||||
const String filesystemScheme = 'foo';
|
||||
@@ -328,12 +333,13 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('exits when ipv6 is specified and debug-port is not', () async {
|
||||
when(device.getLogReader()).thenAnswer((_) {
|
||||
// Now that the reader is used, start writing messages to it.
|
||||
mockLogReader.addLine('Foo');
|
||||
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
|
||||
return mockLogReader;
|
||||
});
|
||||
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
|
||||
.thenAnswer((_) {
|
||||
// Now that the reader is used, start writing messages to it.
|
||||
mockLogReader.addLine('Foo');
|
||||
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
|
||||
return mockLogReader;
|
||||
});
|
||||
testDeviceManager.addDevice(device);
|
||||
|
||||
final AttachCommand command = AttachCommand();
|
||||
@@ -350,12 +356,13 @@ void main() {
|
||||
},);
|
||||
|
||||
testUsingContext('exits when observatory-port is specified and debug-port is not', () async {
|
||||
when(device.getLogReader()).thenAnswer((_) {
|
||||
// Now that the reader is used, start writing messages to it.
|
||||
mockLogReader.addLine('Foo');
|
||||
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
|
||||
return mockLogReader;
|
||||
});
|
||||
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
|
||||
.thenAnswer((_) {
|
||||
// Now that the reader is used, start writing messages to it.
|
||||
mockLogReader.addLine('Foo');
|
||||
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
|
||||
return mockLogReader;
|
||||
});
|
||||
testDeviceManager.addDevice(device);
|
||||
|
||||
final AttachCommand command = AttachCommand();
|
||||
@@ -402,7 +409,7 @@ void main() {
|
||||
when(mockHotRunner.isWaitingForObservatory).thenReturn(false);
|
||||
|
||||
testDeviceManager.addDevice(device);
|
||||
when(device.getLogReader())
|
||||
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
|
||||
.thenAnswer((_) {
|
||||
// Now that the reader is used, start writing messages to it.
|
||||
mockLogReader.addLine('Foo');
|
||||
@@ -441,7 +448,8 @@ void main() {
|
||||
final MockHotRunner mockHotRunner = MockHotRunner();
|
||||
final MockHotRunnerFactory mockHotRunnerFactory = MockHotRunnerFactory();
|
||||
when(device.portForwarder).thenReturn(portForwarder);
|
||||
when(device.getLogReader()).thenAnswer((_) => mockLogReader);
|
||||
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
|
||||
.thenAnswer((_) => mockLogReader);
|
||||
when(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')))
|
||||
.thenAnswer((_) async => hostPort);
|
||||
when(portForwarder.forwardedPorts)
|
||||
|
||||
@@ -633,7 +633,10 @@ class FakeDevice extends Fake implements Device {
|
||||
Future<String> get sdkNameAndVersion => Future<String>.value('');
|
||||
|
||||
@override
|
||||
DeviceLogReader getLogReader({ ApplicationPackage app }) {
|
||||
DeviceLogReader getLogReader({
|
||||
ApplicationPackage app,
|
||||
bool includePastLogs = false,
|
||||
}) {
|
||||
return FakeDeviceLogReader();
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,30 @@ void main() {
|
||||
expect(processManager.hasRemainingExpectations, false);
|
||||
});
|
||||
|
||||
testWithoutContext('AdbLogReader calls adb logcat with expected flags when requesting past logs', () async {
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'adb',
|
||||
'-s',
|
||||
'1234',
|
||||
'logcat',
|
||||
'-v',
|
||||
'time',
|
||||
'-s',
|
||||
'flutter',
|
||||
],
|
||||
)
|
||||
]);
|
||||
await AdbLogReader.createLogReader(
|
||||
createMockDevice(null),
|
||||
processManager,
|
||||
includePastLogs: true,
|
||||
);
|
||||
|
||||
expect(processManager.hasRemainingExpectations, false);
|
||||
});
|
||||
|
||||
testWithoutContext('AdbLogReader handles process early exit', () async {
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
FakeCommand(
|
||||
|
||||
@@ -468,17 +468,48 @@ flutter:
|
||||
});
|
||||
});
|
||||
|
||||
group('lastLogcatTimestamp', () {
|
||||
group('logcat', () {
|
||||
final ProcessManager mockProcessManager = MockProcessManager();
|
||||
final AndroidDevice device = AndroidDevice('1234');
|
||||
|
||||
testUsingContext('returns null if shell command failed', () async {
|
||||
testUsingContext('lastLogcatTimestamp returns null if shell command failed', () async {
|
||||
when(mockProcessManager.runSync(argThat(contains('logcat'))))
|
||||
.thenReturn(ProcessResult(0, 1, '', ''));
|
||||
expect(device.lastLogcatTimestamp, isNull);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
});
|
||||
|
||||
testUsingContext('AdbLogReaders for past+future and future logs are not the same', () async {
|
||||
when(mockProcessManager.run(
|
||||
argThat(contains('getprop')),
|
||||
stderrEncoding: anyNamed('stderrEncoding'),
|
||||
stdoutEncoding: anyNamed('stdoutEncoding'),
|
||||
)).thenAnswer((_) {
|
||||
final StringBuffer buf = StringBuffer()
|
||||
..writeln('[ro.build.version.sdk]: [23]');
|
||||
final ProcessResult result = ProcessResult(1, exitCode, buf.toString(), '');
|
||||
return Future<ProcessResult>.value(result);
|
||||
});
|
||||
when(mockProcessManager.run(
|
||||
argThat(contains('shell')),
|
||||
stderrEncoding: anyNamed('stderrEncoding'),
|
||||
stdoutEncoding: anyNamed('stdoutEncoding'),
|
||||
)).thenAnswer((_) {
|
||||
final StringBuffer buf = StringBuffer()
|
||||
..writeln('11-27 15:39:04.506');
|
||||
final ProcessResult result = ProcessResult(1, exitCode, buf.toString(), '');
|
||||
return Future<ProcessResult>.value(result);
|
||||
});
|
||||
final DeviceLogReader pastLogReader = await device.getLogReader(includePastLogs: true);
|
||||
final DeviceLogReader defaultLogReader = await device.getLogReader();
|
||||
expect(pastLogReader, isNot(equals(defaultLogReader)));
|
||||
// Getting again is cached.
|
||||
expect(pastLogReader, equals(await device.getLogReader(includePastLogs: true)));
|
||||
expect(defaultLogReader, equals(await device.getLogReader()));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
});
|
||||
});
|
||||
|
||||
test('Can parse adb shell dumpsys info', () {
|
||||
|
||||
Reference in New Issue
Block a user