Skip to content

Commit

Permalink
Cleanup and acceptance test for incompatible metrics use (#534)
Browse files Browse the repository at this point in the history
* Significant cleanup

* Small refactoring

* Previous feature had a public default constructor which was public. Bring it back

* Add an acceptance test for the throwing scenario

* Don't use $(SolutionDir) in key path

* Update NServiceBus

* Move Recoverability wire up back to EnableMetrics

* Replace Guards with built-in helpers

* Configure serializer

* Clean up workflow files

* Use primary constructors

* Make struct readonly

---------

Co-authored-by: Brandon Ording <[email protected]>
  • Loading branch information
danielmarbach and bording authored Feb 8, 2024
1 parent b98931d commit 88690a0
Show file tree
Hide file tree
Showing 34 changed files with 115 additions and 501 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
uses: actions/[email protected]
with:
dotnet-version: 8.0.x
dotnet-quality: 'preview'
- name: Build
run: dotnet build src --configuration Release
- name: Upload packages
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
uses: actions/[email protected]
with:
dotnet-version: 8.0.x
dotnet-quality: 'preview'
- name: Build
run: dotnet build src --configuration Release
- name: Sign NuGet packages
Expand Down
21 changes: 0 additions & 21 deletions src/NServiceBus.Metrics.AcceptanceTests/DeterministicGuid.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
namespace NServiceBus.AcceptanceTests.EndpointTemplates
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using AcceptanceTesting.Customization;
using AcceptanceTesting.Support;

public class DefaultServer : IEndpointSetupTemplate
{
public DefaultServer()
{
typesToInclude = [];
}

public DefaultServer(List<Type> typesToInclude)
{
this.typesToInclude = typesToInclude;
}

public async Task<EndpointConfiguration> GetConfiguration(RunDescriptor runDescriptor, EndpointCustomizationConfiguration endpointConfiguration, Func<EndpointConfiguration, Task> configurationBuilderCustomization)
{
var types = endpointConfiguration.GetTypesScopedByTestClass();

typesToInclude.AddRange(types);

var configuration = new EndpointConfiguration(endpointConfiguration.EndpointName);

configuration.TypesToIncludeInScan(typesToInclude);
configuration.EnableInstallers();

configuration.UsePersistence<AcceptanceTestingPersistence>();
var storageDir = Path.Combine(NServiceBusAcceptanceTest.StorageRootDir, NUnit.Framework.TestContext.CurrentContext.Test.ID);
configuration.UseTransport(new LearningTransport { StorageDirectory = storageDir });
configuration.UseSerialization<SystemJsonSerializer>();

var recoverability = configuration.Recoverability();
recoverability.Delayed(delayed => delayed.NumberOfRetries(0));
Expand All @@ -42,9 +27,10 @@ public async Task<EndpointConfiguration> GetConfiguration(RunDescriptor runDescr

await configurationBuilderCustomization(configuration);

// scan types at the end so that all types used by the configuration have been loaded into the AppDomain
configuration.ScanTypesForTest(endpointConfiguration);

return configuration;
}

List<Type> typesToInclude;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NServiceBus.AcceptanceTesting" Version="9.0.0-alpha.1" />
<PackageReference Include="NServiceBus.AcceptanceTesting" Version="9.0.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
Expand Down
18 changes: 0 additions & 18 deletions src/NServiceBus.Metrics.AcceptanceTests/PayloadAssert.cs

This file was deleted.

This file was deleted.

This file was deleted.

25 changes: 0 additions & 25 deletions src/NServiceBus.Metrics.AcceptanceTests/Tests/TagExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public When_having_metrics_handlers_registered()
{
var probesNames = typeof(IProbe).Assembly.GetTypes()
.Where(t => t.GetCustomAttribute<ProbePropertiesAttribute>() != null)
.Select(t => t.GetCustomAttribute<ProbePropertiesAttribute>().Name)
.Select(t => t.GetCustomAttribute<ProbePropertiesAttribute>()!.Name)
.ToArray();

errorProbes =
Expand Down Expand Up @@ -67,8 +67,7 @@ public async Task Should_call_fail_probes_on_success()
var context = await Scenario.Define<Context>()
.WithEndpoint<ThrowingReporter>(b => b.When(s => s.SendLocal(new MyMessage())).DoNotFailOnErrorMessages())
.Done(c => c.Values.Count >= errorProbes.Count)
.Run()
.ConfigureAwait(false);
.Run();

foreach (var kvp in context.Values)
{
Expand All @@ -86,30 +85,24 @@ class Context : ScenarioContext

class ConsumingReporter : EndpointConfigurationBuilder
{
public ConsumingReporter()
{
public ConsumingReporter() =>
EndpointSetup<DefaultServer>((c, r) =>
{
var context = (Context)r.ScenarioContext;

c.EnableMetrics().RegisterObservers(
ctx => { RegisterWritesToTestContext(ctx, context); });
});
}

public class MyHandler : IHandleMessages<MyMessage>
{
public Task Handle(MyMessage message, IMessageHandlerContext context)
{
return Task.Delay(100);
}
public Task Handle(MyMessage message, IMessageHandlerContext context) => Task.Delay(100);
}
}

class ThrowingReporter : EndpointConfigurationBuilder
{
public ThrowingReporter()
{
public ThrowingReporter() =>
EndpointSetup<DefaultServer>((c, r) =>
{
c.Recoverability().Immediate(immediate => immediate.NumberOfRetries(1));
Expand All @@ -118,17 +111,12 @@ public ThrowingReporter()
c.EnableMetrics().RegisterObservers(
ctx => { RegisterWritesToTestContext(ctx, context); });
});
}


public class MyHandler : IHandleMessages<MyMessage>
{
public Task Handle(MyMessage message, IMessageHandlerContext context)
{
var tcs = new TaskCompletionSource<object>();
tcs.SetException(new Exception());
return tcs.Task;
}
=> Task.FromException<Exception>(new Exception());
}
}

Expand Down
Loading

0 comments on commit 88690a0

Please sign in to comment.