Skip to content

Commit

Permalink
8T integration tests (#431)
Browse files Browse the repository at this point in the history
* initial work for 8T integration tests.

* no need to instrument StartAgent method

* Refactors InfiniteTracingTests to cover different framework testing.
Changes the target framework in ConsoleDynamicMethodFixtureCoreLatest to "net5.0"

* 8T supportability metric assertions are enough, scraping for InfiniteTracing log messages is unnecessary.

* Adds comments.

* Added trace observer entry to example secrets file

Co-authored-by: Alex Hemsath <[email protected]>
  • Loading branch information
vuqtran88 and nr-ahemsath authored Jan 21, 2021
1 parent be90787 commit fa79047
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ public NewRelicConfigModifier AddExpectedStatusCodes(string statusCodes)
return this;
}

public NewRelicConfigModifier EnableDistributedTrace()
{
SetOrDeleteDistributedTraceEnabled(true);
return this;
}

public NewRelicConfigModifier EnableInfinteTracing(string traceObserverUrl)
{
CommonUtils.ModifyOrCreateXmlAttributeInNewRelicConfig(_configFilePath,
new[] { "configuration", "infiniteTracing", "trace_observer" }, "host", traceObserverUrl);
return this;
}

public void AutoInstrumentBrowserMonitoring(bool shouldAutoInstrument)
{
var stringValue = shouldAutoInstrument.ToString().ToLower(); //We don't seem to handle the uppercase parse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public DotNetPerfMetricsTestsCore22(ConsoleDynamicMethodFixtureCore22 fixture, I
}

[NetCoreTest]
public class DotNetPerfMetricsTestsCoreLatest : DotNetPerfMetricsTests<ConsoleDynamicMethodFixtureCoreLatest>
public class DotNetPerfMetricsTestsCoreLatest : DotNetPerfMetricsTests<ConsoleDynamicMethodFixtureCore31>
{
public DotNetPerfMetricsTestsCoreLatest(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper output)
public DotNetPerfMetricsTestsCoreLatest(ConsoleDynamicMethodFixtureCore31 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public ApiCallsTestsFW(ConsoleDynamicMethodFixtureFWLatest fixture, ITestOutputH
}

[NetCoreTest]
public class ApiCallsTestsCore : ApiCallsTests<ConsoleDynamicMethodFixtureCoreLatest>
public class ApiCallsTestsCore : ApiCallsTests<ConsoleDynamicMethodFixtureCore31>
{
public ApiCallsTestsCore(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper output)
public ApiCallsTestsCore(ConsoleDynamicMethodFixtureCore31 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public NetStandardLibraryInstrumentationFW(ConsoleDynamicMethodFixtureFWLatest f
}

[NetCoreTest]
public class NetStandardLibraryInstrumentationNetCore : NetStandardLibraryInstrumentation<ConsoleDynamicMethodFixtureCoreLatest>
public class NetStandardLibraryInstrumentationNetCore : NetStandardLibraryInstrumentation<ConsoleDynamicMethodFixtureCore31>
{
public NetStandardLibraryInstrumentationNetCore(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper output) : base(fixture, output)
public NetStandardLibraryInstrumentationNetCore(ConsoleDynamicMethodFixtureCore31 fixture, ITestOutputHelper output) : base(fixture, output)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public FasterEventHarvestNetFrameworkTests(ConsoleDynamicMethodFixtureFWLatest f
}

[NetCoreTest]
public class FasterEventHarvestNetCoreTests : FasterEventHarvestTests<ConsoleDynamicMethodFixtureCoreLatest>
public class FasterEventHarvestNetCoreTests : FasterEventHarvestTests<ConsoleDynamicMethodFixtureCore31>
{
public FasterEventHarvestNetCoreTests(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper output) : base(fixture, output)
public FasterEventHarvestNetCoreTests(ConsoleDynamicMethodFixtureCore31 fixture, ITestOutputHelper output) : base(fixture, output)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System.Collections.Generic;
using MultiFunctionApplicationHelpers;
using NewRelic.Agent.IntegrationTestHelpers;
using Xunit;
using Xunit.Abstractions;

namespace NewRelic.Agent.IntegrationTests.InfiniteTracing
{
public abstract class InfiniteTracingTestsBase<TFixture> : NewRelicIntegrationTest<TFixture>
where TFixture : ConsoleDynamicMethodFixture
{
private readonly TFixture _fixture;

public InfiniteTracingTestsBase(TFixture fixture, ITestOutputHelper output):base(fixture)
{
_fixture = fixture;
_fixture.SetTimeout(System.TimeSpan.FromMinutes(2));
_fixture.TestLogger = output;

_fixture.AddCommand($"InfiniteTracingTester StartAgent");
_fixture.AddCommand($"InfiniteTracingTester Make8TSpan");
_fixture.AddCommand($"InfiniteTracingTester Wait");


_fixture.Actions
(
setupConfiguration: () =>
{
var configModifier = new NewRelicConfigModifier(fixture.DestinationNewRelicConfigFilePath);

configModifier.ForceTransactionTraces()
.EnableDistributedTrace()
.EnableInfinteTracing(_fixture.TestConfiguration.TraceObserverUrl)
.SetLogLevel("finest");
}
);

_fixture.Initialize();
}

[Fact]
public void Test()
{
//1 span count for the Make8TSpan method, another span count for the root span.
var expectedSeenCount = 2;
var expectedSentCount = 2;
var expectedReceivedCount = 2;

var actualMetrics = new List<Assertions.ExpectedMetric>
{
new Assertions.ExpectedMetric { metricName = @"Supportability/InfiniteTracing/Span/Seen", callCount = expectedSeenCount },
new Assertions.ExpectedMetric { metricName = @"Supportability/InfiniteTracing/Span/Sent", callCount = expectedSentCount },
new Assertions.ExpectedMetric { metricName = @"Supportability/InfiniteTracing/Span/Received", callCount = expectedReceivedCount }
};

var metrics = _fixture.AgentLog.GetMetrics();
Assertions.MetricsExist(actualMetrics, metrics);
}
}

[NetFrameworkTest]
public class InfiniteTracingFWLatestTests : InfiniteTracingTestsBase<ConsoleDynamicMethodFixtureFWLatest>
{
public InfiniteTracingFWLatestTests(ConsoleDynamicMethodFixtureFWLatest fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}


[NetFrameworkTest]
public class InfiniteTracingFW471Tests : InfiniteTracingTestsBase<ConsoleDynamicMethodFixtureFW471>
{
public InfiniteTracingFW471Tests(ConsoleDynamicMethodFixtureFW471 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}

[NetFrameworkTest]
public class InfiniteTracingFW461Tests : InfiniteTracingTestsBase<ConsoleDynamicMethodFixtureFW461>
{
public InfiniteTracingFW461Tests(ConsoleDynamicMethodFixtureFW461 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}

[NetCoreTest]
public class InfiniteTracingNetCoreLatestTests : InfiniteTracingTestsBase<ConsoleDynamicMethodFixtureCoreLatest>
{
public InfiniteTracingNetCoreLatestTests(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}

[NetCoreTest]
public class InfiniteTracingNetCore31Tests : InfiniteTracingTestsBase<ConsoleDynamicMethodFixtureCore31>
{
public InfiniteTracingNetCore31Tests(ConsoleDynamicMethodFixtureCore31 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}

[NetCoreTest]
public class InfiniteTracingNetCore21Tests : InfiniteTracingTestsBase<ConsoleDynamicMethodFixtureCore21>
{
public InfiniteTracingNetCore21Tests(ConsoleDynamicMethodFixtureCore21 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ public string CollectorUrl
}
}

public string TraceObserverUrl
{
get
{
if (TestSettingOverrides.TryGetValue(_configurationCategory, out var item) && !string.IsNullOrEmpty(item.TraceObserverUrl))
{
return item.TraceObserverUrl;
};

return DefaultSetting.TraceObserverUrl;
}
}

private IntegrationTestConfiguration(string configurationCategory)
{
_configurationCategory = configurationCategory;
Expand Down Expand Up @@ -77,6 +90,7 @@ public class TestSettings
public string AwsAccessKeyId { get; set; }
public string AwsSecretAccessKey { get; set; }
public string AwsAccountNumber { get; set; }
public string TraceObserverUrl { get; set; }
public IDictionary<string, string> CustomSettings { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public ConsoleDynamicMethodFixtureCore21() : base("netcoreapp2.1")
}
}

public class ConsoleDynamicMethodFixtureCore31 : ConsoleDynamicMethodFixtureCoreSpecificVersion
{
public ConsoleDynamicMethodFixtureCore31() : base("netcoreapp3.1")
{
}
}

/// <summary>
/// Use this fixture if you don't care about which .net core version the test application should use.
/// If you need to test against a feature that belongs to a specific .net core version, then consider
Expand All @@ -68,7 +75,7 @@ public ConsoleDynamicMethodFixtureCore21() : base("netcoreapp2.1")
/// </summary>
public class ConsoleDynamicMethodFixtureCoreLatest : ConsoleDynamicMethodFixtureCoreSpecificVersion
{
public ConsoleDynamicMethodFixtureCoreLatest() : base("netcoreapp3.1")
public ConsoleDynamicMethodFixtureCoreLatest() : base("net5.0")
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Runtime.CompilerServices;
using System.Threading;
using NewRelic.Agent.IntegrationTests.Shared.ReflectionHelpers;
using NewRelic.Api.Agent;

namespace MultiFunctionApplicationHelpers.NetStandardLibraries
{
[Library]
public class InfiniteTracingTester
{
[LibraryMethod]
[Transaction]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public void Make8TSpan()
{
var rand = new Random(10);
rand.Next();
rand.Next();
rand.Next();
rand.Next();
}

[LibraryMethod]
public static void StartAgent()
{
NewRelic.Api.Agent.NewRelic.StartAgent();
//Get everything started up and time for initial Sample().
Thread.Sleep(TimeSpan.FromSeconds(10));
}

[LibraryMethod]
public static void Wait()
{
Thread.Sleep(TimeSpan.FromSeconds(70));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1;netcoreapp2.2;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp2.2;netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public RabbitMqDistributedTracingFW352Tests(ConsoleDynamicMethodFixtureFW461 fix
}

[NetCoreTest]
public class RabbitMqDistributedTracingNetCore621Tests : RabbitMqDistributedTracingTestsBase<ConsoleDynamicMethodFixtureCoreLatest>
public class RabbitMqDistributedTracingNetCore621Tests : RabbitMqDistributedTracingTestsBase<ConsoleDynamicMethodFixtureCore31>
{
public RabbitMqDistributedTracingNetCore621Tests(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper output)
public RabbitMqDistributedTracingNetCore621Tests(ConsoleDynamicMethodFixtureCore31 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public RabbitMqFW352Tests(ConsoleDynamicMethodFixtureFW461 fixture, ITestOutputH
}

[NetCoreTest]
public class RabbitMqNetCore621Tests : RabbitMqTestsBase<ConsoleDynamicMethodFixtureCoreLatest>
public class RabbitMqNetCore621Tests : RabbitMqTestsBase<ConsoleDynamicMethodFixtureCore31>
{
public RabbitMqNetCore621Tests(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper output)
public RabbitMqNetCore621Tests(ConsoleDynamicMethodFixtureCore31 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"AwsTestRoleArn" : "YOUR_AWS_TEST_ROLE_ARN_HERE",
"AwsAccessKeyId" : "YOUR_AWS_ACCESS_KEY_ID_HERE",
"AwsSecretAccessKey" : "YOUR_AWS_SECRET_ACCESS_KEY_HERE",
"AwsAccountNumber" : "YOUR_AWS_ACCOUNT_NUMBER_HERE"
"AwsAccountNumber" : "YOUR_AWS_ACCOUNT_NUMBER_HERE",
"TraceObserverUrl" : "YOUR_NR_EDGE_TRACE_OBSERVER_HERE"
},
"TestSettingOverrides": {
"HSM": {
Expand Down

0 comments on commit fa79047

Please sign in to comment.