Skip to content

Commit 75a3076

Browse files
Acceptance test Done statement improvements (#7588)
* Pipeline folder done statements * Recoverability folder done statements * Remove not used TestRunId * Restore previous concurrency settings but cut execution time slightly * Routing folder done statements * Sagas folder done statements * Reduce the test run time * OpenTelemetry folder done statements * PublishSubscribe folder done statements * Pipeline folder done statements * Tx folder done statements * Serialization folder done statements * Outbox folder done statements * Fail fast on handler timeout firing * Tweak test --------- Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com>
1 parent 4576f89 commit 75a3076

File tree

79 files changed

+534
-1206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+534
-1206
lines changed

src/NServiceBus.AcceptanceTests/Core/OpenTelemetry/When_incoming_message_handled.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ static async Task<TestingMetricListener> WhenMessagesHandled(Func<IMessage> mess
8181
}
8282
}
8383
}))
84-
.Done(c => c.TotalHandledMessages == 5)
8584
.Run();
8685
return metricsListener;
8786
}
@@ -120,7 +119,7 @@ class MyMessageHandler(Context testContext) : IHandleMessages<MyMessage>
120119
{
121120
public Task Handle(MyMessage message, IMessageHandlerContext context)
122121
{
123-
Interlocked.Increment(ref testContext.TotalHandledMessages);
122+
testContext.MarkAsCompleted(Interlocked.Increment(ref testContext.TotalHandledMessages) == 5);
124123
return Task.CompletedTask;
125124
}
126125
}
@@ -129,7 +128,8 @@ class MyExceptionalHandler(Context testContext) : IHandleMessages<MyExceptionalM
129128
{
130129
public Task Handle(MyExceptionalMessage message, IMessageHandlerContext context)
131130
{
132-
Interlocked.Increment(ref testContext.TotalHandledMessages);
131+
var count = Interlocked.Increment(ref testContext.TotalHandledMessages);
132+
testContext.MarkAsCompleted(count == 5);
133133
throw new Exception();
134134
}
135135
}

src/NServiceBus.AcceptanceTests/Core/OpenTelemetry/When_incoming_message_handled_successfully.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public async Task Should_record_handling_time()
2525
await session.SendLocal(new MyMessage());
2626
}
2727
}))
28-
.Done(c => c.TotalHandledMessages == 5)
2928
.Run();
3029

3130
string handlingTime = "nservicebus.messaging.handler_time";
@@ -52,7 +51,8 @@ class MyMessageHandler(Context testContext) : IHandleMessages<MyMessage>
5251
{
5352
public Task Handle(MyMessage message, IMessageHandlerContext context)
5453
{
55-
Interlocked.Increment(ref testContext.TotalHandledMessages);
54+
var count = Interlocked.Increment(ref testContext.TotalHandledMessages);
55+
testContext.MarkAsCompleted(count == 5);
5656
return Task.CompletedTask;
5757
}
5858
}

src/NServiceBus.AcceptanceTests/Core/Pipeline/When_receiving_with_catch_all_handlers_registered.cs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public async Task Should_call_catch_all_handlers()
1616
{
1717
Id = c.Id
1818
})))
19-
.Done(c => c.ObjectHandlerWasCalled && c.DynamicHandlerWasCalled && c.IMessageHandlerWasCalled)
2019
.Run();
2120

2221
using (Assert.EnterMultipleScope())
@@ -33,28 +32,22 @@ public class Context : ScenarioContext
3332
public bool DynamicHandlerWasCalled { get; set; }
3433
public bool IMessageHandlerWasCalled { get; set; }
3534
public Guid Id { get; set; }
35+
36+
public void MaybeCompleted() => MarkAsCompleted(ObjectHandlerWasCalled, DynamicHandlerWasCalled, IMessageHandlerWasCalled);
3637
}
3738

3839
public class Endpoint : EndpointConfigurationBuilder
3940
{
40-
public Endpoint()
41-
{
42-
EndpointSetup<DefaultServer>();
43-
}
41+
public Endpoint() => EndpointSetup<DefaultServer>();
4442
}
4543

4644
public class MyMessage : IMessage
4745
{
4846
public Guid Id { get; set; }
4947
}
5048

51-
public class CatchAllHandler_object : IHandleMessages<object>
49+
public class CatchAllHandler_object(Context testContext) : IHandleMessages<object>
5250
{
53-
public CatchAllHandler_object(Context context)
54-
{
55-
testContext = context;
56-
}
57-
5851
public Task Handle(object message, IMessageHandlerContext context)
5952
{
6053
var myMessage = (MyMessage)message;
@@ -64,19 +57,13 @@ public Task Handle(object message, IMessageHandlerContext context)
6457
}
6558

6659
testContext.ObjectHandlerWasCalled = true;
60+
testContext.MaybeCompleted();
6761
return Task.CompletedTask;
6862
}
69-
70-
Context testContext;
7163
}
7264

73-
public class CatchAllHandler_dynamic : IHandleMessages<object>
65+
public class CatchAllHandler_dynamic(Context testContext) : IHandleMessages<object>
7466
{
75-
public CatchAllHandler_dynamic(Context testContext)
76-
{
77-
this.testContext = testContext;
78-
}
79-
8067
public Task Handle(dynamic message, IMessageHandlerContext context)
8168
{
8269
var myMessage = (MyMessage)message;
@@ -86,20 +73,13 @@ public Task Handle(dynamic message, IMessageHandlerContext context)
8673
}
8774

8875
testContext.DynamicHandlerWasCalled = true;
89-
76+
testContext.MaybeCompleted();
9077
return Task.CompletedTask;
9178
}
92-
93-
Context testContext;
9479
}
9580

96-
public class CatchAllHandler_IMessage : IHandleMessages<IMessage>
81+
public class CatchAllHandler_IMessage(Context testContext) : IHandleMessages<IMessage>
9782
{
98-
public CatchAllHandler_IMessage(Context testContext)
99-
{
100-
this.testContext = testContext;
101-
}
102-
10383
public Task Handle(IMessage message, IMessageHandlerContext context)
10484
{
10585
var myMessage = (MyMessage)message;
@@ -109,9 +89,8 @@ public Task Handle(IMessage message, IMessageHandlerContext context)
10989
}
11090

11191
testContext.IMessageHandlerWasCalled = true;
92+
testContext.MaybeCompleted();
11293
return Task.CompletedTask;
11394
}
114-
115-
Context testContext;
11695
}
11796
}

src/NServiceBus.AcceptanceTests/Core/Pipeline/When_reusing_sendoptions.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public async Task Should_generate_new_message_id_for_every_message()
2222
await s.Send(new SomeCommand(), sendOptions);
2323
await s.Send(new SomeCommand(), sendOptions);
2424
}))
25-
.Done(c => c.ReceivedMessageIds.Count >= 3)
2625
.Run();
2726

2827
Assert.That(context.ReceivedMessageIds, Has.Count.EqualTo(3));
@@ -31,34 +30,23 @@ public async Task Should_generate_new_message_id_for_every_message()
3130

3231
class Context : ScenarioContext
3332
{
34-
public ConcurrentQueue<string> ReceivedMessageIds = new ConcurrentQueue<string>();
33+
public ConcurrentQueue<string> ReceivedMessageIds { get; } = new();
3534
}
3635

3736
class Endpoint : EndpointConfigurationBuilder
3837
{
39-
public Endpoint()
40-
{
41-
EndpointSetup<DefaultServer>();
42-
}
38+
public Endpoint() => EndpointSetup<DefaultServer>();
4339

44-
class CommandHandler : IHandleMessages<SomeCommand>
40+
class CommandHandler(Context testContext) : IHandleMessages<SomeCommand>
4541
{
46-
public CommandHandler(Context testContext)
47-
{
48-
this.testContext = testContext;
49-
}
50-
5142
public Task Handle(SomeCommand message, IMessageHandlerContext context)
5243
{
5344
testContext.ReceivedMessageIds.Enqueue(context.MessageId);
45+
testContext.MarkAsCompleted(testContext.ReceivedMessageIds.Count >= 3);
5446
return Task.CompletedTask;
5547
}
56-
57-
Context testContext;
5848
}
5949
}
6050

61-
public class SomeCommand : ICommand
62-
{
63-
}
64-
}
51+
public class SomeCommand : ICommand;
52+
}

src/NServiceBus.AcceptanceTests/Core/Pipeline/When_setting_handler_execution_order.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public async Task Should_call_designated_handler_first()
1616
{
1717
SomeId = Guid.NewGuid().ToString()
1818
})))
19-
.Done(c => c.InterceptingHandlerCalled && c.SagaStarted)
2019
.Run();
2120

2221
Assert.That(context.InterceptingHandlerCalledFirst, Is.True, "The intercepting message handler should be called first");
@@ -27,6 +26,8 @@ public class SagaEndpointContext : ScenarioContext
2726
public bool InterceptingHandlerCalled { get; set; }
2827
public bool InterceptingHandlerCalledFirst { get; set; }
2928
public bool SagaStarted { get; set; }
29+
30+
public void MaybeCompleted() => MarkAsCompleted(InterceptingHandlerCalled, SagaStarted);
3031
}
3132

3233
public class SagaEndpoint : EndpointConfigurationBuilder
@@ -42,6 +43,7 @@ public Task Handle(StartSagaMessage message, IMessageHandlerContext context)
4243
testContext.InterceptingHandlerCalledFirst = true;
4344
}
4445
testContext.SagaStarted = true;
46+
testContext.MaybeCompleted();
4547
return Task.CompletedTask;
4648
}
4749

@@ -60,7 +62,7 @@ public class InterceptingHandler(SagaEndpointContext testContext) : IHandleMessa
6062
public Task Handle(StartSagaMessage message, IMessageHandlerContext context)
6163
{
6264
testContext.InterceptingHandlerCalled = true;
63-
65+
testContext.MaybeCompleted();
6466
return Task.CompletedTask;
6567
}
6668
}

src/NServiceBus.AcceptanceTests/Core/Pipeline/When_setting_ttbr_in_outer_publish.cs

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public async Task Should_not_apply_ttbr_to_inner_publish()
2020
.WithEndpoint<PublisherWithTtbr>(e => e
2121
.When(s => s.Publish(new OuterEvent())))
2222
.WithEndpoint<Subscriber>()
23-
.Done(c => c.OuterEventReceived && c.InnerEventReceived)
2423
.Run();
2524

2625
using (Assert.EnterMultipleScope())
@@ -36,18 +35,18 @@ class Context : ScenarioContext
3635
public bool OuterEventReceived { get; set; }
3736
public DiscardIfNotReceivedBefore OuterEventTtbr { get; set; }
3837
public DiscardIfNotReceivedBefore InnerEventTtbr { get; set; }
38+
39+
public void MaybeCompleted() => MarkAsCompleted(OuterEventReceived, InnerEventReceived);
3940
}
4041

4142
class PublisherWithTtbr : EndpointConfigurationBuilder
4243
{
43-
public PublisherWithTtbr()
44-
{
44+
public PublisherWithTtbr() =>
4545
EndpointSetup<DefaultServer>((c, r) =>
4646
{
4747
c.Pipeline.Register(new InnerPublishBehavior(), "publishes an additional event when publishing an OuterEvent");
4848
c.Pipeline.Register(new TtbrObserver((Context)r.ScenarioContext), "Checks outgoing messages for their TTBR setting");
4949
});
50-
}
5150

5251
// Behavior needs to be in the OutgoingPhysical stage as the TTBR settings are applied in the OutgoingLogical stage
5352
class InnerPublishBehavior : Behavior<IOutgoingPhysicalMessageContext>
@@ -63,15 +62,8 @@ public override async Task Invoke(IOutgoingPhysicalMessageContext context, Func<
6362
}
6463
}
6564

66-
class TtbrObserver : Behavior<IDispatchContext>
65+
class TtbrObserver(Context testContext) : Behavior<IDispatchContext>
6766
{
68-
Context testContext;
69-
70-
public TtbrObserver(Context testContext)
71-
{
72-
this.testContext = testContext;
73-
}
74-
7567
public override Task Invoke(IDispatchContext context, Func<Task> next)
7668
{
7769
var outgoingMessage = context.Extensions.Get<OutgoingLogicalMessage>();
@@ -92,40 +84,28 @@ public override Task Invoke(IDispatchContext context, Func<Task> next)
9284

9385
class Subscriber : EndpointConfigurationBuilder
9486
{
95-
public Subscriber()
96-
{
97-
EndpointSetup<DefaultServer>();
98-
}
87+
public Subscriber() => EndpointSetup<DefaultServer>();
9988

100-
class EventHandler : IHandleMessages<OuterEvent>, IHandleMessages<InnerEvent>
89+
class EventHandler(Context testContext) : IHandleMessages<OuterEvent>, IHandleMessages<InnerEvent>
10190
{
102-
Context testContext;
103-
104-
public EventHandler(Context testContext)
105-
{
106-
this.testContext = testContext;
107-
}
108-
10991
public Task Handle(OuterEvent message, IMessageHandlerContext context)
11092
{
11193
testContext.OuterEventReceived = true;
94+
testContext.MaybeCompleted();
11295
return Task.CompletedTask;
11396
}
11497

11598
public Task Handle(InnerEvent message, IMessageHandlerContext context)
11699
{
117100
testContext.InnerEventReceived = true;
101+
testContext.MaybeCompleted();
118102
return Task.CompletedTask;
119103
}
120104
}
121105
}
122106

123107
[TimeToBeReceived("00:30:00")]
124-
public class OuterEvent : IEvent
125-
{
126-
}
108+
public class OuterEvent : IEvent;
127109

128-
public class InnerEvent : IEvent
129-
{
130-
}
110+
public class InnerEvent : IEvent;
131111
}

src/NServiceBus.AcceptanceTests/Core/Pipeline/When_using_custom_conversation_id.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public async Task Should_apply_custom_conversation_id_when_no_incoming_message()
2222
options.SetHeader(Headers.ConversationId, customConversationId);
2323
return s.Send(new MessageWithConversationId(), options);
2424
}))
25-
.Done(c => !string.IsNullOrEmpty(c.ReceivedConversationId))
2625
.Run();
2726

2827
Assert.That(context.ReceivedConversationId, Is.EqualTo(customConversationId));
@@ -35,29 +34,18 @@ class Context : ScenarioContext
3534

3635
class ReceivingEndpoint : EndpointConfigurationBuilder
3736
{
38-
public ReceivingEndpoint()
39-
{
40-
EndpointSetup<DefaultServer>();
41-
}
37+
public ReceivingEndpoint() => EndpointSetup<DefaultServer>();
4238

43-
public class ConversationIdMessageHandler : IHandleMessages<MessageWithConversationId>
39+
public class ConversationIdMessageHandler(Context testContext) : IHandleMessages<MessageWithConversationId>
4440
{
45-
Context testContext;
46-
47-
public ConversationIdMessageHandler(Context testContext)
48-
{
49-
this.testContext = testContext;
50-
}
51-
5241
public Task Handle(MessageWithConversationId message, IMessageHandlerContext context)
5342
{
5443
testContext.ReceivedConversationId = context.MessageHeaders[Headers.ConversationId];
44+
testContext.MarkAsCompleted();
5545
return Task.CompletedTask;
5646
}
5747
}
5848
}
5949

60-
public class MessageWithConversationId : ICommand
61-
{
62-
}
50+
public class MessageWithConversationId : ICommand;
6351
}

0 commit comments

Comments
 (0)