Skip to content

Commit 664a2a1

Browse files
authored
DYN-6728 feature flags should be controlled by no network mode when creating a dynamo model directly. (#14975)
* check network mode * align disable and networkmode * add small tests * remove todo * review comments * another test
1 parent fc9f5f2 commit 664a2a1

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

src/DynamoCore/Models/DynamoModel.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,14 @@ protected DynamoModel(IStartConfiguration config)
702702
// Do nothing for now
703703
}
704704
}
705+
//If network traffic is disabled, analytics should also be disabled - this is already done in
706+
//our other entry points(CLI,Sandbox etc) - but
707+
//not all integrators will use those entry points, some may just create a DynamoModel directly.
708+
Analytics.DisableAnalytics = NoNetworkMode || Analytics.DisableAnalytics;
705709

706710
// If user skipped analytics from assembly config, do not try to launch the analytics client
707711
// or the feature flags client for web traffic reason.
708-
if (!IsServiceMode && !areAnalyticsDisabledFromConfig && !Analytics.DisableAnalytics)
712+
if (!IsServiceMode && !areAnalyticsDisabledFromConfig && !Analytics.DisableAnalytics && !NoNetworkMode)
709713
{
710714
HandleAnalytics();
711715

test/DynamoCoreTests/Logging/AnalyticsServiceTest.cs

+67
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,72 @@ public void DisableAnalytics()
8080
dynamoCLI?.Kill();
8181
}
8282
}
83+
84+
[Test]
85+
[Platform("win")]//nunit attribute for now only run on windows until we know it's useful on linux.
86+
public void DisableAnalyticsViaNoNetWorkMode()
87+
{
88+
var versions = new List<Version>(){
89+
90+
new Version(230, 0,0),
91+
};
92+
93+
var directory = new DirectoryInfo(Assembly.GetExecutingAssembly().Location);
94+
var testDirectory = Path.Combine(directory.Parent.Parent.Parent.FullName, "test");
95+
string openPath = Path.Combine(testDirectory, @"core\Angle.dyn");
96+
//go get a valid asm path.
97+
var locatedPath = string.Empty;
98+
var coreDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
99+
Process dynamoCLI = null;
100+
//TODO an approach we could take to get this running on linux.
101+
//unclear if this needs to be compiled with an ifdef or runtime is ok.
102+
//related to https://jira.autodesk.com/browse/DYN-5705
103+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
104+
{
105+
DynamoShapeManager.Utilities.SearchForASMInLibGFallback(versions, ref locatedPath, coreDirectory, out _);
106+
}
107+
else
108+
{
109+
DynamoShapeManager.Utilities.GetInstalledAsmVersion2(versions, ref locatedPath, coreDirectory);
110+
}
111+
try
112+
{
113+
Assert.DoesNotThrow(() =>
114+
{
115+
116+
dynamoCLI = Process.Start(new ProcessStartInfo(Path.Combine(coreDirectory, "DynamoCLI.exe"), $"--GeometryPath \"{locatedPath}\" -k --NoNetworkMode -o \"{openPath}\" ") { UseShellExecute = true });
117+
118+
Thread.Sleep(5000);// Wait 5 seconds to open the dyn
119+
Assert.IsFalse(dynamoCLI.HasExited);
120+
var dt = DataTarget.AttachToProcess(dynamoCLI.Id, false);
121+
var assemblies = dt
122+
.ClrVersions
123+
.Select(dtClrVersion => dtClrVersion.CreateRuntime())
124+
.SelectMany(runtime => runtime.AppDomains.SelectMany(runtimeAppDomain => runtimeAppDomain.Modules))
125+
.Select(clrModule => clrModule.AssemblyName)
126+
.Distinct()
127+
.Where(x => x != null)
128+
.ToList();
129+
130+
var firstASMmodulePath = string.Empty;
131+
foreach (string module in assemblies)
132+
{
133+
if (module.IndexOf("Analytics", StringComparison.OrdinalIgnoreCase) != -1)
134+
{
135+
Assert.Fail("Analytics module was loaded");
136+
}
137+
if (module.IndexOf("AdpSDKCSharpWrapper", StringComparison.OrdinalIgnoreCase) != -1)
138+
{
139+
Assert.Fail("ADP module was loaded");
140+
}
141+
}
142+
});
143+
}
144+
finally
145+
{
146+
147+
dynamoCLI?.Kill();
148+
}
149+
}
83150
}
84151
}

test/System/IntegrationTests/DynamoApplicationTests.cs

+19
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
using System.Diagnostics;
44
using System.IO;
55
using Dynamo.Applications;
6+
using Dynamo.Logging;
67
using Dynamo.Models;
78
using NUnit.Framework;
9+
using static Dynamo.Models.DynamoModel;
810

911
namespace IntegrationTests
1012
{
@@ -64,6 +66,23 @@ public void DynamoMakeModelWithHostName()
6466
var model = Dynamo.Applications.StartupUtils.MakeModel(false, string.Empty, "DynamoFormIt");
6567
Assert.AreEqual(DynamoModel.HostAnalyticsInfo.HostName, "DynamoFormIt");
6668
}
69+
[Test]
70+
public void DynamoModelStartedWithNoNetworkMode_AlsoDisablesAnalytics()
71+
{
72+
var startConfig = new DefaultStartConfiguration() { NoNetworkMode = true };
73+
var model = DynamoModel.Start(startConfig);
74+
Assert.AreEqual(true, Analytics.DisableAnalytics);
75+
model.ShutDown(false);
76+
}
77+
[Test]
78+
public void DynamoModelStartedWithNoNetworkModeFalse_DisablesAnalyticsCanBeTrue()
79+
{
80+
var startConfig = new DefaultStartConfiguration() { NoNetworkMode = false };
81+
Analytics.DisableAnalytics = true;
82+
var model = DynamoModel.Start(startConfig);
83+
Assert.AreEqual(true, Analytics.DisableAnalytics);
84+
model.ShutDown(false);
85+
}
6786

6887
[Test]
6988
public void IfASMPathInvalidExceptionNotThrown()

0 commit comments

Comments
 (0)