-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for MassTransit (#2014)
* Initial exerciser implementation * Cleanup * Build works for all TFMS * Add legacy (7.x) exerciser Also cleanup, and rename start/stop methods * Unify v7/v8 exercisers Also pass in queue name as a parameter to StartBus to help with test assertions * Implement send * Adding alternate instrumentation point and first pass at tests (#2001) * Checkpoint trying to get hosted service model working for v7 * Message consume is working in v7! * Add instrumentation project readmes * Added regex scope, tests are passing * Test send as well as publish; cleanup * Expanded tests, updated instrumentation for v7 * Make regex metric name assertions more specific --------- Co-authored-by: Chris Hynes <[email protected]>
- Loading branch information
1 parent
88f48b1
commit 760f41c
Showing
12 changed files
with
374 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/MassTransit/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This is the wrapper and instrumentation project for version 8.0.0 and higher of [MassTransit](https://masstransit.io/). | ||
|
||
The code in this project is nearly identical to that in the `MassTransitLegacy` project, which is for MassTransit v7. However, different MassTransit types are referenced | ||
in the two projects. The team decided at the time this instrumentation was introduced that eliminating the duplicate code would make things far less readable, | ||
and that code duplication was the lesser of two evils. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/MassTransitLegacy/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This is the wrapper and instrumentation project for version 7.x of [MassTransit](https://masstransit.io/). | ||
|
||
The code in this project is nearly identical to that in the `MassTransit` project, which is for MassTransit v8. However, different MassTransit types are referenced | ||
in the two projects. The team decided at the time this instrumentation was introduced that eliminating the duplicate code would make things far less readable, | ||
and that code duplication was the lesser of two evils. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
tests/Agent/IntegrationTests/IntegrationTests/MassTransit/MassTransitTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using NewRelic.Agent.IntegrationTestHelpers; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using System; | ||
using NewRelic.Agent.IntegrationTestHelpers.RemoteServiceFixtures; | ||
|
||
namespace NewRelic.Agent.IntegrationTests.MassTransit | ||
{ | ||
public abstract class MassTransitTestsBase<TFixture> : NewRelicIntegrationTest<TFixture> | ||
where TFixture : ConsoleDynamicMethodFixture | ||
{ | ||
private readonly TFixture _fixture; | ||
|
||
public MassTransitTestsBase(TFixture fixture, ITestOutputHelper output, bool useStartBus) : base(fixture) | ||
{ | ||
_fixture = fixture; | ||
_fixture.SetTimeout(TimeSpan.FromMinutes(2)); | ||
_fixture.TestLogger = output; | ||
|
||
if (useStartBus) | ||
{ | ||
_fixture.AddCommand($"MassTransitExerciser StartBus"); | ||
} | ||
else | ||
{ | ||
_fixture.AddCommand("MassTransitExerciser StartHost"); | ||
} | ||
_fixture.AddCommand("MassTransitExerciser Publish publishedMessageOne"); | ||
_fixture.AddCommand("MassTransitExerciser Publish publishedMessageTwo"); | ||
_fixture.AddCommand("MassTransitExerciser Send sentMessageOne"); | ||
_fixture.AddCommand("MassTransitExerciser Send sentMessageTwo"); | ||
|
||
if (useStartBus) | ||
{ | ||
_fixture.AddCommand($"MassTransitExerciser StopBus"); | ||
} | ||
else | ||
{ | ||
_fixture.AddCommand("MassTransitExerciser StopHost"); | ||
} | ||
|
||
_fixture.AddActions | ||
( | ||
setupConfiguration: () => | ||
{ | ||
var configModifier = new NewRelicConfigModifier(fixture.DestinationNewRelicConfigFilePath); | ||
configModifier.ForceTransactionTraces(); | ||
configModifier.SetLogLevel("finest"); | ||
}, | ||
exerciseApplication: () => | ||
{ | ||
_fixture.AgentLog.WaitForLogLine(AgentLogBase.MetricDataLogLineRegex, TimeSpan.FromMinutes(2)); | ||
} | ||
); | ||
|
||
_fixture.Initialize(); | ||
} | ||
|
||
[Fact] | ||
public void Test() | ||
{ | ||
|
||
var massTransitMetricNameRegexBase = @"MessageBroker\/MassTransit\/Queue\/"; | ||
var queueNameRegex = @"Named\/(.{26})"; // The auto-generated in-memory queue names have 26 chars | ||
var massTransitProduceMetricNameRegex = massTransitMetricNameRegexBase + @"Produce\/" + queueNameRegex; | ||
var massTransitConsumeMetricNameRegex = massTransitMetricNameRegexBase + @"Consume\/" + queueNameRegex; | ||
|
||
var metrics = _fixture.AgentLog.GetMetrics().ToList(); | ||
|
||
var expectedMetrics = new List<Assertions.ExpectedMetric> | ||
{ | ||
new Assertions.ExpectedMetric { metricName = massTransitConsumeMetricNameRegex, callCount = 4, IsRegexName = true}, | ||
new Assertions.ExpectedMetric { metricName = massTransitProduceMetricNameRegex, callCount = 4, IsRegexName = true}, | ||
|
||
new Assertions.ExpectedMetric { metricName = massTransitConsumeMetricNameRegex, callCount = 4, IsRegexName = true, metricScope = @"OtherTransaction\/Message\/MassTransit\/Queue\/" + queueNameRegex, IsRegexScope = true}, | ||
new Assertions.ExpectedMetric { metricName = massTransitProduceMetricNameRegex, callCount = 2, IsRegexName = true, metricScope = "OtherTransaction/Custom/MultiFunctionApplicationHelpers.NetStandardLibraries.MassTransitExerciser/Publish"}, | ||
new Assertions.ExpectedMetric { metricName = massTransitProduceMetricNameRegex, callCount = 2, IsRegexName = true, metricScope = "OtherTransaction/Custom/MultiFunctionApplicationHelpers.NetStandardLibraries.MassTransitExerciser/Send"}, | ||
}; | ||
|
||
Assertions.MetricsExist(expectedMetrics, metrics); | ||
|
||
var transactionEvent = _fixture.AgentLog.TryGetTransactionEvent($"OtherTransaction/Custom/MultiFunctionApplicationHelpers.NetStandardLibraries.MassTransitExerciser/Publish"); | ||
|
||
Assert.NotNull( transactionEvent ); | ||
} | ||
} | ||
|
||
// Tests using StartHost (hosted service configuration method) | ||
[NetFrameworkTest] | ||
public class MassTransitTests_StartHost_FW462 : MassTransitTestsBase<ConsoleDynamicMethodFixtureFW462> | ||
{ | ||
public MassTransitTests_StartHost_FW462(ConsoleDynamicMethodFixtureFW462 fixture, ITestOutputHelper output) | ||
: base(fixture, output, false) | ||
{ | ||
} | ||
} | ||
[NetFrameworkTest] | ||
public class MassTransitTests_StartHost_FWLatest : MassTransitTestsBase<ConsoleDynamicMethodFixtureFWLatest> | ||
{ | ||
public MassTransitTests_StartHost_FWLatest(ConsoleDynamicMethodFixtureFWLatest fixture, ITestOutputHelper output) | ||
: base(fixture, output, false) | ||
{ | ||
} | ||
} | ||
[NetCoreTest] | ||
public class MassTransitTests_StartHost_Core60 : MassTransitTestsBase<ConsoleDynamicMethodFixtureCore60> | ||
{ | ||
public MassTransitTests_StartHost_Core60(ConsoleDynamicMethodFixtureCore60 fixture, ITestOutputHelper output) | ||
: base(fixture, output, false) | ||
{ | ||
} | ||
} | ||
[NetCoreTest] | ||
public class MassTransitTests_StartHost_CoreLatest : MassTransitTestsBase<ConsoleDynamicMethodFixtureCoreLatest> | ||
{ | ||
public MassTransitTests_StartHost_CoreLatest(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper output) | ||
: base(fixture, output, false) | ||
{ | ||
} | ||
} | ||
|
||
// Tests using StartBus (bus factory configuration method) | ||
[NetFrameworkTest] | ||
public class MassTransitTests_StartBus_FW462 : MassTransitTestsBase<ConsoleDynamicMethodFixtureFW462> | ||
{ | ||
public MassTransitTests_StartBus_FW462(ConsoleDynamicMethodFixtureFW462 fixture, ITestOutputHelper output) | ||
: base(fixture, output, true) | ||
{ | ||
} | ||
} | ||
[NetFrameworkTest] | ||
public class MassTransitTests_StartBus_FWLatest : MassTransitTestsBase<ConsoleDynamicMethodFixtureFWLatest> | ||
{ | ||
public MassTransitTests_StartBus_FWLatest(ConsoleDynamicMethodFixtureFWLatest fixture, ITestOutputHelper output) | ||
: base(fixture, output, true) | ||
{ | ||
} | ||
} | ||
[NetCoreTest] | ||
public class MassTransitTests_StartBus_Core60 : MassTransitTestsBase<ConsoleDynamicMethodFixtureCore60> | ||
{ | ||
public MassTransitTests_StartBus_Core60(ConsoleDynamicMethodFixtureCore60 fixture, ITestOutputHelper output) | ||
: base(fixture, output, true) | ||
{ | ||
} | ||
} | ||
[NetCoreTest] | ||
public class MassTransitTests_StartBus_CoreLatest : MassTransitTestsBase<ConsoleDynamicMethodFixtureCoreLatest> | ||
{ | ||
public MassTransitTests_StartBus_CoreLatest(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper output) | ||
: base(fixture, output, true) | ||
{ | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.