Skip to content

Commit 58877b8

Browse files
committed
Add cancel on start to the wathdog for completeness
1 parent aa3557a commit 58877b8

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/ServiceControl.Audit/Auditing/AuditIngestion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ async Task OnMessage(MessageContext messageContext, CancellationToken cancellati
231231

232232
public override async Task StartAsync(CancellationToken cancellationToken)
233233
{
234-
await watchdog.Start(() => applicationLifetime.StopApplication());
234+
await watchdog.Start(() => applicationLifetime.StopApplication(), cancellationToken);
235235
await base.StartAsync(cancellationToken);
236236
}
237237

src/ServiceControl.Infrastructure.Tests/WatchdogTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace ServiceControl.Infrastructure.Tests
22
{
33
using System;
4+
using System.Threading;
45
using System.Threading.Tasks;
56
using NServiceBus.Logging;
67
using NUnit.Framework;
@@ -27,7 +28,7 @@ public async Task It_shuts_down_gracefully()
2728
return Task.CompletedTask;
2829
}, x => { }, () => { }, TimeSpan.FromSeconds(1), log);
2930

30-
await dog.Start(() => { });
31+
await dog.Start(() => { }, CancellationToken.None);
3132

3233
await started.Task;
3334

@@ -48,7 +49,7 @@ public async Task When_stop_fails_it_reports_the_failure()
4849
return Task.CompletedTask;
4950
}, token => throw new Exception("Simulated"), x => lastFailure = x, () => lastFailure = null, TimeSpan.FromSeconds(1), log);
5051

51-
await dog.Start(() => { });
52+
await dog.Start(() => { }, CancellationToken.None);
5253

5354
await started.Task;
5455

@@ -83,7 +84,7 @@ public async Task On_failure_triggers_stopping()
8384
return Task.CompletedTask;
8485
}, x => { }, () => { }, TimeSpan.FromSeconds(1), log);
8586

86-
await dog.Start(() => { });
87+
await dog.Start(() => { }, CancellationToken.None);
8788

8889
await started.Task;
8990

@@ -125,7 +126,7 @@ public async Task When_first_start_attempt_works_it_recovers_from_further_errors
125126
return Task.CompletedTask;
126127
}, token => Task.CompletedTask, x => lastFailure = x, () => lastFailure = null, TimeSpan.FromSeconds(1), log);
127128

128-
await dog.Start(() => { });
129+
await dog.Start(() => { }, CancellationToken.None);
129130

130131
await recoveredFromError.Task;
131132

@@ -144,7 +145,7 @@ public async Task When_first_start_attempt_fails_onFailedOnStartup_is_called()
144145

145146
var dog = new Watchdog("test process", token => throw new Exception("Simulated"), token => Task.CompletedTask, x => lastFailure = x, () => lastFailure = null, TimeSpan.FromSeconds(1), log);
146147

147-
await dog.Start(() => { onStartupFailureCalled.SetResult(true); });
148+
await dog.Start(() => { onStartupFailureCalled.SetResult(true); }, CancellationToken.None);
148149

149150
await onStartupFailureCalled.Task;
150151

src/ServiceControl.Infrastructure/Watchdog.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Task OnFailure(string failure)
4141
return ensureStopped(shutdownTokenSource.Token);
4242
}
4343

44-
public Task Start(Action onFailedOnStartup)
44+
public Task Start(Action onFailedOnStartup, CancellationToken cancellationToken)
4545
{
4646
watchdog = Task.Run(async () =>
4747
{
@@ -88,7 +88,8 @@ public Task Start(Action onFailedOnStartup)
8888
//Ignore, no need to log cancellation of delay
8989
}
9090
}
91-
});
91+
}, cancellationToken);
92+
9293
return Task.CompletedTask;
9394
}
9495

src/ServiceControl/Operations/ErrorIngestion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public ErrorIngestion(
7272

7373
public override async Task StartAsync(CancellationToken cancellationToken)
7474
{
75-
await watchdog.Start(() => applicationLifetime.StopApplication());
75+
await watchdog.Start(() => applicationLifetime.StopApplication(), cancellationToken);
7676
await base.StartAsync(cancellationToken);
7777
}
7878

0 commit comments

Comments
 (0)