Unverified Commit 523afbe5 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

Ensure analytics are sent before disabling (#62094)

parent 7877d46c
......@@ -113,9 +113,15 @@ class ConfigCommand extends FlutterCommand {
if (argResults.wasParsed('analytics')) {
final bool value = boolArg('analytics');
// We send the analytics event *before* toggling the flag intentionally
// to be sure that opt-out events are sent correctly.
// The tool sends the analytics event *before* toggling the flag
// intentionally to be sure that opt-out events are sent correctly.
AnalyticsConfigEvent(enabled: value).send();
if (!value) {
// Normally, the tool waits for the analytics to all send before the
// tool exits, but only when analytics are enabled. When reporting that
// analytics have been disable, the wait must be done here instead.
await globals.flutterUsage.ensureAnalyticsSent();
}
globals.flutterUsage.enabled = value;
globals.printStatus('Analytics reporting ${value ? 'enabled' : 'disabled'}.');
}
......
......@@ -233,6 +233,9 @@ void main() {
expect(mockUsage.enabled, false);
// Verify that we flushed the analytics queue.
verify(mockUsage.ensureAnalyticsSent());
// Verify that we only send the analytics disable event, and no other
// info.
verifyNever(mockUsage.sendCommand(
......
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