Skip to content

Commit

Permalink
Addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Jul 18, 2023
1 parent 6d09a01 commit df1a559
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
run: dotnet restore

- name: Build & Run Unit Tests
run: dotnet test --verbosity normal --no-restore --settings tests\UnitTests.runsettings --results-directory ${{ env.test_results_path }}
run: dotnet test --verbosity minimal --no-restore --settings tests\UnitTests.runsettings --results-directory ${{ env.test_results_path }}

- name: Upload coverage reports to Codecov.io
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ private static List<TestCaseData> GetTraceContextTestData()
{
var testCaseData = new List<TestCaseData>();

string location;
#if NETFRAMEWORK
location = Assembly.GetExecutingAssembly().CodeBase;
#else
location = Assembly.GetExecutingAssembly().Location;
#endif
string location = Assembly.GetExecutingAssembly().GetLocation();
var dllPath = Path.GetDirectoryName(new Uri(location).LocalPath);
var jsonPath = Path.Combine(dllPath, "CrossAgentTests", "DistributedTracing", "trace_context.json");
var jsonString = File.ReadAllText(jsonPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using NewRelic.Agent.Core.DataTransport;
using NewRelic.Agent.Core.Labels;
using NewRelic.Agent.Core.Utilities;
using NewRelic.Agent.TestUtilities;
using NewRelic.SystemInterfaces;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -80,12 +81,7 @@ private static List<TestCaseData> GetSecurityPoliciesTestData()
{
var testCaseDatas = new List<TestCaseData>();

string location;
#if NETFRAMEWORK
location = Assembly.GetExecutingAssembly().CodeBase;
#else
location = Assembly.GetExecutingAssembly().Location;
#endif
string location = Assembly.GetExecutingAssembly().GetLocation();
var dllPath = Path.GetDirectoryName(new Uri(location).LocalPath);
var jsonPath = Path.Combine(dllPath, "CrossAgentTests", "SecurityPolicies", "security_policies.json");
var jsonString = File.ReadAllText(jsonPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using NewRelic.Agent.Api;
using NewRelic.Agent.Core.Database;
using NewRelic.Agent.Extensions.Providers.Wrapper;
using NewRelic.Agent.TestUtilities;
using Newtonsoft.Json;
using NUnit.Framework;

Expand Down Expand Up @@ -85,12 +86,7 @@ private static List<TestCaseData> GetSqlObfuscationTestDatas()
{
var testCaseDatas = new List<TestCaseData>();

string location;
#if NETFRAMEWORK
location = Assembly.GetExecutingAssembly().CodeBase;
#else
location = Assembly.GetExecutingAssembly().Location;
#endif
string location = Assembly.GetExecutingAssembly().GetLocation();
var dllPath = Path.GetDirectoryName(new Uri(location).LocalPath);
var jsonPath = Path.Combine(dllPath, "CrossAgentTests", "SqlObfuscation", "sql_obfuscation.json");
var jsonString = File.ReadAllText(jsonPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using NewRelic.Agent.Api;
using NewRelic.Agent.Core.Utilization;
using NewRelic.Agent.TestUtilities;
using Newtonsoft.Json;
using NUnit.Framework;
using System;
Expand Down Expand Up @@ -208,12 +209,7 @@ private static List<TestCaseData> GetUtilizationTestData()
{
var testCaseDatas = new List<TestCaseData>();

string location;
#if NETFRAMEWORK
location = Assembly.GetExecutingAssembly().CodeBase;
#else
location = Assembly.GetExecutingAssembly().Location;
#endif
string location = Assembly.GetExecutingAssembly().GetLocation();
var dllPath = Path.GetDirectoryName(new Uri(location).LocalPath);
var jsonPath = Path.Combine(dllPath, "CrossAgentTests", "Utilization", "utilization_json.json");
var jsonString = File.ReadAllText(jsonPath);
Expand Down
102 changes: 51 additions & 51 deletions tests/Agent/UnitTests/CompositeTests/Samplers/GcSamplerNetCoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,75 +75,75 @@ public void SamplerStartsWithoutException()
sampler.Start();
}

//[Test]
//public void SamplerDisposesEventListenerOnException()
//{
// var samplerWasStopped = false;
// var listenerWasDisposed = false;
[Test]
public void SamplerDisposesEventListenerOnException()
{
var samplerWasStopped = false;
var listenerWasDisposed = false;

// var mockListener = Mock.Create<ISampledEventListener<Dictionary<GCSampleType, float>>>();
var mockListener = Mock.Create<ISampledEventListener<Dictionary<GCSampleType, float>>>();

// Mock.Arrange(() => mockListener.Dispose())
// .DoInstead(() => { listenerWasDisposed = true; });
Mock.Arrange(() => mockListener.Dispose())
.DoInstead(() => { listenerWasDisposed = true; });

// //This is our mechanism for shutting down the sampler. If a config change is used, it starts/stops 3x which makes
// //it difficult to determine current state. Instead, throw an exception in the eventListener's sample method.
// Mock.Arrange(() => mockListener.Sample())
// .DoInstead(() => throw new Exception());
//This is our mechanism for shutting down the sampler. If a config change is used, it starts/stops 3x which makes
//it difficult to determine current state. Instead, throw an exception in the eventListener's sample method.
Mock.Arrange(() => mockListener.Sample())
.DoInstead(() => throw new Exception());

// Func<ISampledEventListener<Dictionary<GCSampleType, float>>> mockListenerFactory = () =>
// {
// return mockListener;
// };
Func<ISampledEventListener<Dictionary<GCSampleType, float>>> mockListenerFactory = () =>
{
return mockListener;
};

// var mockScheduler = Mock.Create<IScheduler>();
var mockScheduler = Mock.Create<IScheduler>();

// //Prevents the scheduler from actually running
// Mock.Arrange(() => _mockScheduler.ExecuteEvery(Arg.IsAny<Action>(), Arg.IsAny<TimeSpan>(), Arg.IsAny<TimeSpan?>()))
// .DoNothing();
//Prevents the scheduler from actually running
Mock.Arrange(() => _mockScheduler.ExecuteEvery(Arg.IsAny<Action>(), Arg.IsAny<TimeSpan>(), Arg.IsAny<TimeSpan?>()))
.DoNothing();

// //Tracks the stop executing for the scheduler which indicates that the sampler
// //has requested it to stop;
// Mock.Arrange(() => mockScheduler.StopExecuting(Arg.IsAny<Action>(), Arg.IsAny<TimeSpan?>()))
// .DoInstead<Action, TimeSpan?>((a, t) => { samplerWasStopped = true; });
//Tracks the stop executing for the scheduler which indicates that the sampler
//has requested it to stop;
Mock.Arrange(() => mockScheduler.StopExecuting(Arg.IsAny<Action>(), Arg.IsAny<TimeSpan?>()))
.DoInstead<Action, TimeSpan?>((a, t) => { samplerWasStopped = true; });

// var sampler = new GCSamplerNetCore(mockScheduler, mockListenerFactory, _mockTransformer, _fxSamplerValidForFrameworkOverride);
var sampler = new GCSamplerNetCore(mockScheduler, mockListenerFactory, _mockTransformer, _fxSamplerValidForFrameworkOverride);

// //Act
// sampler.Start();
//Act
sampler.Start();

// //Cause error which will shut down the sampler
// sampler.Sample();
//Cause error which will shut down the sampler
sampler.Sample();

// //Assert
// Assert.IsTrue(samplerWasStopped);
// Assert.IsTrue(listenerWasDisposed);
//}
//Assert
Assert.IsTrue(samplerWasStopped);
Assert.IsTrue(listenerWasDisposed);
}

//[Test]
//public void SamplerDisposesEventListenerWhenDisposed()
//{
// var listenerWasDisposed = false;
[Test]
public void SamplerDisposesEventListenerWhenDisposed()
{
var listenerWasDisposed = false;

// var mockListener = Mock.Create<ISampledEventListener<Dictionary<GCSampleType, float>>>();
var mockListener = Mock.Create<ISampledEventListener<Dictionary<GCSampleType, float>>>();

// Mock.Arrange(() => mockListener.Dispose())
// .DoInstead(() => { listenerWasDisposed = true; });
Mock.Arrange(() => mockListener.Dispose())
.DoInstead(() => { listenerWasDisposed = true; });

// Func<ISampledEventListener<Dictionary<GCSampleType, float>>> mockListenerFactory = () =>
// {
// return mockListener;
// };
Func<ISampledEventListener<Dictionary<GCSampleType, float>>> mockListenerFactory = () =>
{
return mockListener;
};

// var sampler = new GCSamplerNetCore(_mockScheduler, mockListenerFactory, _mockTransformer, _fxSamplerValidForFrameworkOverride);
var sampler = new GCSamplerNetCore(_mockScheduler, mockListenerFactory, _mockTransformer, _fxSamplerValidForFrameworkOverride);

// //Act
// sampler.Start();
// sampler.Dispose();
//Act
sampler.Start();
sampler.Dispose();

// //Assert
// Assert.IsTrue(listenerWasDisposed);
//}
//Assert
Assert.IsTrue(listenerWasDisposed);
}

[Test]
public void SamplerStartsEventListenerWhenStarted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using NewRelic.Agent.Core.Configuration;
using NewRelic.Agent.Core.DataTransport;
using System.Reflection;
using NewRelic.Agent.TestUtilities;

namespace NewRelic.Agent.Core.CrossAgentTests.DataTransport
{
Expand Down Expand Up @@ -107,11 +108,7 @@ public void RunCrossAgentCollectorHostnameTests(string configFileKey, string env
private static List<TestCaseData> GetCollectorHostnameTestData()
{
var testDatas = new List<TestCaseData>();
#if NETFRAMEWORK
var location = Assembly.GetExecutingAssembly().CodeBase;
#else
var location = Assembly.GetExecutingAssembly().Location;
#endif
string location = Assembly.GetExecutingAssembly().GetLocation();
var dllPath = Path.GetDirectoryName(new Uri(location).LocalPath);
var jsonPath = Path.Combine(dllPath, "CrossAgentTests", "DataTransport", "collector_hostname.json");
var jsonString = File.ReadAllText(jsonPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using NewRelic.Agent.TestUtilities;
using Telerik.JustMock;

namespace NewRelic.Agent.Core.CrossAgentTests
Expand Down Expand Up @@ -203,11 +204,7 @@ public static IEnumerable<TestCase[]> TestCases
{
get
{
#if NETFRAMEWORK
var location = Assembly.GetExecutingAssembly().CodeBase;
#else
var location = Assembly.GetExecutingAssembly().Location;
#endif
string location = Assembly.GetExecutingAssembly().GetLocation();
var dllPath = Path.GetDirectoryName(new Uri(location).LocalPath);
var jsonPath = Path.Combine(dllPath, "CrossAgentTests", "ServerSentEvent", "data_collection_server_configuration.json");
var jsonString = File.ReadAllText(jsonPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System.Reflection;

namespace NewRelic.Agent.TestUtilities
{
public static class AssemblyExtensions
{
public static string GetLocation(this Assembly assembly)
{
#if NETFRAMEWORK
return assembly.CodeBase;
#else
return assembly.Location;
#endif

}
}
}

0 comments on commit df1a559

Please sign in to comment.