Skip to content

Commit

Permalink
test: update BackgroundServiceBaseTests to reflect new changes and fi…
Browse files Browse the repository at this point in the history
…x issue with accessing dispoed variable from outer scope
  • Loading branch information
Per Kops committed Oct 7, 2024
1 parent 0a1c033 commit 5496c61
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions test/Atc.Hosting.Tests/BackgroundServiceBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public async Task Logging_Start_Retry_Cancel_Stop()
new OptionsWrapper<MyServiceOptions>(options),
tcs.Task);

var serviceName = sut.ServiceName;

// Act
await sut.StartAsync(cts.Token);

Expand All @@ -122,23 +124,23 @@ public async Task Logging_Start_Retry_Cancel_Stop()
logger
.Log(
LogLevel.Information,
$"Started worker {sut.ServiceName}. Worker will run with {options.RepeatIntervalSeconds} seconds interval");
$"Started worker {serviceName}. Worker will run with {options.RepeatIntervalSeconds} seconds interval");
logger
.Log(
LogLevel.Warning,
$"Unhandled exception occurred in worker {sut.ServiceName}. Worker will retry after {options.RepeatIntervalSeconds} seconds",
$"Unhandled exception occurred in worker {serviceName}. Worker will retry after {options.RepeatIntervalSeconds} seconds",
exception);
logger
.Log(
LogLevel.Warning,
$"Cancellation invoked for worker {sut.ServiceName}");
$"Cancellation invoked for worker {serviceName}");
logger
.Log(
LogLevel.Information,
$"Stopped worker {sut.ServiceName}");
$"Stopped worker {serviceName}");
});
}

Expand All @@ -165,6 +167,8 @@ public async Task Logging_Start_Exception_Stop()
new OptionsWrapper<MyServiceOptions>(options),
tcs.Task);

var serviceName = sut.ServiceName;

// Act
await sut.StartAsync(cts.Token);

Expand All @@ -177,18 +181,18 @@ public async Task Logging_Start_Exception_Stop()
logger
.Log(
LogLevel.Information,
$"Started worker {sut.ServiceName}. Worker will run with {options.RepeatIntervalSeconds} seconds interval");
$"Started worker {serviceName}. Worker will run with {options.RepeatIntervalSeconds} seconds interval");
logger
.Log(
LogLevel.Error,
$"Unhandled exception occurred in worker {sut.ServiceName}",
$"Unhandled exception occurred in worker {serviceName}",
exception);
logger
.Log(
LogLevel.Information,
$"Stopped worker {sut.ServiceName}");
$"Stopped worker {serviceName}");
});
}

Expand Down Expand Up @@ -217,6 +221,8 @@ public async Task HealthService_Start_Retry_Cancel_Stop()
healthService,
tcs.Task);

var serviceName = sut.ServiceName;

// Act
await sut.StartAsync(cts.Token);

Expand All @@ -226,9 +232,10 @@ public async Task HealthService_Start_Retry_Cancel_Stop()
Received.InOrder(
() =>
{
healthService.SetRunningState(sut.ServiceName, true);
healthService.SetRunningState(sut.ServiceName, true);
healthService.SetRunningState(sut.ServiceName, false);
healthService.SetRunningState(serviceName, true);
healthService.SetRunningState(serviceName, true);
healthService.SetRunningState(serviceName, true);
healthService.SetRunningState(serviceName, false);
});
}

Expand Down Expand Up @@ -257,6 +264,8 @@ public async Task HealthService_Start_Exception_Stop()
healthService,
tcs.Task);

var serviceName = sut.ServiceName;

// Act
await sut.StartAsync(cts.Token);

Expand All @@ -266,9 +275,9 @@ public async Task HealthService_Start_Exception_Stop()
Received.InOrder(
() =>
{
healthService.SetRunningState(sut.ServiceName, true);
healthService.SetRunningState(sut.ServiceName, true);
healthService.SetRunningState(sut.ServiceName, false);
healthService.SetRunningState(serviceName, true);
healthService.SetRunningState(serviceName, true);
healthService.SetRunningState(serviceName, false);
});
}
}

0 comments on commit 5496c61

Please sign in to comment.