Skip to content

Commit 07940f4

Browse files
committed
Fix race condition in WebHooks integration specs causing UnknownReactorId
The WebhookReactor is a kernel-side system reactor registered asynchronously via ReactorsReactor processing EventStoreAdded. On early test contexts, the DiscoverAndRegister call had not yet completed when GetHandlerById was invoked, causing UnknownReactorId to be thrown. Retry GetHandlerById with a 30-second timeout (polling every 100ms) in the shared Register() helper so all contexts wait for the reactor to become available. Also remove the duplicate GetHandlerById + WaitTillReachesEventSequenceNumber calls in with_headers_and_subscribed_event_type_is_appended, which were already performed inside Register().
1 parent 1057ad6 commit 07940f4

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

Integration/DotNET.InProcess/for_Webhooks/given/webhook_states_after_registering.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,24 @@ protected async Task Register(params (WebhookId, WebhookTargetUrl, Action<IWebho
1919
await Webhooks.Register(id, targetUrl, configure);
2020
}
2121

22-
var webhookReactor = EventStore.Reactors.GetHandlerById("$system.Cratis.Chronicle.Observation.Webhooks.WebhookReactor");
22+
// The WebhookReactor is a kernel-side system reactor registered asynchronously
23+
// via ReactorsReactor processing EventStoreAdded. Retry until it is available.
24+
IReactorHandler? webhookReactor = null;
25+
var deadline = DateTimeOffset.UtcNow.AddSeconds(30);
26+
while (DateTimeOffset.UtcNow < deadline)
27+
{
28+
try
29+
{
30+
webhookReactor = EventStore.Reactors.GetHandlerById("$system.Cratis.Chronicle.Observation.Webhooks.WebhookReactor");
31+
break;
32+
}
33+
catch (UnknownReactorId)
34+
{
35+
await Task.Delay(100);
36+
}
37+
}
38+
39+
webhookReactor.ShouldNotBeNull();
2340
await webhookReactor.WaitTillReachesEventSequenceNumber(EventSequenceNumber.First);
2441

2542
StoredWebhooks = await EventStoreStorage.Webhooks.GetAll();

Integration/DotNET.InProcess/for_Webhooks/when_registering/with_headers_and_subscribed_event_type_is_appended.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Copyright (c) Cratis. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using Cratis.Chronicle.Events;
54
using Cratis.Chronicle.EventSequences;
6-
using Cratis.Chronicle.Reactors;
75
using Cratis.Chronicle.Webhooks;
86
using context = Cratis.Chronicle.InProcess.Integration.for_Webhooks.when_registering.with_headers_and_subscribed_event_type_is_appended.context;
97

@@ -21,9 +19,6 @@ public async Task Establish()
2119
{
2220
await Register(
2321
(WebhookId, TargetUrl, builder => builder.WithEventType<SomeEvent>().WithHeader("some-header", "some-value")));
24-
25-
var webhookReactor = EventStore.Reactors.GetHandlerById("$system.Cratis.Chronicle.Observation.Webhooks.WebhookReactor");
26-
await webhookReactor.WaitTillReachesEventSequenceNumber(EventSequenceNumber.First);
2722
}
2823

2924
public async Task Because()

0 commit comments

Comments
 (0)