Ensure analytics are sent before disabling (#62094)

This commit is contained in:
Zachary Anderson 2020-07-24 15:31:18 -07:00 committed by GitHub
parent 7877d46c8b
commit 523afbe58b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -113,9 +113,15 @@ class ConfigCommand extends FlutterCommand {
if (argResults.wasParsed('analytics')) { if (argResults.wasParsed('analytics')) {
final bool value = boolArg('analytics'); final bool value = boolArg('analytics');
// We send the analytics event *before* toggling the flag intentionally // The tool sends the analytics event *before* toggling the flag
// to be sure that opt-out events are sent correctly. // intentionally to be sure that opt-out events are sent correctly.
AnalyticsConfigEvent(enabled: value).send(); 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.flutterUsage.enabled = value;
globals.printStatus('Analytics reporting ${value ? 'enabled' : 'disabled'}.'); globals.printStatus('Analytics reporting ${value ? 'enabled' : 'disabled'}.');
} }

View File

@ -233,6 +233,9 @@ void main() {
expect(mockUsage.enabled, false); 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 // Verify that we only send the analytics disable event, and no other
// info. // info.
verifyNever(mockUsage.sendCommand( verifyNever(mockUsage.sendCommand(