Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Analytics] Skip GA Client Tear Down Process if NOT Necessary #10340

Merged
merged 3 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/DynamoCore/Logging/DynamoAnalyticsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ public void Dispose()
else
StabilityCookie.WriteCleanShutdown();

Service.ShutDown();
//Unregister the GATrackerFactory only after shutdown is recorded.
//Unregister is required, so that the host app can re-start Analytics service.
Service.Instance.Unregister(GATrackerFactory.Name);
// If the Analytics Client was initialized, shut it down.
// Otherwise skip this step because it would cause an exception.
if (Service.IsInitialized)
{
Service.ShutDown();
// Unregister the GATrackerFactory only after shutdown is recorded.
// Unregister is required, so that the host app can re-start Analytics service.
Service.Instance.Unregister(GATrackerFactory.Name);
}

if (null != heartbeat)
Heartbeat.DestroyInstance();
Expand Down
13 changes: 10 additions & 3 deletions test/DynamoCoreWpfTests/CoreUITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,20 +502,27 @@ public void PreferenceSetting_RenderPrecision()

[Test]
[Category("DynamoUI")]
public void PreferenceSetting_Analytics()
public void PreferenceSetting_AgreeAnalyticSharing()
{
// Test deserialization of analytics setting
// Test loading old settings file without agreement
var filePath = Path.Combine(GetTestDirectory(ExecutingDirectory), @"settings\DynamoSettings-firstrun.xml");
var resultSetting = PreferenceSettings.Load(filePath);
Assert.AreEqual(false, resultSetting.IsAnalyticsReportingApproved);
Assert.AreEqual(false, resultSetting.IsUsageReportingApproved);
Assert.DoesNotThrow(() => Dynamo.Logging.AnalyticsService.ShutDown());
}

[Test]
[Category("DynamoUI")]
public void PreferenceSetting_NotAgreeAnalyticsSharing()
{
// Test loading old settings file without render precision attribute
filePath = Path.Combine(GetTestDirectory(ExecutingDirectory), @"settings\DynamoSettings-AnalyticsTurnedOn.xml");
resultSetting = PreferenceSettings.Load(filePath);
var filePath = Path.Combine(GetTestDirectory(ExecutingDirectory), @"settings\DynamoSettings-AnalyticsTurnedOn.xml");
var resultSetting = PreferenceSettings.Load(filePath);
Assert.AreEqual(true, resultSetting.IsAnalyticsReportingApproved);
Assert.AreEqual(true, resultSetting.IsUsageReportingApproved);
Assert.DoesNotThrow(() => Dynamo.Logging.AnalyticsService.ShutDown());
}

#region PreferenceSettings
Expand Down