Record flutter run success/fail, build mode, platform, start time in analytics (#9597)
FlutterCommand.runCommand subclasses can optionally return a FlutterCommandResult which is used to append additional analytics. Fix flutter run timing report and add a bunch of dimensional data
This commit is contained in:
@@ -23,6 +23,7 @@ import 'package:flutter_tools/src/usage.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
import 'package:quiver/time.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'common.dart';
|
||||
@@ -55,7 +56,8 @@ void _defaultInitializeContext(AppContext testContext) {
|
||||
})
|
||||
..putIfAbsent(SimControl, () => new MockSimControl())
|
||||
..putIfAbsent(Usage, () => new MockUsage())
|
||||
..putIfAbsent(FlutterVersion, () => new MockFlutterVersion());
|
||||
..putIfAbsent(FlutterVersion, () => new MockFlutterVersion())
|
||||
..putIfAbsent(Clock, () => const Clock());
|
||||
}
|
||||
|
||||
void testUsingContext(String description, dynamic testMethod(), {
|
||||
@@ -220,10 +222,7 @@ class MockUsage implements Usage {
|
||||
void sendEvent(String category, String parameter) { }
|
||||
|
||||
@override
|
||||
void sendTiming(String category, String variableName, Duration duration) { }
|
||||
|
||||
@override
|
||||
UsageTimer startTimer(String event) => new _MockUsageTimer(event);
|
||||
void sendTiming(String category, String variableName, Duration duration, { String label }) { }
|
||||
|
||||
@override
|
||||
void sendException(dynamic exception, StackTrace trace) { }
|
||||
@@ -238,14 +237,6 @@ class MockUsage implements Usage {
|
||||
void printWelcome() { }
|
||||
}
|
||||
|
||||
class _MockUsageTimer implements UsageTimer {
|
||||
_MockUsageTimer(this.event);
|
||||
|
||||
@override
|
||||
final String event;
|
||||
|
||||
@override
|
||||
void finish() { }
|
||||
}
|
||||
|
||||
class MockFlutterVersion extends Mock implements FlutterVersion {}
|
||||
|
||||
class MockClock extends Mock implements Clock {}
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/usage.dart';
|
||||
import 'package:flutter_tools/src/runner/flutter_command.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:quiver/time.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../context.dart';
|
||||
@@ -16,9 +18,18 @@ void main() {
|
||||
group('Flutter Command', () {
|
||||
|
||||
MockCache cache;
|
||||
MockClock clock;
|
||||
MockUsage usage;
|
||||
List<int> mockTimes;
|
||||
|
||||
setUp(() {
|
||||
cache = new MockCache();
|
||||
clock = new MockClock();
|
||||
usage = new MockUsage();
|
||||
when(usage.isFirstRun).thenReturn(false);
|
||||
when(clock.now()).thenAnswer(
|
||||
(Invocation _) => new DateTime.fromMillisecondsSinceEpoch(mockTimes.removeAt(0))
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('honors shouldUpdateCache false', () async {
|
||||
@@ -38,12 +49,84 @@ void main() {
|
||||
overrides: <Type, Generator>{
|
||||
Cache: () => cache,
|
||||
});
|
||||
|
||||
testUsingContext('report execution timing by default', () async {
|
||||
// Crash if called a third time which is unexpected.
|
||||
mockTimes = <int>[1000, 2000];
|
||||
|
||||
final DummyFlutterCommand flutterCommand = new DummyFlutterCommand();
|
||||
await flutterCommand.run();
|
||||
verify(clock.now()).called(2);
|
||||
|
||||
expect(
|
||||
verify(usage.sendTiming(captureAny, captureAny, captureAny, label: captureAny)).captured,
|
||||
<dynamic>['flutter', 'dummy', const Duration(milliseconds: 1000), null]
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Clock: () => clock,
|
||||
Usage: () => usage,
|
||||
});
|
||||
|
||||
testUsingContext('no timing report without usagePath', () async {
|
||||
// Crash if called a third time which is unexpected.
|
||||
mockTimes = <int>[1000, 2000];
|
||||
|
||||
final DummyFlutterCommand flutterCommand =
|
||||
new DummyFlutterCommand(noUsagePath: true);
|
||||
await flutterCommand.run();
|
||||
verify(clock.now()).called(2);
|
||||
verifyNever(usage.sendTiming(captureAny, captureAny, captureAny, label: captureAny));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Clock: () => clock,
|
||||
Usage: () => usage,
|
||||
});
|
||||
|
||||
testUsingContext('report additional FlutterCommandResult data', () async {
|
||||
// Crash if called a third time which is unexpected.
|
||||
mockTimes = <int>[1000, 2000];
|
||||
|
||||
final FlutterCommandResult commandResult = new FlutterCommandResult(
|
||||
ExitStatus.fail,
|
||||
// nulls should be cleaned up.
|
||||
analyticsParameters: <String> ['blah1', 'blah2', null, 'blah3'],
|
||||
endTimeOverride: new DateTime.fromMillisecondsSinceEpoch(1500)
|
||||
);
|
||||
|
||||
final DummyFlutterCommand flutterCommand =
|
||||
new DummyFlutterCommand(flutterCommandResult: commandResult);
|
||||
await flutterCommand.run();
|
||||
verify(clock.now()).called(2);
|
||||
expect(
|
||||
verify(usage.sendTiming(captureAny, captureAny, captureAny, label: captureAny)).captured,
|
||||
<dynamic>[
|
||||
'flutter',
|
||||
'dummy',
|
||||
const Duration(milliseconds: 500), // FlutterCommandResult's end time used instead.
|
||||
'fail-blah1-blah2-blah3',
|
||||
],
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Clock: () => clock,
|
||||
Usage: () => usage,
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
class DummyFlutterCommand extends FlutterCommand {
|
||||
|
||||
DummyFlutterCommand({this.shouldUpdateCache});
|
||||
DummyFlutterCommand({
|
||||
this.shouldUpdateCache : false,
|
||||
this.noUsagePath : false,
|
||||
this.flutterCommandResult
|
||||
});
|
||||
|
||||
final bool noUsagePath;
|
||||
final FlutterCommandResult flutterCommandResult;
|
||||
|
||||
@override
|
||||
final bool shouldUpdateCache;
|
||||
@@ -51,13 +134,18 @@ class DummyFlutterCommand extends FlutterCommand {
|
||||
@override
|
||||
String get description => 'does nothing';
|
||||
|
||||
@override
|
||||
Future<String> get usagePath => noUsagePath ? null : super.usagePath;
|
||||
|
||||
@override
|
||||
String get name => 'dummy';
|
||||
|
||||
@override
|
||||
Future<Null> runCommand() async {
|
||||
// does nothing.
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
return flutterCommandResult;
|
||||
}
|
||||
}
|
||||
|
||||
class MockCache extends Mock implements Cache {}
|
||||
class MockCache extends Mock implements Cache {}
|
||||
|
||||
class MockUsage extends Mock implements Usage {}
|
||||
Reference in New Issue
Block a user