Unverified Commit 6c4475e7 authored by auto-submit[bot]'s avatar auto-submit[bot] Committed by GitHub

Reverts "Migration for the `sendTiming` events for `package:unified_analytics`" (#139278)

Reverts flutter/flutter#138896
Initiated by: CaseyHillers
This change reverts the following previous change:
Original Description:
Related to tracker issue:
- https://github.com/flutter/flutter/issues/128251

<img width="278" alt="image" src="https://github.com/flutter/flutter/assets/42216813/cee7b9be-48d6-48e5-8c39-de28d0a1f0de">

The image above shows all of the instances where we have `sendTiming`. All of the call sites have been updated to use the new `Event.timing` event from `package:unified_analytics`.
parent c8101b56
......@@ -490,13 +490,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
status.stop();
}
final Duration elapsedDuration = sw.elapsed;
_usage.sendTiming('build', 'gradle', elapsedDuration);
_analytics.send(Event.timing(
workflow: 'build',
variableName: 'gradle',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
_usage.sendTiming('build', 'gradle', sw.elapsed);
if (exitCode != 0) {
if (detectedGradleError == null) {
......@@ -763,13 +757,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
} finally {
status.stop();
}
final Duration elapsedDuration = sw.elapsed;
_usage.sendTiming('build', 'gradle-aar', elapsedDuration);
_analytics.send(Event.timing(
workflow: 'build',
variableName: 'gradle-aar',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
_usage.sendTiming('build', 'gradle-aar', sw.elapsed);
if (result.exitCode != 0) {
_logger.printStatus(result.stdout, wrap: false);
......@@ -804,13 +792,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
project: project,
);
final Duration elapsedDuration = sw.elapsed;
_usage.sendTiming('print', 'android build variants', elapsedDuration);
_analytics.send(Event.timing(
workflow: 'print',
variableName: 'android build variants',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
_usage.sendTiming('print', 'android build variants', sw.elapsed);
if (result.exitCode != 0) {
_logger.printStatus(result.stdout, wrap: false);
......@@ -846,13 +828,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
options: <String>['-q', '-PoutputPath=$outputPath'],
project: project,
);
final Duration elapsedDuration = sw.elapsed;
_usage.sendTiming('outputs', 'app link settings', elapsedDuration);
_analytics.send(Event.timing(
workflow: 'outputs',
variableName: 'app link settings',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
_usage.sendTiming('outputs', 'app link settings', sw.elapsed);
if (result.exitCode != 0) {
_logger.printStatus(result.stdout, wrap: false);
......
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'package:args/args.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../base/common.dart';
import '../base/os.dart';
......@@ -299,7 +298,7 @@ class PackagesGetCommand extends FlutterCommand {
processManager: globals.processManager,
platform: globals.platform,
usage: globals.flutterUsage,
analytics: analytics,
analytics: globals.analytics,
projectDir: rootProject.directory,
generateDartPluginRegistry: true,
);
......@@ -320,7 +319,7 @@ class PackagesGetCommand extends FlutterCommand {
processManager: globals.processManager,
platform: globals.platform,
usage: globals.flutterUsage,
analytics: analytics,
analytics: globals.analytics,
projectDir: rootProject.directory,
generateDartPluginRegistry: true,
);
......@@ -355,24 +354,10 @@ class PackagesGetCommand extends FlutterCommand {
command: name,
touchesPackageConfig: !(isHelp || dryRun),
);
final Duration elapsedDuration = timer.elapsed;
globals.flutterUsage.sendTiming('pub', 'get', elapsedDuration, label: 'success');
analytics.send(Event.timing(
workflow: 'pub',
variableName: 'get',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
label: 'success'
));
globals.flutterUsage.sendTiming('pub', 'get', timer.elapsed, label: 'success');
// Not limiting to catching Exception because the exception is rethrown.
} catch (_) { // ignore: avoid_catches_without_on_clauses
final Duration elapsedDuration = timer.elapsed;
globals.flutterUsage.sendTiming('pub', 'get', elapsedDuration, label: 'failure');
analytics.send(Event.timing(
workflow: 'pub',
variableName: 'get',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
label: 'failure'
));
globals.flutterUsage.sendTiming('pub', 'get', timer.elapsed, label: 'failure');
rethrow;
}
......
......@@ -419,13 +419,7 @@ Future<XcodeBuildResult> buildXcodeProject({
'Xcode ${xcodeBuildActionToString(buildAction)} done.'.padRight(kDefaultStatusPadding + 1)
+ getElapsedAsSeconds(sw.elapsed).padLeft(5),
);
final Duration elapsedDuration = sw.elapsed;
globals.flutterUsage.sendTiming(xcodeBuildActionToString(buildAction), 'xcode-ios', elapsedDuration);
globals.analytics.send(Event.timing(
workflow: xcodeBuildActionToString(buildAction),
variableName: 'xcode-ios',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
globals.flutterUsage.sendTiming(xcodeBuildActionToString(buildAction), 'xcode-ios', Duration(milliseconds: sw.elapsedMilliseconds));
if (tempDir.existsSync()) {
// Display additional warning and error message from xcresult bundle.
......
......@@ -452,11 +452,6 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
// Don't track restart times for dart2js builds or web-server devices.
if (debuggingOptions.buildInfo.isDebug && deviceIsDebuggable) {
_usage.sendTiming('hot', 'web-incremental-restart', elapsed);
_analytics.send(Event.timing(
workflow: 'hot',
variableName: 'web-incremental-restart',
elapsedMilliseconds: elapsed.inMilliseconds,
));
final String sdkName = await device!.device!.sdkNameAndVersion;
HotEvent(
'restart',
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:unified_analytics/unified_analytics.dart';
import '../artifacts.dart';
import '../base/analyze_size.dart';
import '../base/common.dart';
......@@ -157,13 +155,7 @@ Future<void> _runCmake(String buildModeName, Directory sourceDir, Directory buil
if (result != 0) {
throwToolExit('Unable to generate build files');
}
final Duration elapsedDuration = sw.elapsed;
globals.flutterUsage.sendTiming('build', 'cmake-linux', elapsedDuration);
globals.analytics.send(Event.timing(
workflow: 'build',
variableName: 'cmake-linux',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
globals.flutterUsage.sendTiming('build', 'cmake-linux', Duration(milliseconds: sw.elapsedMilliseconds));
}
Future<void> _runBuild(Directory buildDir) async {
......@@ -193,11 +185,5 @@ Future<void> _runBuild(Directory buildDir) async {
if (result != 0) {
throwToolExit('Build process failed');
}
final Duration elapsedDuration = sw.elapsed;
globals.flutterUsage.sendTiming('build', 'linux-ninja', elapsedDuration);
globals.analytics.send(Event.timing(
workflow: 'build',
variableName: 'linux-ninja',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
globals.flutterUsage.sendTiming('build', 'linux-ninja', Duration(milliseconds: sw.elapsedMilliseconds));
}
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:unified_analytics/unified_analytics.dart';
import '../base/analyze_size.dart';
import '../base/common.dart';
import '../base/file_system.dart';
......@@ -162,13 +160,7 @@ Future<void> buildMacOS({
throwToolExit('Build process failed');
}
await _writeCodeSizeAnalysis(buildInfo, sizeAnalyzer);
final Duration elapsedDuration = sw.elapsed;
globals.flutterUsage.sendTiming('build', 'xcode-macos', elapsedDuration);
globals.analytics.send(Event.timing(
workflow: 'build',
variableName: 'xcode-macos',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
globals.flutterUsage.sendTiming('build', 'xcode-macos', Duration(milliseconds: sw.elapsedMilliseconds));
}
/// Performs a size analysis of the AOT snapshot and writes to an analysis file, if configured.
......
......@@ -713,13 +713,7 @@ class HotRunner extends ResidentRunner {
restartTimer.elapsed.inMilliseconds);
// Send timing analytics.
final Duration elapsedDuration = restartTimer.elapsed;
globals.flutterUsage.sendTiming('hot', 'restart', elapsedDuration);
_analytics.send(Event.timing(
workflow: 'hot',
variableName: 'restart',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
globals.flutterUsage.sendTiming('hot', 'restart', restartTimer.elapsed);
// Toggle the main dill name after successfully uploading.
_swap =! _swap;
......@@ -1118,11 +1112,6 @@ class HotRunner extends ResidentRunner {
// Only report timings if we reloaded a single view without any errors.
if ((reassembleResult.reassembleViews.length == 1) && !reassembleResult.failedReassemble && shouldReportReloadTime) {
globals.flutterUsage.sendTiming('hot', 'reload', reloadDuration);
_analytics.send(Event.timing(
workflow: 'hot',
variableName: 'reload',
elapsedMilliseconds: reloadDuration.inMilliseconds,
));
}
return OperationResult(
reassembleResult.failedReassemble ? 1 : OperationResult.ok.code,
......
......@@ -1634,26 +1634,16 @@ abstract class FlutterCommand extends Command<void> {
final String label = labels
.where((String? label) => label != null && !_isBlank(label))
.join('-');
// If the command provides its own end time, use it. Otherwise report
// the duration of the entire execution.
final Duration elapsedDuration = (commandResult.endTimeOverride ?? endTime).difference(startTime);
globals.flutterUsage.sendTiming(
'flutter',
name,
elapsedDuration,
// If the command provides its own end time, use it. Otherwise report
// the duration of the entire execution.
(commandResult.endTimeOverride ?? endTime).difference(startTime),
// Report in the form of `success-[parameter1-parameter2]`, all of which
// can be null if the command doesn't provide a FlutterCommandResult.
label: label == '' ? null : label,
);
analytics.send(Event.timing(
workflow: 'flutter',
variableName: name,
elapsedMilliseconds: elapsedDuration.inMilliseconds,
// Report in the form of `success-[parameter1-parameter2]`, all of which
// can be null if the command doesn't provide a FlutterCommandResult.
label: label == '' ? null : label,
));
}
/// Perform validation then call [runCommand] to execute the command.
......@@ -1717,7 +1707,7 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
processManager: globals.processManager,
platform: globals.platform,
usage: globals.flutterUsage,
analytics: analytics,
analytics: globals.analytics,
projectDir: project.directory,
generateDartPluginRegistry: true,
);
......
......@@ -6,7 +6,6 @@ import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:completion/completion.dart';
import 'package:file/file.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../artifacts.dart';
import '../base/common.dart';
......@@ -330,11 +329,6 @@ class FlutterCommandRunner extends CommandRunner<void> {
if ((topLevelResults[FlutterGlobalOptions.kVersionFlag] as bool?) ?? false) {
globals.flutterUsage.sendCommand(FlutterGlobalOptions.kVersionFlag);
globals.analytics.send(Event.flutterCommandResult(
commandPath: 'version',
result: 'success',
commandHasTerminal: globals.stdio.hasTerminal,
));
final FlutterVersion version = globals.flutterVersion.fetchTagsAndGetVersion(
clock: globals.systemClock,
);
......
......@@ -150,17 +150,11 @@ class WebBuilder {
settings: buildSettingsString,
));
final Duration elapsedDuration = sw.elapsed;
_flutterUsage.sendTiming(
'build',
compilerConfig.isWasm ? 'dart2wasm' : 'dart2js',
elapsedDuration,
Duration(milliseconds: sw.elapsedMilliseconds),
);
_analytics.send(Event.timing(
workflow: 'build',
variableName: compilerConfig.isWasm ? 'dart2wasm' : 'dart2js',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
}
}
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:unified_analytics/unified_analytics.dart';
import '../artifacts.dart';
import '../base/analyze_size.dart';
import '../base/common.dart';
......@@ -204,13 +202,7 @@ Future<void> _runCmakeGeneration({
if (result != 0) {
throwToolExit('Unable to generate build files');
}
final Duration elapsedDuration = sw.elapsed;
globals.flutterUsage.sendTiming('build', 'windows-cmake-generation', elapsedDuration);
globals.analytics.send(Event.timing(
workflow: 'build',
variableName: 'windows-cmake-generation',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
globals.flutterUsage.sendTiming('build', 'windows-cmake-generation', Duration(milliseconds: sw.elapsedMilliseconds));
}
Future<void> _runBuild(
......@@ -261,13 +253,7 @@ Future<void> _runBuild(
if (result != 0) {
throwToolExit('Build process failed.');
}
final Duration elapsedDuration = sw.elapsed;
globals.flutterUsage.sendTiming('build', 'windows-cmake-build', elapsedDuration);
globals.analytics.send(Event.timing(
workflow: 'build',
variableName: 'windows-cmake-build',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
globals.flutterUsage.sendTiming('build', 'windows-cmake-build', Duration(milliseconds: sw.elapsedMilliseconds));
}
/// Writes the generated CMake file with the configuration for the given build.
......
......@@ -48,7 +48,7 @@ dependencies:
http_multi_server: 3.2.1
convert: 3.1.1
async: 2.11.0
unified_analytics: 5.6.0
unified_analytics: 5.5.0
cli_config: 0.1.2
graphs: 2.3.1
......@@ -69,7 +69,7 @@ dependencies:
analyzer: 6.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
built_collection: 5.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
built_value: 8.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
built_value: 8.7.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
clock: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
csslib: 1.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dap: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
......@@ -91,7 +91,7 @@ dependencies:
source_map_stack_trace: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
source_maps: 0.10.12 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
sse: 4.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
sse: 4.1.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
string_scanner: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
sync_http: 0.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
......@@ -115,4 +115,4 @@ dartdoc:
# Exclude this package from the hosted API docs.
nodoc: true
# PUBSPEC CHECKSUM: b1a1
# PUBSPEC CHECKSUM: e59e
......@@ -19,7 +19,6 @@ import 'package:flutter_tools/src/ios/plist_parser.dart';
import 'package:flutter_tools/src/ios/xcodeproj.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:test/fake.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../../general.shard/ios/xcresult_test_data.dart';
import '../../src/common.dart';
......@@ -79,7 +78,6 @@ void main() {
late FakePlistUtils plistUtils;
late BufferLogger logger;
late Artifacts artifacts;
late FakeAnalytics fakeAnalytics;
setUpAll(() {
Cache.disableLocking();
......@@ -96,10 +94,6 @@ void main() {
processManager: fakeProcessManager,
);
plistUtils = FakePlistUtils();
fakeAnalytics = getInitializedFakeAnalyticsInstance(
fs: fileSystem,
fakeFlutterVersion: FakeFlutterVersion(),
);
});
// Sets up the minimal mock project files necessary to look like a Flutter project.
......@@ -800,9 +794,6 @@ void main() {
const TestUsageEvent('code-size-analysis', 'ios'),
));
expect(fakeProcessManager, hasNoRemainingExpectations);
expect(fakeAnalytics.sentEvents, contains(
Event.codeSizeAnalysis(platform: 'ios')
));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
Logger: () => logger,
......@@ -810,7 +801,6 @@ void main() {
Platform: () => macosPlatform,
FileSystemUtils: () => FileSystemUtils(fileSystem: fileSystem, platform: macosPlatform),
Usage: () => usage,
Analytics: () => fakeAnalytics,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
});
......
......@@ -21,7 +21,6 @@ import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:test/fake.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../../src/common.dart';
import '../../src/context.dart';
......@@ -49,13 +48,12 @@ void main() {
Cache.disableLocking();
});
late MemoryFileSystem fileSystem;
late FileSystem fileSystem;
late FakeProcessManager processManager;
late ProcessUtils processUtils;
late Logger logger;
late TestUsage usage;
late Artifacts artifacts;
late FakeAnalytics fakeAnalytics;
setUp(() {
fileSystem = MemoryFileSystem.test();
......@@ -68,10 +66,6 @@ void main() {
logger: logger,
processManager: processManager,
);
fakeAnalytics = getInitializedFakeAnalyticsInstance(
fs: fileSystem,
fakeFlutterVersion: FakeFlutterVersion(),
);
});
// Creates the mock files necessary to look like a Flutter project.
......@@ -215,30 +209,12 @@ void main() {
const <String>['build', 'linux', '--no-pub']
);
expect(fileSystem.file('linux/flutter/ephemeral/generated_config.cmake'), exists);
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'build',
variableName: 'cmake-linux',
),
true,
);
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'build',
variableName: 'linux-ninja',
),
true,
);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
Analytics: () => fakeAnalytics,
});
testUsingContext('Handles missing cmake', () async {
......@@ -725,9 +701,6 @@ set(BINARY_NAME "fizz_bar")
expect(usage.events, contains(
const TestUsageEvent('code-size-analysis', 'linux'),
));
expect(fakeAnalytics.sentEvents, contains(
Event.codeSizeAnalysis(platform: 'linux')
));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
......@@ -735,7 +708,6 @@ set(BINARY_NAME "fizz_bar")
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
Usage: () => usage,
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
Analytics: () => fakeAnalytics,
});
testUsingContext('Linux on ARM64 build --release passes, and check if the LinuxBuildDirectory for arm64 can be referenced correctly by using analytics', () async {
......@@ -782,9 +754,6 @@ set(BINARY_NAME "fizz_bar")
expect(usage.events, contains(
const TestUsageEvent('code-size-analysis', 'linux'),
));
expect(fakeAnalytics.sentEvents, contains(
Event.codeSizeAnalysis(platform: 'linux')
));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
......@@ -792,7 +761,6 @@ set(BINARY_NAME "fizz_bar")
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
Usage: () => usage,
OperatingSystemUtils: () => CustomFakeOperatingSystemUtils(hostPlatform: HostPlatform.linux_arm64),
Analytics: () => fakeAnalytics,
});
}
......
......@@ -20,7 +20,6 @@ import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/ios/xcodeproj.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../../src/common.dart';
import '../../src/context.dart';
......@@ -71,7 +70,6 @@ void main() {
late BufferLogger logger;
late XcodeProjectInterpreter xcodeProjectInterpreter;
late Artifacts artifacts;
late FakeAnalytics fakeAnalytics;
setUpAll(() {
Cache.disableLocking();
......@@ -88,10 +86,6 @@ void main() {
processManager: fakeProcessManager,
);
xcodeProjectInterpreter = FakeXcodeProjectInterpreter();
fakeAnalytics = getInitializedFakeAnalyticsInstance(
fs: fileSystem,
fakeFlutterVersion: FakeFlutterVersion(),
);
});
// Sets up the minimal mock project files necessary to look like a Flutter project.
......@@ -200,21 +194,11 @@ STDERR STUFF
await createTestCommandRunner(command).run(
const <String>['build', 'macos', '--no-pub']
);
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'build',
variableName: 'xcode-macos',
),
true,
);
}, overrides: <Type, Generator>{
Platform: () => macosPlatform,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
Analytics: () => fakeAnalytics,
});
testUsingContext('macOS build fails on non-macOS platform', () async {
......@@ -610,7 +594,6 @@ STDERR STUFF
expect(usage.events, contains(
const TestUsageEvent('code-size-analysis', 'macos'),
));
expect(fakeAnalytics.sentEvents, contains(Event.codeSizeAnalysis(platform: 'macos')));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
......@@ -635,6 +618,5 @@ STDERR STUFF
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
FileSystemUtils: () => FileSystemUtils(fileSystem: fileSystem, platform: macosPlatform),
Usage: () => usage,
Analytics: () => fakeAnalytics,
});
}
......@@ -13,7 +13,6 @@ import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:flutter_tools/src/windows/visual_studio.dart';
import 'package:test/fake.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../../src/common.dart';
import '../../src/context.dart';
......@@ -46,7 +45,6 @@ void main() {
late FileSystem fileSystem;
late ProcessManager processManager;
late TestUsage usage;
late FakeAnalytics fakeAnalytics;
setUpAll(() {
Cache.disableLocking();
......@@ -57,10 +55,6 @@ void main() {
fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows);
Cache.flutterRoot = flutterRoot;
usage = TestUsage();
fakeAnalytics = getInitializedFakeAnalyticsInstance(
fs: fileSystem,
fakeFlutterVersion: FakeFlutterVersion(),
);
});
// Creates the mock files necessary to look like a Flutter project.
......@@ -215,46 +209,6 @@ void main() {
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
});
testUsingContext('Windows build sends timing events', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[
cmakeGenerationCommand(),
buildCommand('Release'),
]);
await createTestCommandRunner(command).run(
const <String>['windows', '--no-pub']
);
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'build',
variableName: 'windows-cmake-generation',
),
true,
);
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'build',
variableName: 'windows-cmake-build',
),
true,
);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Platform: () => windowsPlatform,
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
Analytics: () => fakeAnalytics,
});
testUsingContext('Windows build extracts errors from stdout', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
......@@ -975,9 +929,6 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
expect(usage.events, contains(
const TestUsageEvent('code-size-analysis', 'windows'),
));
expect(fakeAnalytics.sentEvents, contains(
Event.codeSizeAnalysis(platform: 'windows')
));
}, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
FileSystem: () => fileSystem,
......@@ -985,7 +936,6 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
Platform: () => windowsPlatform,
FileSystemUtils: () => FileSystemUtils(fileSystem: fileSystem, platform: windowsPlatform),
Usage: () => usage,
Analytics: () => fakeAnalytics,
});
// Confirms that running for Windows in a directory with a
......
......@@ -5,7 +5,6 @@
import 'dart:convert';
import 'package:args/command_runner.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/android/android_studio.dart';
import 'package:flutter_tools/src/android/java.dart';
......@@ -18,11 +17,10 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:test/fake.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart' as fakes;
import '../../src/fakes.dart';
import '../../src/test_flutter_command_runner.dart';
void main() {
......@@ -31,29 +29,23 @@ void main() {
late FakeAndroidSdk fakeAndroidSdk;
late FakeFlutterVersion fakeFlutterVersion;
late TestUsage testUsage;
late FakeAnalytics fakeAnalytics;
setUpAll(() {
Cache.disableLocking();
});
setUp(() {
fakeJava = fakes.FakeJava();
fakeJava = FakeJava();
fakeAndroidStudio = FakeAndroidStudio();
fakeAndroidSdk = FakeAndroidSdk();
fakeFlutterVersion = FakeFlutterVersion();
testUsage = TestUsage();
fakeAnalytics = getInitializedFakeAnalyticsInstance(
fs: MemoryFileSystem.test(),
fakeFlutterVersion: fakes.FakeFlutterVersion(),
);
});
void verifyNoAnalytics() {
expect(testUsage.commands, isEmpty);
expect(testUsage.events, isEmpty);
expect(testUsage.timings, isEmpty);
expect(fakeAnalytics.sentEvents, isEmpty);
}
group('config', () {
......@@ -271,7 +263,6 @@ void main() {
]));
expect(testUsage.commands, isEmpty);
expect(testUsage.timings, isEmpty);
expect(fakeAnalytics.sentEvents, isEmpty);
}, overrides: <Type, Generator>{
Usage: () => testUsage,
});
......@@ -294,7 +285,6 @@ void main() {
]));
expect(testUsage.commands, isEmpty);
expect(testUsage.timings, isEmpty);
expect(fakeAnalytics.sentEvents, isEmpty);
}, overrides: <Type, Generator>{
Usage: () => testUsage,
});
......
......@@ -23,7 +23,6 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/packages.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:unified_analytics/unified_analytics.dart';
import '../../src/common.dart';
import '../../src/context.dart';
......@@ -41,14 +40,9 @@ void main() {
Cache.disableLocking();
group('packages get/upgrade', () {
late Directory tempDir;
late FakeAnalytics fakeAnalytics;
setUp(() {
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
fakeAnalytics = getInitializedFakeAnalyticsInstance(
fs: MemoryFileSystem.test(),
fakeFlutterVersion: FakeFlutterVersion(),
);
});
tearDown(() {
......@@ -226,15 +220,6 @@ void main() {
expectDependenciesResolved(projectPath);
expectZeroPluginsInjected(projectPath);
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'pub',
variableName: 'get',
label: 'success',
),
true,
);
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Pub: () => Pub.test(
......@@ -246,7 +231,6 @@ void main() {
platform: globals.platform,
stdio: mockStdio,
),
Analytics: () => fakeAnalytics,
});
testUsingContext('get --offline fetches packages', () async {
......
......@@ -145,21 +145,11 @@ void main() {
expect(
fakeAnalytics.sentEvents,
containsAll(<Event>[
unorderedEquals(<Event>[
Event.flutterBuildInfo(label: 'app-not-using-android-x', buildType: 'gradle'),
Event.flutterBuildInfo(label: 'gradle-random-event-label-failure', buildType: 'gradle'),
]),
);
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'build',
variableName: 'gradle',
),
true,
);
}, overrides: <Type, Generator>{
AndroidStudio: () => FakeAndroidStudio(),
});
......@@ -338,7 +328,7 @@ void main() {
));
expect(testUsage.events, hasLength(4));
expect(fakeAnalytics.sentEvents, hasLength(7));
expect(fakeAnalytics.sentEvents, hasLength(4));
expect(fakeAnalytics.sentEvents, contains(
Event.flutterBuildInfo(
label: 'gradle-random-event-label-failure',
......@@ -441,7 +431,7 @@ void main() {
));
expect(testUsage.events, hasLength(2));
expect(fakeAnalytics.sentEvents, hasLength(3));
expect(fakeAnalytics.sentEvents, hasLength(2));
expect(fakeAnalytics.sentEvents, contains(
Event.flutterBuildInfo(
label: 'gradle-random-event-label-failure',
......@@ -888,18 +878,8 @@ BuildVariant: paidProfile
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
);
expect(actual, <String>['freeDebug', 'paidDebug', 'freeRelease', 'paidRelease', 'freeProfile', 'paidProfile']);
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'print',
variableName: 'android build variants',
),
true,
);
}, overrides: <Type, Generator>{
AndroidStudio: () => FakeAndroidStudio(),
Analytics: () => fakeAnalytics,
});
testUsingContext('getBuildOptions returns empty list if gradle returns error', () async {
......@@ -961,20 +941,10 @@ Gradle Crashed
'freeDebug',
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
);
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'outputs',
variableName: 'app link settings',
),
true,
);
}, overrides: <Type, Generator>{
AndroidStudio: () => FakeAndroidStudio(),
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Analytics: () => fakeAnalytics,
});
testUsingContext("doesn't indicate how to consume an AAR when printHowToConsumeAar is false", () async {
......@@ -1040,18 +1010,8 @@ Gradle Crashed
isFalse,
);
expect(processManager, hasNoRemainingExpectations);
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'build',
variableName: 'gradle-aar',
),
true,
);
}, overrides: <Type, Generator>{
AndroidStudio: () => FakeAndroidStudio(),
Analytics: () => fakeAnalytics,
});
testUsingContext('Verbose mode for AARs includes Gradle stacktrace and sets debug log level', () async {
......
......@@ -21,8 +21,7 @@ import 'package:flutter_tools/src/resident_devtools_handler.dart';
import 'package:flutter_tools/src/resident_runner.dart';
import 'package:flutter_tools/src/run_hot.dart';
import 'package:flutter_tools/src/vmservice.dart';
import 'package:native_assets_cli/native_assets_cli.dart'
hide BuildMode, Target;
import 'package:native_assets_cli/native_assets_cli.dart' hide BuildMode, Target;
import 'package:native_assets_cli/native_assets_cli.dart' as native_assets_cli;
import 'package:package_config/package_config.dart';
import 'package:test/fake.dart';
......@@ -37,116 +36,84 @@ import 'fake_native_assets_build_runner.dart';
void main() {
group('validateReloadReport', () {
testUsingContext('invalid', () async {
expect(
HotRunner.validateReloadReport(
vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{},
})),
false);
expect(
HotRunner.validateReloadReport(
vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <Map<String, dynamic>>[],
},
})),
false);
expect(
HotRunner.validateReloadReport(
vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <String, dynamic>{
'message': 'error',
},
},
})),
false);
expect(
HotRunner.validateReloadReport(
vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <Map<String, dynamic>>[],
},
})),
false);
expect(
HotRunner.validateReloadReport(
vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <Map<String, dynamic>>[
<String, dynamic>{'message': false},
],
},
})),
false);
expect(
HotRunner.validateReloadReport(
vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <Map<String, dynamic>>[
<String, dynamic>{
'message': <String>['error']
},
],
},
})),
false);
expect(
HotRunner.validateReloadReport(
vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <Map<String, dynamic>>[
<String, dynamic>{'message': 'error'},
<String, dynamic>{
'message': <String>['error']
},
],
},
})),
false);
expect(
HotRunner.validateReloadReport(
vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <Map<String, dynamic>>[
<String, dynamic>{'message': 'error'},
],
},
})),
false);
expect(
HotRunner.validateReloadReport(
vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': true,
})),
true);
expect(HotRunner.validateReloadReport(vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{},
})), false);
expect(HotRunner.validateReloadReport(vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <Map<String, dynamic>>[
],
},
})), false);
expect(HotRunner.validateReloadReport(vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <String, dynamic>{
'message': 'error',
},
},
})), false);
expect(HotRunner.validateReloadReport(vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <Map<String, dynamic>>[],
},
})), false);
expect(HotRunner.validateReloadReport(vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <Map<String, dynamic>>[
<String, dynamic>{'message': false},
],
},
})), false);
expect(HotRunner.validateReloadReport(vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <Map<String, dynamic>>[
<String, dynamic>{'message': <String>['error']},
],
},
})), false);
expect(HotRunner.validateReloadReport(vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <Map<String, dynamic>>[
<String, dynamic>{'message': 'error'},
<String, dynamic>{'message': <String>['error']},
],
},
})), false);
expect(HotRunner.validateReloadReport(vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': false,
'details': <String, dynamic>{
'notices': <Map<String, dynamic>>[
<String, dynamic>{'message': 'error'},
],
},
})), false);
expect(HotRunner.validateReloadReport(vm_service.ReloadReport.parse(<String, dynamic>{
'type': 'ReloadReport',
'success': true,
})), true);
});
testWithoutContext(
'ReasonForCancelling toString has a hint for specific errors', () {
testWithoutContext('ReasonForCancelling toString has a hint for specific errors', () {
final ReasonForCancelling reasonForCancelling = ReasonForCancelling(
message: 'Const class cannot remove fields',
);
expect(reasonForCancelling.toString(),
contains('Try performing a hot restart instead.'));
expect(reasonForCancelling.toString(), contains('Try performing a hot restart instead.'));
});
});
......@@ -180,10 +147,7 @@ void main() {
..writeAsStringSync('\n');
final FakeDevice device = FakeDevice();
final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(device,
generator: residentCompiler,
buildInfo: BuildInfo.debug,
developmentShaderCompiler: const FakeShaderCompiler())
FlutterDevice(device, generator: residentCompiler, buildInfo: BuildInfo.debug, developmentShaderCompiler: const FakeShaderCompiler())
..devFS = FakeDevFs(),
];
final OperationResult result = await HotRunner(
......@@ -192,6 +156,7 @@ void main() {
target: 'main.dart',
devtoolsHandler: createNoOpHandler,
analytics: fakeAnalytics,
).restart(fullRestart: true);
expect(result.isOk, false);
expect(result.message, 'setupHotRestart failed');
......@@ -223,13 +188,12 @@ void main() {
Map<FlutterDevice?, List<FlutterView>> viewCache,
void Function(String message)? onSlow,
String reloadMessage,
) async =>
ReassembleResult(
<FlutterView?, FlutterVmService?>{null: null},
false,
true,
),
analytics: fakeAnalytics,
) async => ReassembleResult(
<FlutterView?, FlutterVmService?>{null: null},
false,
true,
),
analytics: fakeAnalytics,
).restart();
expect(result.isOk, false);
expect(result.message, 'setupHotReload failed');
......@@ -256,10 +220,7 @@ void main() {
..writeAsStringSync('\n');
final FakeDevice device = FakeDevice();
final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(device,
generator: residentCompiler,
buildInfo: BuildInfo.debug,
developmentShaderCompiler: const FakeShaderCompiler()),
FlutterDevice(device, generator: residentCompiler, buildInfo: BuildInfo.debug, developmentShaderCompiler: const FakeShaderCompiler()),
];
await HotRunner(
devices,
......@@ -282,10 +243,7 @@ void main() {
..writeAsStringSync('\n');
final FakeDevice device = FakeDevice();
final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(device,
generator: residentCompiler,
buildInfo: BuildInfo.debug,
developmentShaderCompiler: const FakeShaderCompiler()),
FlutterDevice(device, generator: residentCompiler, buildInfo: BuildInfo.debug, developmentShaderCompiler: const FakeShaderCompiler()),
];
await HotRunner(
devices,
......@@ -310,36 +268,30 @@ void main() {
successfulHotRestartSetup: true,
);
});
testUsingContext(
'correctly tracks time spent for analytics for hot restart',
() async {
testUsingContext('correctly tracks time spent for analytics for hot restart', () async {
final FakeDevice device = FakeDevice();
final FakeFlutterDevice fakeFlutterDevice = FakeFlutterDevice(device);
final List<FlutterDevice> devices = <FlutterDevice>[
fakeFlutterDevice,
];
fakeFlutterDevice.updateDevFSReportCallback =
() async => UpdateFSReport(
success: true,
invalidatedSourcesCount: 2,
syncedBytes: 4,
scannedSourcesCount: 8,
compileDuration: const Duration(seconds: 16),
transferDuration: const Duration(seconds: 32),
);
fakeFlutterDevice.updateDevFSReportCallback = () async => UpdateFSReport(
success: true,
invalidatedSourcesCount: 2,
syncedBytes: 4,
scannedSourcesCount: 8,
compileDuration: const Duration(seconds: 16),
transferDuration: const Duration(seconds: 32),
);
final FakeStopwatchFactory fakeStopwatchFactory = FakeStopwatchFactory(
stopwatches: <String, Stopwatch>{
'fullRestartHelper': FakeStopwatch()
..elapsed = const Duration(seconds: 64),
'updateDevFS': FakeStopwatch()
..elapsed = const Duration(seconds: 128),
'fullRestartHelper': FakeStopwatch()..elapsed = const Duration(seconds: 64),
'updateDevFS': FakeStopwatch()..elapsed = const Duration(seconds: 128),
},
);
(fakeFlutterDevice.devFS! as FakeDevFs).baseUri =
Uri.parse('file:///base_uri');
(fakeFlutterDevice.devFS! as FakeDevFs).baseUri = Uri.parse('file:///base_uri');
final OperationResult result = await HotRunner(
devices,
......@@ -352,45 +304,37 @@ void main() {
expect(result.isOk, true);
expect(testUsage.events, <TestUsageEvent>[
const TestUsageEvent('hot', 'restart',
parameters: CustomDimensions(
hotEventTargetPlatform: 'flutter-tester',
hotEventSdkName: 'Tester',
hotEventEmulator: false,
hotEventFullRestart: true,
hotEventOverallTimeInMs: 64000,
hotEventSyncedBytes: 4,
hotEventInvalidatedSourcesCount: 2,
hotEventTransferTimeInMs: 32000,
hotEventCompileTimeInMs: 16000,
hotEventFindInvalidatedTimeInMs: 128000,
hotEventScannedSourcesCount: 8,
)),
const TestUsageEvent('hot', 'restart', parameters: CustomDimensions(
hotEventTargetPlatform: 'flutter-tester',
hotEventSdkName: 'Tester',
hotEventEmulator: false,
hotEventFullRestart: true,
hotEventOverallTimeInMs: 64000,
hotEventSyncedBytes: 4,
hotEventInvalidatedSourcesCount: 2,
hotEventTransferTimeInMs: 32000,
hotEventCompileTimeInMs: 16000,
hotEventFindInvalidatedTimeInMs: 128000,
hotEventScannedSourcesCount: 8,
)),
]);
expect(
fakeAnalytics.sentEvents,
contains(Event.hotRunnerInfo(
label: 'restart',
targetPlatform: 'flutter-tester',
sdkName: 'Tester',
emulator: false,
fullRestart: true,
syncedBytes: 4,
invalidatedSourcesCount: 2,
transferTimeInMs: 32000,
overallTimeInMs: 64000,
compileTimeInMs: 16000,
findInvalidatedTimeInMs: 128000,
scannedSourcesCount: 8)));
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'hot',
variableName: 'restart',
),
true,
);
expect(fakeAnalytics.sentEvents, contains(
Event.hotRunnerInfo(
label: 'restart',
targetPlatform: 'flutter-tester',
sdkName: 'Tester',
emulator: false,
fullRestart: true,
syncedBytes: 4,
invalidatedSourcesCount: 2,
transferTimeInMs: 32000,
overallTimeInMs: 64000,
compileTimeInMs: 16000,
findInvalidatedTimeInMs: 128000,
scannedSourcesCount: 8
)
));
expect(testingConfig.updateDevFSCompleteCalled, true);
}, overrides: <Type, Generator>{
HotRunnerConfig: () => testingConfig,
......@@ -409,39 +353,32 @@ void main() {
successfulHotReloadSetup: true,
);
});
testUsingContext(
'correctly tracks time spent for analytics for hot reload', () async {
testUsingContext('correctly tracks time spent for analytics for hot reload', () async {
final FakeDevice device = FakeDevice();
final FakeFlutterDevice fakeFlutterDevice = FakeFlutterDevice(device);
final List<FlutterDevice> devices = <FlutterDevice>[
fakeFlutterDevice,
];
fakeFlutterDevice.updateDevFSReportCallback =
() async => UpdateFSReport(
success: true,
invalidatedSourcesCount: 6,
syncedBytes: 8,
scannedSourcesCount: 16,
compileDuration: const Duration(seconds: 16),
transferDuration: const Duration(seconds: 32),
);
fakeFlutterDevice.updateDevFSReportCallback = () async => UpdateFSReport(
success: true,
invalidatedSourcesCount: 6,
syncedBytes: 8,
scannedSourcesCount: 16,
compileDuration: const Duration(seconds: 16),
transferDuration: const Duration(seconds: 32),
);
final FakeStopwatchFactory fakeStopwatchFactory = FakeStopwatchFactory(
stopwatches: <String, Stopwatch>{
'updateDevFS': FakeStopwatch()
..elapsed = const Duration(seconds: 64),
'reloadSources:reload': FakeStopwatch()
..elapsed = const Duration(seconds: 128),
'reloadSources:reassemble': FakeStopwatch()
..elapsed = const Duration(seconds: 256),
'reloadSources:vm': FakeStopwatch()
..elapsed = const Duration(seconds: 512),
'updateDevFS': FakeStopwatch()..elapsed = const Duration(seconds: 64),
'reloadSources:reload': FakeStopwatch()..elapsed = const Duration(seconds: 128),
'reloadSources:reassemble': FakeStopwatch()..elapsed = const Duration(seconds: 256),
'reloadSources:vm': FakeStopwatch()..elapsed = const Duration(seconds: 512),
},
);
(fakeFlutterDevice.devFS! as FakeDevFs).baseUri =
Uri.parse('file:///base_uri');
(fakeFlutterDevice.devFS! as FakeDevFs).baseUri = Uri.parse('file:///base_uri');
final OperationResult result = await HotRunner(
devices,
......@@ -473,68 +410,57 @@ void main() {
Map<FlutterDevice?, List<FlutterView>> viewCache,
void Function(String message)? onSlow,
String reloadMessage,
) async =>
ReassembleResult(
<FlutterView?, FlutterVmService?>{null: null},
false,
true,
),
) async => ReassembleResult(
<FlutterView?, FlutterVmService?>{null: null},
false,
true,
),
).restart();
expect(result.isOk, true);
expect(testUsage.events, <TestUsageEvent>[
const TestUsageEvent('hot', 'reload',
parameters: CustomDimensions(
hotEventFinalLibraryCount: 2,
hotEventSyncedLibraryCount: 3,
hotEventSyncedClassesCount: 4,
hotEventSyncedProceduresCount: 5,
hotEventSyncedBytes: 8,
hotEventInvalidatedSourcesCount: 6,
hotEventTransferTimeInMs: 32000,
hotEventOverallTimeInMs: 128000,
hotEventTargetPlatform: 'flutter-tester',
hotEventSdkName: 'Tester',
hotEventEmulator: false,
hotEventFullRestart: false,
hotEventCompileTimeInMs: 16000,
hotEventFindInvalidatedTimeInMs: 64000,
hotEventScannedSourcesCount: 16,
hotEventReassembleTimeInMs: 256000,
hotEventReloadVMTimeInMs: 512000,
)),
const TestUsageEvent('hot', 'reload', parameters: CustomDimensions(
hotEventFinalLibraryCount: 2,
hotEventSyncedLibraryCount: 3,
hotEventSyncedClassesCount: 4,
hotEventSyncedProceduresCount: 5,
hotEventSyncedBytes: 8,
hotEventInvalidatedSourcesCount: 6,
hotEventTransferTimeInMs: 32000,
hotEventOverallTimeInMs: 128000,
hotEventTargetPlatform: 'flutter-tester',
hotEventSdkName: 'Tester',
hotEventEmulator: false,
hotEventFullRestart: false,
hotEventCompileTimeInMs: 16000,
hotEventFindInvalidatedTimeInMs: 64000,
hotEventScannedSourcesCount: 16,
hotEventReassembleTimeInMs: 256000,
hotEventReloadVMTimeInMs: 512000,
)),
]);
expect(
fakeAnalytics.sentEvents,
contains(
Event.hotRunnerInfo(
label: 'reload',
targetPlatform: 'flutter-tester',
sdkName: 'Tester',
emulator: false,
fullRestart: false,
finalLibraryCount: 2,
syncedLibraryCount: 3,
syncedClassesCount: 4,
syncedProceduresCount: 5,
syncedBytes: 8,
invalidatedSourcesCount: 6,
transferTimeInMs: 32000,
overallTimeInMs: 128000,
compileTimeInMs: 16000,
findInvalidatedTimeInMs: 64000,
scannedSourcesCount: 16,
reassembleTimeInMs: 256000,
reloadVMTimeInMs: 512000),
));
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'hot',
variableName: 'reload',
expect(fakeAnalytics.sentEvents, contains(
Event.hotRunnerInfo(
label: 'reload',
targetPlatform: 'flutter-tester',
sdkName: 'Tester',
emulator: false,
fullRestart: false,
finalLibraryCount: 2,
syncedLibraryCount: 3,
syncedClassesCount: 4,
syncedProceduresCount: 5,
syncedBytes: 8,
invalidatedSourcesCount: 6,
transferTimeInMs: 32000,
overallTimeInMs: 128000,
compileTimeInMs: 16000,
findInvalidatedTimeInMs: 64000,
scannedSourcesCount: 16,
reassembleTimeInMs: 256000,
reloadVMTimeInMs: 512000
),
true,
);
));
expect(testingConfig.updateDevFSCompleteCalled, true);
}, overrides: <Type, Generator>{
HotRunnerConfig: () => testingConfig,
......@@ -559,8 +485,7 @@ void main() {
final List<FlutterDevice> devices = <FlutterDevice>[
fakeFlutterDevice,
];
fakeFlutterDevice.updateDevFSReportCallback =
() async => throw Exception('updateDevFS failed');
fakeFlutterDevice.updateDevFSReportCallback = () async => throw Exception('updateDevFS failed');
final HotRunner runner = HotRunner(
devices,
......@@ -570,10 +495,7 @@ void main() {
analytics: fakeAnalytics,
);
await expectLater(
runner.restart(fullRestart: true),
throwsA(isA<Exception>().having((Exception e) => e.toString(),
'message', 'Exception: updateDevFS failed')));
await expectLater(runner.restart(fullRestart: true), throwsA(isA<Exception>().having((Exception e) => e.toString(), 'message', 'Exception: updateDevFS failed')));
expect(testingConfig.updateDevFSCompleteCalled, true);
}, overrides: <Type, Generator>{
HotRunnerConfig: () => testingConfig,
......@@ -598,8 +520,7 @@ void main() {
final List<FlutterDevice> devices = <FlutterDevice>[
fakeFlutterDevice,
];
fakeFlutterDevice.updateDevFSReportCallback =
() async => throw Exception('updateDevFS failed');
fakeFlutterDevice.updateDevFSReportCallback = () async => throw Exception('updateDevFS failed');
final HotRunner runner = HotRunner(
devices,
......@@ -609,10 +530,7 @@ void main() {
analytics: fakeAnalytics,
);
await expectLater(
runner.restart(),
throwsA(isA<Exception>().having((Exception e) => e.toString(),
'message', 'Exception: updateDevFS failed')));
await expectLater(runner.restart(), throwsA(isA<Exception>().having((Exception e) => e.toString(), 'message', 'Exception: updateDevFS failed')));
expect(testingConfig.updateDevFSCompleteCalled, true);
}, overrides: <Type, Generator>{
HotRunnerConfig: () => testingConfig,
......@@ -637,9 +555,8 @@ void main() {
);
});
testUsingContext(
'Exits with code 2 when HttpException is thrown '
'during VM service connection', () async {
testUsingContext('Exits with code 2 when HttpException is thrown '
'during VM service connection', () async {
fileSystem.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
......@@ -650,14 +567,12 @@ void main() {
TestFlutterDevice(
device: device,
generator: residentCompiler,
exception: const HttpException(
'Connection closed before full header was received, '
exception: const HttpException('Connection closed before full header was received, '
'uri = http://127.0.0.1:63394/5ZmLv8A59xY=/ws'),
),
];
final int exitCode = await HotRunner(
devices,
final int exitCode = await HotRunner(devices,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
analytics: fakeAnalytics,
......@@ -695,8 +610,7 @@ void main() {
flutterDevice2,
];
await HotRunner(
devices,
await HotRunner(devices,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
analytics: fakeAnalytics,
......@@ -733,19 +647,17 @@ void main() {
];
fakeFlutterDevice.updateDevFSReportCallback = () async => UpdateFSReport(
success: true,
invalidatedSourcesCount: 6,
syncedBytes: 8,
scannedSourcesCount: 16,
compileDuration: const Duration(seconds: 16),
transferDuration: const Duration(seconds: 32),
);
success: true,
invalidatedSourcesCount: 6,
syncedBytes: 8,
scannedSourcesCount: 16,
compileDuration: const Duration(seconds: 16),
transferDuration: const Duration(seconds: 32),
);
(fakeFlutterDevice.devFS! as FakeDevFs).baseUri =
Uri.parse('file:///base_uri');
(fakeFlutterDevice.devFS! as FakeDevFs).baseUri = Uri.parse('file:///base_uri');
final FakeNativeAssetsBuildRunner buildRunner =
FakeNativeAssetsBuildRunner(
final FakeNativeAssetsBuildRunner buildRunner = FakeNativeAssetsBuildRunner(
packagesWithNativeAssetsResult: <Package>[
Package('bar', fileSystem.currentDirectory.uri),
],
......@@ -783,32 +695,28 @@ void main() {
FileSystem: () => fileSystem,
Platform: () => FakePlatform(),
ProcessManager: () => FakeProcessManager.empty(),
FeatureFlags: () =>
TestFeatureFlags(isNativeAssetsEnabled: true, isMacOSEnabled: true),
FeatureFlags: () => TestFeatureFlags(isNativeAssetsEnabled: true, isMacOSEnabled: true),
});
testUsingContext('native assets run unsupported', () async {
final FakeDevice device =
FakeDevice(targetPlatform: TargetPlatform.android_arm64);
final FakeDevice device = FakeDevice(targetPlatform: TargetPlatform.android_arm64);
final FakeFlutterDevice fakeFlutterDevice = FakeFlutterDevice(device);
final List<FlutterDevice> devices = <FlutterDevice>[
fakeFlutterDevice,
];
fakeFlutterDevice.updateDevFSReportCallback = () async => UpdateFSReport(
success: true,
invalidatedSourcesCount: 6,
syncedBytes: 8,
scannedSourcesCount: 16,
compileDuration: const Duration(seconds: 16),
transferDuration: const Duration(seconds: 32),
);
success: true,
invalidatedSourcesCount: 6,
syncedBytes: 8,
scannedSourcesCount: 16,
compileDuration: const Duration(seconds: 16),
transferDuration: const Duration(seconds: 32),
);
(fakeFlutterDevice.devFS! as FakeDevFs).baseUri =
Uri.parse('file:///base_uri');
(fakeFlutterDevice.devFS! as FakeDevFs).baseUri = Uri.parse('file:///base_uri');
final FakeNativeAssetsBuildRunner buildRunner =
FakeNativeAssetsBuildRunner(
final FakeNativeAssetsBuildRunner buildRunner = FakeNativeAssetsBuildRunner(
packagesWithNativeAssetsResult: <Package>[
Package('bar', fileSystem.currentDirectory.uri),
],
......@@ -833,27 +741,28 @@ void main() {
analytics: fakeAnalytics,
);
expect(
() => hotRunner.run(),
throwsToolExit(
message: 'Package(s) bar require the native assets feature. '
'This feature has not yet been implemented for `TargetPlatform.android_arm64`. '
'For more info see https://github.com/flutter/flutter/issues/129757.',
));
() => hotRunner.run(),
throwsToolExit( message:
'Package(s) bar require the native assets feature. '
'This feature has not yet been implemented for `TargetPlatform.android_arm64`. '
'For more info see https://github.com/flutter/flutter/issues/129757.',
)
);
}, overrides: <Type, Generator>{
HotRunnerConfig: () => testingConfig,
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(),
ProcessManager: () => FakeProcessManager.empty(),
FeatureFlags: () =>
TestFeatureFlags(isNativeAssetsEnabled: true, isMacOSEnabled: true),
FeatureFlags: () => TestFeatureFlags(isNativeAssetsEnabled: true, isMacOSEnabled: true),
});
});
}
class FakeDevFs extends Fake implements DevFS {
@override
Future<void> destroy() async {}
Future<void> destroy() async { }
@override
List<Uri> sources = <Uri>[];
......@@ -868,10 +777,10 @@ class FakeDevFs extends Fake implements DevFS {
Set<String> assetPathsToEvict = <String>{};
@override
Set<String> shaderPathsToEvict = <String>{};
Set<String> shaderPathsToEvict= <String>{};
@override
Set<String> scenePathsToEvict = <String>{};
Set<String> scenePathsToEvict= <String>{};
@override
Uri? baseUri;
......@@ -964,8 +873,7 @@ class FakeFlutterDevice extends Fake implements FlutterDevice {
required String dillOutputPath,
required List<Uri> invalidatedFiles,
required PackageConfig packageConfig,
}) =>
updateDevFSReportCallback();
}) => updateDevFSReportCallback();
@override
TargetPlatform? get targetPlatform => device._targetPlatform;
......@@ -976,10 +884,7 @@ class TestFlutterDevice extends FlutterDevice {
required Device device,
required this.exception,
required ResidentCompiler generator,
}) : super(device,
buildInfo: BuildInfo.debug,
generator: generator,
developmentShaderCompiler: const FakeShaderCompiler());
}) : super(device, buildInfo: BuildInfo.debug, generator: generator, developmentShaderCompiler: const FakeShaderCompiler());
/// The exception to throw when the connect method is called.
final Exception exception;
......@@ -1005,8 +910,7 @@ class TestFlutterDevice extends FlutterDevice {
}
class TestHotRunnerConfig extends HotRunnerConfig {
TestHotRunnerConfig(
{this.successfulHotRestartSetup, this.successfulHotReloadSetup});
TestHotRunnerConfig({this.successfulHotRestartSetup, this.successfulHotReloadSetup});
bool? successfulHotRestartSetup;
bool? successfulHotReloadSetup;
bool shutdownHookCalled = false;
......@@ -1014,15 +918,13 @@ class TestHotRunnerConfig extends HotRunnerConfig {
@override
Future<bool?> setupHotRestart() async {
assert(successfulHotRestartSetup != null,
'setupHotRestart is not expected to be called in this test.');
assert(successfulHotRestartSetup != null, 'setupHotRestart is not expected to be called in this test.');
return successfulHotRestartSetup;
}
@override
Future<bool?> setupHotReload() async {
assert(successfulHotReloadSetup != null,
'setupHotReload is not expected to be called in this test.');
assert(successfulHotReloadSetup != null, 'setupHotReload is not expected to be called in this test.');
return successfulHotReloadSetup;
}
......@@ -1047,9 +949,7 @@ class FakeFlutterVmService extends Fake implements FlutterVmService {
vm_service.VmService get service => FakeVmService();
@override
Future<List<FlutterView>> getFlutterViews(
{bool returnEarly = false,
Duration delay = const Duration(milliseconds: 50)}) async {
Future<List<FlutterView>> getFlutterViews({bool returnEarly = false, Duration delay = const Duration(milliseconds: 50)}) async {
return <FlutterView>[];
}
}
......@@ -1071,7 +971,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler {
void configureCompiler(
TargetPlatform? platform, {
required ImpellerStatus impellerStatus,
}) {}
}) { }
@override
Future<DevFSContent> recompileShader(DevFSContent inputShader) {
......
......@@ -27,7 +27,6 @@ import 'package:flutter_tools/src/ios/xcodeproj.dart';
import 'package:flutter_tools/src/macos/xcode.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:test/fake.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../../src/common.dart';
import '../../src/context.dart' hide FakeXcodeProjectInterpreter;
......@@ -89,13 +88,12 @@ void main() {
});
group('IOSDevice.startApp succeeds in release mode', () {
late MemoryFileSystem fileSystem;
late FileSystem fileSystem;
late FakeProcessManager processManager;
late BufferLogger logger;
late Xcode xcode;
late FakeXcodeProjectInterpreter fakeXcodeProjectInterpreter;
late XcodeProjectInfo projectInfo;
late FakeAnalytics fakeAnalytics;
setUp(() {
logger = BufferLogger.test();
......@@ -112,10 +110,6 @@ void main() {
fileSystem.file('foo/.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
fakeAnalytics = getInitializedFakeAnalyticsInstance(
fs: fileSystem,
fakeFlutterVersion: FakeFlutterVersion(),
);
});
testUsingContext('missing TARGET_BUILD_DIR', () async {
......@@ -141,14 +135,6 @@ void main() {
expect(launchResult.started, false);
expect(logger.errorText, contains('Xcode build is missing expected TARGET_BUILD_DIR build setting'));
expect(processManager, hasNoRemainingExpectations);
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'build',
variableName: 'xcode-ios',
),
true,
);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
FileSystem: () => fileSystem,
......@@ -159,7 +145,6 @@ void main() {
'DEVELOPMENT_TEAM': '3333CCCC33',
}, projectInfo: projectInfo),
Xcode: () => xcode,
Analytics: () => fakeAnalytics,
});
testUsingContext('missing project info', () async {
......
......@@ -41,7 +41,6 @@ import 'package:native_assets_cli/native_assets_cli.dart'
import 'package:native_assets_cli/native_assets_cli.dart' as native_assets_cli;
import 'package:package_config/package_config.dart';
import 'package:test/fake.dart';
import 'package:unified_analytics/src/enums.dart';
import 'package:unified_analytics/unified_analytics.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
......@@ -960,11 +959,8 @@ void main() {
expect(event.parameters?.hotEventTargetPlatform, getNameForTargetPlatform(TargetPlatform.android_arm));
expect(fakeVmServiceHost?.hasRemainingExpectations, false);
// Parse out the event of interest since we may have timing events with
// the new analytics package
final List<Event> newEventList = fakeAnalytics.sentEvents.where((Event e) => e.eventName == DashEvent.hotRunnerInfo).toList();
expect(newEventList, hasLength(1));
final Event newEvent = newEventList.first;
final Event newEvent = fakeAnalytics.sentEvents.first;
expect(newEvent.eventName.label, 'hot_runner_info');
expect(newEvent.eventData['label'], 'restart');
expect(newEvent.eventData['targetPlatform'], getNameForTargetPlatform(TargetPlatform.android_arm));
......
......@@ -693,13 +693,6 @@ void main() {
expect(testUsage.timings, const <TestTimingEvent>[
TestTimingEvent('hot', 'web-incremental-restart', Duration.zero),
]);
expect(fakeAnalytics.sentEvents, contains(
Event.timing(
workflow: 'hot',
variableName: 'web-incremental-restart',
elapsedMilliseconds: 0,
),
));
}, overrides: <Type, Generator>{
Usage: () => testUsage,
Analytics: () => fakeAnalytics,
......@@ -786,13 +779,6 @@ void main() {
expect(testUsage.timings, const <TestTimingEvent>[
TestTimingEvent('hot', 'web-incremental-restart', Duration.zero),
]);
expect(fakeAnalytics.sentEvents, contains(
Event.timing(
workflow: 'hot',
variableName: 'web-incremental-restart',
elapsedMilliseconds: 0,
),
));
}, overrides: <Type, Generator>{
Usage: () => testUsage,
Analytics: () => fakeAnalytics,
......
......@@ -10,13 +10,10 @@ import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/test_flutter_command_runner.dart';
......@@ -29,8 +26,6 @@ void main() {
group('FlutterCommandRunner', () {
late MemoryFileSystem fileSystem;
late Platform platform;
late TestUsage testUsage;
late FakeAnalytics fakeAnalytics;
setUpAll(() {
Cache.disableLocking();
......@@ -41,11 +36,6 @@ void main() {
fileSystem.directory(_kFlutterRoot).createSync(recursive: true);
fileSystem.directory(_kProjectRoot).createSync(recursive: true);
fileSystem.currentDirectory = _kProjectRoot;
testUsage = TestUsage();
fakeAnalytics = getInitializedFakeAnalyticsInstance(
fs: fileSystem,
fakeFlutterVersion: FakeFlutterVersion(),
);
platform = FakePlatform(
environment: <String, String>{
......@@ -154,25 +144,14 @@ void main() {
final FakeFlutterVersion version = globals.flutterVersion as FakeFlutterVersion;
await runner.run(<String>['--version']);
expect(version.didFetchTagsAndUpdate, true);
expect(testUsage.commands, contains(
const TestUsageCommand('version'),
));
expect(fakeAnalytics.sentEvents, contains(
Event.flutterCommandResult(
commandPath: 'version',
result: 'success',
commandHasTerminal: false,
),
));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => platform,
FlutterVersion: () => FakeFlutterVersion(),
OutputPreferences: () => OutputPreferences.test(),
Usage: () => testUsage,
Analytics: () => fakeAnalytics,
});
testUsingContext("Doesn't crash on invalid .packages file", () async {
......
......@@ -27,7 +27,6 @@ import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:test/fake.dart';
import 'package:unified_analytics/src/enums.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../../src/common.dart';
......@@ -230,14 +229,14 @@ void main() {
value: 10,
),
]);
expect(fakeAnalytics.sentEvents, contains(
expect(fakeAnalytics.sentEvents, <Event>[
Event.flutterCommandResult(
commandPath: 'dummy',
result: 'success',
maxRss: 10,
commandHasTerminal: false,
),
));
]);
});
testUsingCommandContext('reports command that results in warning', () async {
......@@ -264,14 +263,14 @@ void main() {
value: 10,
),
]);
expect(fakeAnalytics.sentEvents, contains(
expect(fakeAnalytics.sentEvents, <Event>[
Event.flutterCommandResult(
commandPath: 'dummy',
result: 'warning',
maxRss: 10,
commandHasTerminal: false,
),
));
]);
});
testUsingCommandContext('reports command that results in error', () async {
......@@ -300,14 +299,14 @@ void main() {
value: 10,
),
]);
expect(fakeAnalytics.sentEvents, contains(
expect(fakeAnalytics.sentEvents, <Event>[
Event.flutterCommandResult(
commandPath: 'dummy',
result: 'fail',
maxRss: 10,
commandHasTerminal: false,
),
));
]);
});
test('FlutterCommandResult.success()', () async {
......@@ -414,14 +413,14 @@ void main() {
value: 10,
),
]);
expect(fakeAnalytics.sentEvents, contains(
expect(fakeAnalytics.sentEvents, <Event>[
Event.flutterCommandResult(
commandPath: 'dummy',
result: 'killed',
maxRss: 10,
commandHasTerminal: false,
),
));
]);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
......@@ -486,14 +485,6 @@ void main() {
Duration(milliseconds: 1000),
label: 'fail',
)));
expect(fakeAnalytics.sentEvents, contains(
Event.timing(
workflow: 'flutter',
variableName: 'dummy',
elapsedMilliseconds: 1000,
label: 'fail',
)
));
});
testUsingCommandContext('no timing report without usagePath', () async {
......@@ -505,19 +496,6 @@ void main() {
await flutterCommand.run();
expect(usage.timings, isEmpty);
// Iterate through and count all the [Event.timing] instances
int timingEventCounts = 0;
for (final Event e in fakeAnalytics.sentEvents) {
if (e.eventName == DashEvent.timing) {
timingEventCounts += 1;
}
}
expect(
timingEventCounts,
0,
reason: 'There should not be any timing events sent, there may '
'be other non-timing events',
);
});
testUsingCommandContext('report additional FlutterCommandResult data', () async {
......@@ -543,14 +521,6 @@ void main() {
Duration(milliseconds: 500),
label: 'success-blah1-blah2-blah3',
)));
expect(fakeAnalytics.sentEvents, contains(
Event.timing(
workflow: 'flutter',
variableName: 'dummy',
elapsedMilliseconds: 500,
label: 'success-blah1-blah2-blah3',
),
));
});
testUsingCommandContext('report failed execution timing too', () async {
......@@ -575,14 +545,6 @@ void main() {
label: 'fail',
),
));
expect(fakeAnalytics.sentEvents, contains(
Event.timing(
workflow: 'flutter',
variableName: 'dummy',
elapsedMilliseconds: 1000,
label: 'fail',
),
));
});
testUsingContext('reports null safety analytics when reportNullSafety is true', () async {
......
......@@ -111,7 +111,7 @@ void main() {
expect(
fakeAnalytics.sentEvents,
containsAll(<Event>[
unorderedEquals(<Event>[
Event.flutterBuildInfo(
label: 'web-compile',
buildType: 'web',
......@@ -124,14 +124,6 @@ void main() {
final TestTimingEvent timingEvent = testUsage.timings.single;
expect(timingEvent.category, 'build');
expect(timingEvent.variableName, 'dart2wasm');
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'build',
variableName: 'dart2wasm',
),
true,
);
});
testUsingContext('WebBuilder throws tool exit on failure', () async {
......@@ -167,6 +159,5 @@ void main() {
expect(logger.errorText, contains('Target hello failed: FormatException: illegal character in input string'));
expect(testUsage.timings, isEmpty);
expect(fakeAnalytics.sentEvents, isEmpty);
});
}
......@@ -5,7 +5,6 @@
import 'dart:async';
import 'package:args/command_runner.dart';
import 'package:collection/collection.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/context.dart';
......@@ -348,38 +347,3 @@ FakeAnalytics getInitializedFakeAnalyticsInstance({
clientIde: clientIde,
);
}
/// Returns "true" if the timing event searched for exists in [sentEvents].
///
/// This utility function allows us to check for an instance of
/// [Event.timing] within a [FakeAnalytics] instance. Normally, we can
/// use the equality operator for [Event] to check if the event exists, but
/// we are unable to do so for the timing event because the elapsed time
/// is variable so we cannot predict what that value will be in tests.
///
/// This function allows us to check for the other keys that have
/// string values by removing the `elapsedMilliseconds` from the
/// [Event.eventData] map and checking for a match.
bool analyticsTimingEventExists({
required List<Event> sentEvents,
required String workflow,
required String variableName,
String? label,
}) {
final Map<String, String> lookup = <String, String>{
'workflow': workflow,
'variableName': variableName,
if (label != null) 'label': label,
};
for (final Event e in sentEvents) {
final Map<String, Object?> eventData = e.eventData;
eventData.remove('elapsedMilliseconds');
if (const DeepCollectionEquality().equals(lookup, eventData)) {
return true;
}
}
return false;
}
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