Apply basic log filtering and formatting to fuchsia logs. (#24143)
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:flutter_tools/src/base/time.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:quiver/time.dart';
|
||||
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
@@ -56,7 +56,7 @@ void main() {
|
||||
await runner.run(<String>['doctor']);
|
||||
expect(count, 0);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => FlutterVersion(const Clock()),
|
||||
FlutterVersion: () => FlutterVersion(const SystemClock()),
|
||||
Usage: () => Usage(configDirOverride: tempDir.path),
|
||||
});
|
||||
|
||||
@@ -75,14 +75,14 @@ void main() {
|
||||
await runner.run(<String>['config']);
|
||||
expect(count, 0);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => FlutterVersion(const Clock()),
|
||||
FlutterVersion: () => FlutterVersion(const SystemClock()),
|
||||
Usage: () => Usage(configDirOverride: tempDir.path),
|
||||
});
|
||||
});
|
||||
|
||||
group('analytics with mocks', () {
|
||||
Usage mockUsage;
|
||||
Clock mockClock;
|
||||
SystemClock mockClock;
|
||||
Doctor mockDoctor;
|
||||
List<int> mockTimes;
|
||||
|
||||
@@ -110,7 +110,7 @@ void main() {
|
||||
<dynamic>['flutter', 'doctor', const Duration(milliseconds: 1000), 'success']
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
Clock: () => mockClock,
|
||||
SystemClock: () => mockClock,
|
||||
Doctor: () => mockDoctor,
|
||||
Usage: () => mockUsage,
|
||||
});
|
||||
@@ -129,7 +129,7 @@ void main() {
|
||||
<dynamic>['flutter', 'doctor', const Duration(milliseconds: 1000), 'warning']
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
Clock: () => mockClock,
|
||||
SystemClock: () => mockClock,
|
||||
Doctor: () => mockDoctor,
|
||||
Usage: () => mockUsage,
|
||||
});
|
||||
|
||||
@@ -2,7 +2,16 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/fuchsia/fuchsia_device.dart';
|
||||
import 'package:flutter_tools/src/base/time.dart';
|
||||
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
@@ -34,5 +43,102 @@ d 2 0 .
|
||||
expect(ports.length, 1);
|
||||
expect(ports.single, 36780);
|
||||
});
|
||||
|
||||
group('device logs', () {
|
||||
const String exampleUtcLogs = '''
|
||||
[2018-11-09 01:27:45][3][297950920][log] INFO: example_app(flutter): Error doing thing
|
||||
[2018-11-09 01:27:58][46257][46269][foo] INFO: Using a thing
|
||||
[2018-11-09 01:29:58][46257][46269][foo] INFO: Blah blah blah
|
||||
[2018-11-09 01:29:58][46257][46269][foo] INFO: other_app(flutter): Do thing
|
||||
[2018-11-09 01:30:02][41175][41187][bar] INFO: Invoking a bar
|
||||
[2018-11-09 01:30:12][52580][52983][log] INFO: example_app(flutter): Did thing this time
|
||||
|
||||
''';
|
||||
final MockProcessManager mockProcessManager = MockProcessManager();
|
||||
final MockProcess mockProcess = MockProcess();
|
||||
Completer<int> exitCode;
|
||||
StreamController<List<int>> stdout;
|
||||
StreamController<List<int>> stderr;
|
||||
when(mockProcessManager.start(any)).thenAnswer((Invocation _) => Future<Process>.value(mockProcess));
|
||||
when(mockProcess.exitCode).thenAnswer((Invocation _) => exitCode.future);
|
||||
when(mockProcess.stdout).thenAnswer((Invocation _) => stdout.stream);
|
||||
when(mockProcess.stderr).thenAnswer((Invocation _) => stderr.stream);
|
||||
|
||||
setUp(() {
|
||||
stdout = StreamController<List<int>>(sync: true);
|
||||
stderr = StreamController<List<int>>(sync: true);
|
||||
exitCode = Completer<int>();
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
exitCode.complete(0);
|
||||
});
|
||||
|
||||
testUsingContext('can be parsed for an app', () async {
|
||||
final FuchsiaDevice device = FuchsiaDevice('id', name: 'tester');
|
||||
final DeviceLogReader reader = device.getLogReader(app: FuchsiaModulePackage(name: 'example_app'));
|
||||
final List<String> logLines = <String>[];
|
||||
reader.logLines.listen(logLines.add);
|
||||
expect(logLines, isEmpty);
|
||||
|
||||
stdout.add(utf8.encode(exampleUtcLogs));
|
||||
await stdout.close();
|
||||
|
||||
expect(logLines, <String>[
|
||||
'[2018-11-09 01:27:45.000] Flutter: Error doing thing',
|
||||
'[2018-11-09 01:30:12.000] Flutter: Did thing this time',
|
||||
]);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
SystemClock: () => SystemClock.fixed(DateTime(2018, 11, 9, 1, 25, 45)),
|
||||
});
|
||||
|
||||
testUsingContext('cuts off prior logs', () async {
|
||||
final FuchsiaDevice device = FuchsiaDevice('id', name: 'tester');
|
||||
final DeviceLogReader reader = device.getLogReader(app: FuchsiaModulePackage(name: 'example_app'));
|
||||
final List<String> logLines = <String>[];
|
||||
final Completer<void> lock = Completer<void>();
|
||||
reader.logLines.listen((String line) {
|
||||
logLines.add(line);
|
||||
lock.complete();
|
||||
});
|
||||
expect(logLines, isEmpty);
|
||||
|
||||
stdout.add(utf8.encode(exampleUtcLogs));
|
||||
await stdout.close();
|
||||
await lock.future;
|
||||
|
||||
expect(logLines, <String>[
|
||||
'[2018-11-09 01:30:12.000] Flutter: Did thing this time',
|
||||
]);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
SystemClock: () => SystemClock.fixed(DateTime(2018, 11, 9, 1, 29, 45)),
|
||||
});
|
||||
|
||||
testUsingContext('can be parsed for all apps', () async {
|
||||
final FuchsiaDevice device = FuchsiaDevice('id', name: 'tester');
|
||||
final DeviceLogReader reader = device.getLogReader();
|
||||
final List<String> logLines = <String>[];
|
||||
reader.logLines.listen(logLines.add);
|
||||
expect(logLines, isEmpty);
|
||||
|
||||
stdout.add(utf8.encode(exampleUtcLogs));
|
||||
await stdout.close();
|
||||
|
||||
expect(logLines, <String>[
|
||||
'[2018-11-09 01:27:45.000] Flutter: Error doing thing',
|
||||
'[2018-11-09 01:29:58.000] Flutter: Do thing',
|
||||
'[2018-11-09 01:30:12.000] Flutter: Did thing this time',
|
||||
]);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
SystemClock: () => SystemClock.fixed(DateTime(2018, 11, 9, 1, 25, 45)),
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
|
||||
class MockProcess extends Mock implements Process {}
|
||||
|
||||
@@ -5,15 +5,14 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/base/time.dart';
|
||||
import 'package:flutter_tools/src/usage.dart';
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/runner/flutter_command.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:quiver/time.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
group('Flutter Command', () {
|
||||
@@ -67,7 +66,7 @@ void main() {
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Clock: () => clock,
|
||||
SystemClock: () => clock,
|
||||
Usage: () => usage,
|
||||
});
|
||||
|
||||
@@ -84,7 +83,7 @@ void main() {
|
||||
label: anyNamed('label')));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Clock: () => clock,
|
||||
SystemClock: () => clock,
|
||||
Usage: () => usage,
|
||||
});
|
||||
|
||||
@@ -117,7 +116,7 @@ void main() {
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Clock: () => clock,
|
||||
SystemClock: () => clock,
|
||||
Usage: () => usage,
|
||||
});
|
||||
|
||||
@@ -153,7 +152,7 @@ void main() {
|
||||
}
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Clock: () => clock,
|
||||
SystemClock: () => clock,
|
||||
Usage: () => usage,
|
||||
});
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/doctor.dart';
|
||||
import 'package:flutter_tools/src/ios/simulators.dart';
|
||||
import 'package:flutter_tools/src/ios/xcodeproj.dart';
|
||||
import 'package:flutter_tools/src/base/time.dart';
|
||||
import 'package:flutter_tools/src/usage.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:quiver/time.dart';
|
||||
|
||||
import 'common.dart';
|
||||
|
||||
@@ -300,7 +300,7 @@ class MockXcodeProjectInterpreter implements XcodeProjectInterpreter {
|
||||
|
||||
class MockFlutterVersion extends Mock implements FlutterVersion {}
|
||||
|
||||
class MockClock extends Mock implements Clock {}
|
||||
class MockClock extends Mock implements SystemClock {}
|
||||
|
||||
class MockHttpClient extends Mock implements HttpClient {}
|
||||
|
||||
|
||||
21
packages/flutter_tools/test/time_test.dart
Normal file
21
packages/flutter_tools/test/time_test.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/base/time.dart';
|
||||
|
||||
import 'src/common.dart';
|
||||
|
||||
void main() {
|
||||
group(SystemClock, () {
|
||||
test('can set a fixed time', () {
|
||||
final SystemClock clock = SystemClock.fixed(DateTime(1991, 8, 23));
|
||||
expect(clock.now(), DateTime(1991, 8, 23));
|
||||
});
|
||||
|
||||
test('can find a time ago', () {
|
||||
final SystemClock clock = SystemClock.fixed(DateTime(1991, 8, 23));
|
||||
expect(clock.ago(Duration(days: 10)), DateTime(1991, 8, 13));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -5,9 +5,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:collection/collection.dart' show ListEquality;
|
||||
import 'package:flutter_tools/src/base/time.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
import 'package:quiver/time.dart';
|
||||
|
||||
import 'package:flutter_tools/src/base/context.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
@@ -18,11 +18,11 @@ import 'package:flutter_tools/src/version.dart';
|
||||
import 'src/common.dart';
|
||||
import 'src/context.dart';
|
||||
|
||||
final Clock _testClock = Clock.fixed(DateTime(2015, 1, 1));
|
||||
final DateTime _upToDateVersion = _testClock.agoBy(FlutterVersion.kVersionAgeConsideredUpToDate ~/ 2);
|
||||
final DateTime _outOfDateVersion = _testClock.agoBy(FlutterVersion.kVersionAgeConsideredUpToDate * 2);
|
||||
final DateTime _stampUpToDate = _testClock.agoBy(FlutterVersion.kCheckAgeConsideredUpToDate ~/ 2);
|
||||
final DateTime _stampOutOfDate = _testClock.agoBy(FlutterVersion.kCheckAgeConsideredUpToDate * 2);
|
||||
final SystemClock _testClock = SystemClock.fixed(DateTime(2015, 1, 1));
|
||||
final DateTime _upToDateVersion = _testClock.ago(FlutterVersion.kVersionAgeConsideredUpToDate ~/ 2);
|
||||
final DateTime _outOfDateVersion = _testClock.ago(FlutterVersion.kVersionAgeConsideredUpToDate * 2);
|
||||
final DateTime _stampUpToDate = _testClock.ago(FlutterVersion.kCheckAgeConsideredUpToDate ~/ 2);
|
||||
final DateTime _stampOutOfDate = _testClock.ago(FlutterVersion.kCheckAgeConsideredUpToDate * 2);
|
||||
|
||||
void main() {
|
||||
MockProcessManager mockProcessManager;
|
||||
@@ -161,7 +161,7 @@ void main() {
|
||||
localCommitDate: _outOfDateVersion,
|
||||
stamp: VersionCheckStamp(
|
||||
lastTimeVersionWasChecked: _stampOutOfDate,
|
||||
lastKnownRemoteVersion: _testClock.ago(days: 2),
|
||||
lastKnownRemoteVersion: _testClock.ago(const Duration(days: 2)),
|
||||
),
|
||||
remoteCommitDate: _upToDateVersion,
|
||||
expectSetStamp: true,
|
||||
@@ -287,15 +287,15 @@ void main() {
|
||||
testUsingContext('loads valid JSON', () async {
|
||||
fakeData(mockProcessManager, mockCache, stampJson: '''
|
||||
{
|
||||
"lastKnownRemoteVersion": "${_testClock.ago(days: 1)}",
|
||||
"lastTimeVersionWasChecked": "${_testClock.ago(days: 2)}",
|
||||
"lastKnownRemoteVersion": "${_testClock.ago(const Duration(days: 1))}",
|
||||
"lastTimeVersionWasChecked": "${_testClock.ago(const Duration(days: 2))}",
|
||||
"lastTimeWarningWasPrinted": "${_testClock.now()}"
|
||||
}
|
||||
''');
|
||||
|
||||
final VersionCheckStamp stamp = await VersionCheckStamp.load();
|
||||
expect(stamp.lastKnownRemoteVersion, _testClock.ago(days: 1));
|
||||
expect(stamp.lastTimeVersionWasChecked, _testClock.ago(days: 2));
|
||||
expect(stamp.lastKnownRemoteVersion, _testClock.ago(const Duration(days: 1)));
|
||||
expect(stamp.lastTimeVersionWasChecked, _testClock.ago(const Duration(days: 2)));
|
||||
expect(stamp.lastTimeWarningWasPrinted, _testClock.now());
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => FlutterVersion(_testClock),
|
||||
@@ -309,15 +309,15 @@ void main() {
|
||||
_expectDefault(await VersionCheckStamp.load());
|
||||
|
||||
final VersionCheckStamp stamp = VersionCheckStamp(
|
||||
lastKnownRemoteVersion: _testClock.ago(days: 1),
|
||||
lastTimeVersionWasChecked: _testClock.ago(days: 2),
|
||||
lastKnownRemoteVersion: _testClock.ago(const Duration(days: 1)),
|
||||
lastTimeVersionWasChecked: _testClock.ago(const Duration(days: 2)),
|
||||
lastTimeWarningWasPrinted: _testClock.now(),
|
||||
);
|
||||
await stamp.store();
|
||||
|
||||
final VersionCheckStamp storedStamp = await VersionCheckStamp.load();
|
||||
expect(storedStamp.lastKnownRemoteVersion, _testClock.ago(days: 1));
|
||||
expect(storedStamp.lastTimeVersionWasChecked, _testClock.ago(days: 2));
|
||||
expect(storedStamp.lastKnownRemoteVersion, _testClock.ago(const Duration(days: 1)));
|
||||
expect(storedStamp.lastTimeVersionWasChecked, _testClock.ago(const Duration(days: 2)));
|
||||
expect(storedStamp.lastTimeWarningWasPrinted, _testClock.now());
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => FlutterVersion(_testClock),
|
||||
@@ -331,19 +331,19 @@ void main() {
|
||||
_expectDefault(await VersionCheckStamp.load());
|
||||
|
||||
final VersionCheckStamp stamp = VersionCheckStamp(
|
||||
lastKnownRemoteVersion: _testClock.ago(days: 10),
|
||||
lastTimeVersionWasChecked: _testClock.ago(days: 9),
|
||||
lastTimeWarningWasPrinted: _testClock.ago(days: 8),
|
||||
lastKnownRemoteVersion: _testClock.ago(const Duration(days: 10)),
|
||||
lastTimeVersionWasChecked: _testClock.ago(const Duration(days: 9)),
|
||||
lastTimeWarningWasPrinted: _testClock.ago(const Duration(days: 8)),
|
||||
);
|
||||
await stamp.store(
|
||||
newKnownRemoteVersion: _testClock.ago(days: 1),
|
||||
newTimeVersionWasChecked: _testClock.ago(days: 2),
|
||||
newKnownRemoteVersion: _testClock.ago(const Duration(days: 1)),
|
||||
newTimeVersionWasChecked: _testClock.ago(const Duration(days: 2)),
|
||||
newTimeWarningWasPrinted: _testClock.now(),
|
||||
);
|
||||
|
||||
final VersionCheckStamp storedStamp = await VersionCheckStamp.load();
|
||||
expect(storedStamp.lastKnownRemoteVersion, _testClock.ago(days: 1));
|
||||
expect(storedStamp.lastTimeVersionWasChecked, _testClock.ago(days: 2));
|
||||
expect(storedStamp.lastKnownRemoteVersion, _testClock.ago(const Duration(days: 1)));
|
||||
expect(storedStamp.lastTimeVersionWasChecked, _testClock.ago(const Duration(days: 2)));
|
||||
expect(storedStamp.lastTimeWarningWasPrinted, _testClock.now());
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => FlutterVersion(_testClock),
|
||||
|
||||
Reference in New Issue
Block a user