6
6
using Aspire . Hosting . ApplicationModel ;
7
7
using Aspire . Hosting . Tests . Utils ;
8
8
using Aspire . Hosting . Utils ;
9
+ using Microsoft . AspNetCore . InternalTesting ;
9
10
using Microsoft . EntityFrameworkCore ;
10
11
using Microsoft . EntityFrameworkCore . Infrastructure ;
11
12
using Microsoft . EntityFrameworkCore . Storage ;
@@ -27,7 +28,7 @@ public class MySqlFunctionalTests(ITestOutputHelper testOutputHelper)
27
28
[ RequiresDocker ]
28
29
public async Task VerifyWaitForOnMySqlBlocksDependentResources ( )
29
30
{
30
- var cts = new CancellationTokenSource ( TimeSpan . FromMinutes ( 3 ) ) ;
31
+ using var cts = new CancellationTokenSource ( TestConstants . ExtraLongTimeoutTimeSpan ) ;
31
32
using var builder = TestDistributedApplicationBuilder . CreateWithTestContainerRegistry ( testOutputHelper ) ;
32
33
33
34
var healthCheckTcs = new TaskCompletionSource < HealthCheckResult > ( ) ;
@@ -58,14 +59,14 @@ public async Task VerifyWaitForOnMySqlBlocksDependentResources()
58
59
59
60
await pendingStart ;
60
61
61
- await app . StopAsync ( ) ;
62
+ await app . StopAsync ( cts . Token ) ;
62
63
}
63
64
64
65
[ Fact ]
65
66
[ RequiresDocker ]
66
67
public async Task VerifyMySqlResource ( )
67
68
{
68
- var cts = new CancellationTokenSource ( TimeSpan . FromMinutes ( 5 ) ) ;
69
+ using var cts = new CancellationTokenSource ( TestConstants . ExtraLongTimeoutTimeSpan * 2 ) ;
69
70
var pipeline = new ResiliencePipelineBuilder ( )
70
71
. AddRetry ( new ( ) { MaxRetryAttempts = 10 , BackoffType = DelayBackoffType . Linear , Delay = TimeSpan . FromSeconds ( 2 ) , ShouldHandle = new PredicateBuilder ( ) . Handle < MySqlException > ( ) } )
71
72
. Build ( ) ;
@@ -79,9 +80,9 @@ public async Task VerifyMySqlResource()
79
80
80
81
using var app = builder . Build ( ) ;
81
82
82
- await app . StartAsync ( ) ;
83
+ await app . StartAsync ( cts . Token ) ;
83
84
84
- await app . WaitForTextAsync ( s_mySqlReadyText ) . WaitAsync ( TimeSpan . FromMinutes ( 2 ) ) ;
85
+ await app . WaitForTextAsync ( s_mySqlReadyText , cts . Token ) . WaitAsync ( cts . Token ) ;
85
86
86
87
var hb = Host . CreateApplicationBuilder ( ) ;
87
88
@@ -94,7 +95,7 @@ public async Task VerifyMySqlResource()
94
95
95
96
using var host = hb . Build ( ) ;
96
97
97
- await host . StartAsync ( ) ;
98
+ await host . StartAsync ( cts . Token ) ;
98
99
await pipeline . ExecuteAsync ( async token =>
99
100
{
100
101
using var connection = host . Services . GetRequiredService < MySqlConnection > ( ) ;
@@ -119,7 +120,7 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume)
119
120
string ? volumeName = null ;
120
121
string ? bindMountPath = null ;
121
122
122
- var cts = new CancellationTokenSource ( TimeSpan . FromMinutes ( 5 ) ) ;
123
+ using var cts = new CancellationTokenSource ( TestConstants . ExtraLongTimeoutTimeSpan * 2 ) ;
123
124
var pipeline = new ResiliencePipelineBuilder ( )
124
125
. AddRetry ( new ( ) { MaxRetryAttempts = 10 , BackoffType = DelayBackoffType . Linear , Delay = TimeSpan . FromSeconds ( 2 ) } )
125
126
. Build ( ) ;
@@ -151,9 +152,9 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume)
151
152
152
153
using ( var app = builder1 . Build ( ) )
153
154
{
154
- await app . StartAsync ( ) ;
155
+ await app . StartAsync ( cts . Token ) ;
155
156
156
- await app . WaitForTextAsync ( s_mySqlReadyText ) . WaitAsync ( TimeSpan . FromMinutes ( 2 ) ) ;
157
+ await app . WaitForTextAsync ( s_mySqlReadyText , cts . Token ) . WaitAsync ( cts . Token ) ;
157
158
158
159
try
159
160
{
@@ -168,7 +169,7 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume)
168
169
169
170
using ( var host = hb . Build ( ) )
170
171
{
171
- await host . StartAsync ( ) ;
172
+ await host . StartAsync ( cts . Token ) ;
172
173
173
174
// Wait until the database is available
174
175
await pipeline . ExecuteAsync ( async token =>
@@ -199,7 +200,7 @@ await pipeline.ExecuteAsync(async token =>
199
200
finally
200
201
{
201
202
// Stops the container, or the Volume/mount would still be in use
202
- await app . StopAsync ( ) ;
203
+ await app . StopAsync ( cts . Token ) ;
203
204
}
204
205
}
205
206
@@ -220,24 +221,24 @@ await pipeline.ExecuteAsync(async token =>
220
221
221
222
using ( var app = builder2 . Build ( ) )
222
223
{
223
- await app . StartAsync ( ) ;
224
+ await app . StartAsync ( cts . Token ) ;
224
225
225
- await app . WaitForTextAsync ( s_mySqlReadyText ) . WaitAsync ( TimeSpan . FromMinutes ( 2 ) ) ;
226
+ await app . WaitForTextAsync ( s_mySqlReadyText , cts . Token ) . WaitAsync ( cts . Token ) ;
226
227
227
228
try
228
229
{
229
230
var hb = Host . CreateApplicationBuilder ( ) ;
230
231
231
232
hb . Configuration . AddInMemoryCollection ( new Dictionary < string , string ? >
232
233
{
233
- [ $ "ConnectionStrings:{ db2 . Resource . Name } "] = await db2 . Resource . ConnectionStringExpression . GetValueAsync ( default )
234
+ [ $ "ConnectionStrings:{ db2 . Resource . Name } "] = await db2 . Resource . ConnectionStringExpression . GetValueAsync ( cts . Token )
234
235
} ) ;
235
236
236
237
hb . AddMySqlDataSource ( db2 . Resource . Name ) ;
237
238
238
239
using ( var host = hb . Build ( ) )
239
240
{
240
- await host . StartAsync ( ) ;
241
+ await host . StartAsync ( cts . Token ) ;
241
242
242
243
// Wait until the database is available
243
244
await pipeline . ExecuteAsync ( async token =>
@@ -264,7 +265,7 @@ await pipeline.ExecuteAsync(async token =>
264
265
finally
265
266
{
266
267
// Stops the container, or the Volume/mount would still be in use
267
- await app . StopAsync ( ) ;
268
+ await app . StopAsync ( cts . Token ) ;
268
269
}
269
270
}
270
271
@@ -296,7 +297,7 @@ public async Task VerifyWithInitBindMount()
296
297
{
297
298
// Creates a script that should be executed when the container is initialized.
298
299
299
- var cts = new CancellationTokenSource ( TimeSpan . FromMinutes ( 5 ) ) ;
300
+ using var cts = new CancellationTokenSource ( TestConstants . ExtraLongTimeoutTimeSpan * 2 ) ;
300
301
var pipeline = new ResiliencePipelineBuilder ( )
301
302
. AddRetry ( new ( ) { MaxRetryAttempts = 10 , BackoffType = DelayBackoffType . Linear , Delay = TimeSpan . FromSeconds ( 2 ) , ShouldHandle = new PredicateBuilder ( ) . Handle < MySqlException > ( ) } )
302
303
. Build ( ) ;
@@ -323,22 +324,22 @@ public async Task VerifyWithInitBindMount()
323
324
324
325
using var app = builder . Build ( ) ;
325
326
326
- await app . StartAsync ( ) ;
327
+ await app . StartAsync ( cts . Token ) ;
327
328
328
- await app . WaitForTextAsync ( s_mySqlReadyText ) . WaitAsync ( TimeSpan . FromMinutes ( 2 ) ) ;
329
+ await app . WaitForTextAsync ( s_mySqlReadyText , cts . Token ) . WaitAsync ( cts . Token ) ;
329
330
330
331
var hb = Host . CreateApplicationBuilder ( ) ;
331
332
332
333
hb . Configuration . AddInMemoryCollection ( new Dictionary < string , string ? >
333
334
{
334
- [ $ "ConnectionStrings:{ db . Resource . Name } "] = await db . Resource . ConnectionStringExpression . GetValueAsync ( default )
335
+ [ $ "ConnectionStrings:{ db . Resource . Name } "] = await db . Resource . ConnectionStringExpression . GetValueAsync ( cts . Token )
335
336
} ) ;
336
337
337
338
hb . AddMySqlDataSource ( db . Resource . Name ) ;
338
339
339
340
using var host = hb . Build ( ) ;
340
341
341
- await host . StartAsync ( ) ;
342
+ await host . StartAsync ( cts . Token ) ;
342
343
343
344
// Wait until the database is available
344
345
await pipeline . ExecuteAsync ( async token =>
@@ -380,7 +381,7 @@ await pipeline.ExecuteAsync(async token =>
380
381
[ QuarantinedTest ( "https://github.com/dotnet/aspire/issues/7340" ) ]
381
382
public async Task VerifyEfMySql ( )
382
383
{
383
- var cts = new CancellationTokenSource ( TimeSpan . FromMinutes ( 5 ) ) ;
384
+ using var cts = new CancellationTokenSource ( TestConstants . ExtraLongTimeoutTimeSpan * 2 ) ;
384
385
var pipeline = new ResiliencePipelineBuilder ( )
385
386
. AddRetry ( new ( ) { MaxRetryAttempts = 10 , BackoffType = DelayBackoffType . Linear , Delay = TimeSpan . FromSeconds ( 1 ) , ShouldHandle = new PredicateBuilder ( ) . Handle < MySqlException > ( ) } )
386
387
. Build ( ) ;
@@ -394,22 +395,22 @@ public async Task VerifyEfMySql()
394
395
395
396
using var app = builder . Build ( ) ;
396
397
397
- await app . StartAsync ( ) ;
398
+ await app . StartAsync ( cts . Token ) ;
398
399
399
- await app . WaitForTextAsync ( s_mySqlReadyText ) . WaitAsync ( TimeSpan . FromMinutes ( 2 ) ) ;
400
+ await app . WaitForTextAsync ( s_mySqlReadyText , cts . Token ) . WaitAsync ( cts . Token ) ;
400
401
401
402
var hb = Host . CreateApplicationBuilder ( ) ;
402
403
403
404
hb . Configuration . AddInMemoryCollection ( new Dictionary < string , string ? >
404
405
{
405
- [ $ "ConnectionStrings:{ db . Resource . Name } "] = await db . Resource . ConnectionStringExpression . GetValueAsync ( default )
406
+ [ $ "ConnectionStrings:{ db . Resource . Name } "] = await db . Resource . ConnectionStringExpression . GetValueAsync ( cts . Token )
406
407
} ) ;
407
408
408
409
hb . AddMySqlDbContext < TestDbContext > ( db . Resource . Name ) ;
409
410
410
411
using var host = hb . Build ( ) ;
411
412
412
- await host . StartAsync ( ) ;
413
+ await host . StartAsync ( cts . Token ) ;
413
414
414
415
// Wait until the database is available
415
416
await pipeline . ExecuteAsync ( async token =>
@@ -453,7 +454,7 @@ public async Task MySql_WithPersistentLifetime_ReusesContainers(bool useMultiple
453
454
// it generates and mounts a config.user.inc.php file instead of using environment variables.
454
455
// For this reason we need to test with and without multiple instances to cover both scenarios.
455
456
456
- var cts = new CancellationTokenSource ( TimeSpan . FromMinutes ( 10 ) ) ;
457
+ using var cts = new CancellationTokenSource ( TestConstants . ExtraLongTimeoutTimeSpan * 2 ) ;
457
458
458
459
// Use the same path for both runs
459
460
var aspireStorePath = Directory . CreateTempSubdirectory ( ) . FullName ;
@@ -511,7 +512,7 @@ public async Task MySql_WithPersistentLifetime_ReusesContainers(bool useMultiple
511
512
resourceEvent = await rns . WaitForResourceHealthyAsync ( "resource-phpmyadmin" , cts . Token ) ;
512
513
var phpMyAdminId = GetContainerId ( resourceEvent ) ;
513
514
514
- await app . StopAsync ( cts . Token ) . WaitAsync ( TimeSpan . FromMinutes ( 1 ) , cts . Token ) ;
515
+ await app . StopAsync ( cts . Token ) . WaitAsync ( cts . Token ) ;
515
516
516
517
return [ mySqlId , mySqlId2 , phpMyAdminId ] ;
517
518
}
0 commit comments