|
1 | 1 | namespace BervProject.WebApi.Integration.Test.Fixtures; |
2 | 2 |
|
3 | | -using Aspire.Hosting; |
4 | | -using Aspire.Hosting.ApplicationModel; |
5 | 3 | using Aspire.Hosting.Testing; |
6 | | -using Microsoft.Extensions.DependencyInjection; |
7 | 4 | using Projects; |
8 | 5 |
|
9 | 6 | public class WebAppFixture : IAsyncLifetime |
10 | 7 | { |
| 8 | + // CI environments are slower — use a longer timeout when running in CI |
| 9 | + private static readonly TimeSpan DefaultTimeout = |
| 10 | + Environment.GetEnvironmentVariable("CI") is not null |
| 11 | + ? TimeSpan.FromMinutes(10) |
| 12 | + : TimeSpan.FromMinutes(3); |
| 13 | + |
11 | 14 | private DistributedApplication? _app; |
12 | 15 |
|
13 | 16 | public async Task InitializeAsync() |
14 | 17 | { |
15 | 18 | var appHost = await DistributedApplicationTestingBuilder |
16 | 19 | .CreateAsync<BervProject_WebApi_Boilerplate_AppHost>(); |
17 | 20 |
|
18 | | - _app = await appHost.BuildAsync(); |
19 | | - await _app.StartAsync(); |
| 21 | + _app = await appHost.BuildAsync() |
| 22 | + .WaitAsync(DefaultTimeout); |
| 23 | + |
| 24 | + await _app.StartAsync() |
| 25 | + .WaitAsync(DefaultTimeout); |
20 | 26 |
|
21 | | - var rns = _app.Services.GetRequiredService<ResourceNotificationService>(); |
22 | | - var rcs = _app.Services.GetRequiredService<ResourceCommandService>(); |
| 27 | + using var cts = new CancellationTokenSource(DefaultTimeout); |
23 | 28 |
|
24 | | - // migrations uses WithExplicitStart — trigger the "start" command manually |
25 | | - await rcs.ExecuteCommandAsync("migrations", "start"); |
26 | | - await rns.WaitForResourceAsync("migrations", KnownResourceStates.Finished); |
27 | | - await rns.WaitForResourceHealthyAsync("apiservice"); |
| 29 | + // migrations has WithExplicitStart — trigger it via ResourceCommands then wait for |
| 30 | + // it to finish. apiservice has .WaitForCompletion(migration), so it won't start until |
| 31 | + // migrations is Finished. |
| 32 | + await _app.ResourceCommands.ExecuteCommandAsync("migrations", "start", cts.Token); |
| 33 | + await _app.ResourceNotifications |
| 34 | + .WaitForResourceAsync("migrations", KnownResourceStates.Finished, cts.Token); |
| 35 | + await _app.ResourceNotifications |
| 36 | + .WaitForResourceHealthyAsync("apiservice", cts.Token); |
28 | 37 | } |
29 | 38 |
|
30 | 39 | public async Task DisposeAsync() |
|
0 commit comments