Skip to content

Commit

Permalink
Skip GA Client Tear Down Process if NOT Necessary (#10340)
Browse files Browse the repository at this point in the history
* Skip Analytics Client Tear down if it is not needed

* Add unit test covering analytics tear down

* Touch test naming
  • Loading branch information
QilongTang committed Feb 10, 2020
1 parent 9cec99e commit 5bc2f39
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
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 @@ -471,20 +471,27 @@ public void PreferenceSetting_BackgroundPreview_1_0API()

[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

0 comments on commit 5bc2f39

Please sign in to comment.