Skip to content

Commit faf0e82

Browse files
committed
Explicitly opt-in to parameter randomisation
Resolves dotnet#9193
1 parent 8119672 commit faf0e82

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

tests/Aspire.Playground.Tests/AppHostTests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public async Task TestEndpointsReturnOk(TestEndpoints testEndpoints)
3535
{
3636
var appHostType = testEndpoints.AppHostType!;
3737
var resourceEndpoints = testEndpoints.ResourceEndpoints!;
38-
var appHost = await DistributedApplicationTestFactory.CreateAsync(appHostType, _testOutput);
38+
var appHost = await DistributedApplicationTestFactory.CreateAsync(appHostType, _testOutput, testEndpoints.EnableParameterRandomisation);
3939
var projects = appHost.Resources.OfType<ProjectResource>();
4040
await using var app = await appHost.BuildAsync();
4141

@@ -144,6 +144,7 @@ public static IList<TestEndpoints> GetAllTestEndpoints()
144144
// whenReady: TestEventHubsAppHost),
145145
new TestEndpoints(typeof(Projects.Redis_AppHost),
146146
resourceEndpoints: new() { { "apiservice", ["/alive", "/health", "/garnet/ping", "/garnet/get", "/garnet/set", "/redis/ping", "/redis/get", "/redis/set", "/valkey/ping", "/valkey/get", "/valkey/set"] } },
147+
enableParameterRandomisation: false,
147148
waitForTexts: [
148149
new ("redis", "Ready to accept connections tcp"),
149150
new ("valkey", "Ready to accept connections tcp"),
@@ -152,11 +153,13 @@ public static IList<TestEndpoints> GetAllTestEndpoints()
152153
]),
153154
new TestEndpoints(typeof(Projects.AzureStorageEndToEnd_AppHost),
154155
resourceEndpoints: new() { { "api", ["/alive", "/health", "/"] } },
156+
enableParameterRandomisation: false,
155157
waitForTexts: [
156158
new ("storage", "Azurite Table service is successfully listening")
157159
]),
158160
new TestEndpoints(typeof(Projects.MilvusPlayground_AppHost),
159161
resourceEndpoints: new() { { "apiservice", ["/alive", "/health", "/create", "/search"] } },
162+
enableParameterRandomisation: false,
160163
waitForTexts: [
161164
new ("milvus", "Milvus Proxy successfully initialized and ready to serve"),
162165
]),
@@ -166,19 +169,22 @@ public static IList<TestEndpoints> GetAllTestEndpoints()
166169
// // "/ef" - disabled due to https://github.com/dotnet/aspire/issues/5415
167170
// waitForTexts: [
168171
// new ("cosmos", "Started$"),
169-
// new ("api", "Application started")
172+
// new("api", "Application started")
170173
// ]),
171174
new TestEndpoints(typeof(Projects.Keycloak_AppHost),
172-
resourceEndpoints: new() { { "apiservice", ["/alive", "/health"] } }),
175+
resourceEndpoints: new() { { "apiservice", ["/alive", "/health"] } },
176+
enableParameterRandomisation: false),
173177
new TestEndpoints(typeof(Projects.Mongo_AppHost),
174178
resourceEndpoints: new() { { "api", ["/alive", "/health", "/"] } },
179+
enableParameterRandomisation: false,
175180
waitForTexts: [
176181
new ("mongo", "Waiting for connections"),
177182
new ("mongo-mongoexpress", "Mongo Express server listening"),
178183
new("api", "Application started.")
179184
]),
180185
new TestEndpoints(typeof(Projects.MySqlDb_AppHost),
181186
resourceEndpoints: new() { { "apiservice", ["/alive", "/health", "/catalog"] } },
187+
enableParameterRandomisation: false,
182188
waitForTexts: [
183189
new ("mysql", "ready for connections.* port: 33060"),
184190
new ("apiservice", "Application started")
@@ -188,12 +194,14 @@ public static IList<TestEndpoints> GetAllTestEndpoints()
188194
{ "api", ["/alive", "/health"] },
189195
{ "backend", ["/alive", "/health"] }
190196
},
197+
enableParameterRandomisation: false,
191198
waitForTexts: [
192199
new ("nats", "Server is ready"),
193200
new("api", "Application started")
194201
]),
195202
new TestEndpoints(typeof(Projects.ParameterEndToEnd_AppHost),
196203
resourceEndpoints: new() { { "api", ["/", "/alive", "/health"] } },
204+
enableParameterRandomisation: false,
197205
waitForTexts: [
198206
new ("sql", "SQL Server is now ready for client connections."),
199207
]),
@@ -202,6 +210,7 @@ public static IList<TestEndpoints> GetAllTestEndpoints()
202210
// Invoking "/" first as that *creates* the databases
203211
{ "api", ["/", "/alive", "/health"] }
204212
},
213+
enableParameterRandomisation: false,
205214
waitForTexts: [
206215
new ("pg1", "PostgreSQL init process complete; ready for start up"),
207216
new ("pg2", "PostgreSQL init process complete; ready for start up"),
@@ -213,26 +222,30 @@ public static IList<TestEndpoints> GetAllTestEndpoints()
213222
]),
214223
new TestEndpoints(typeof(Projects.ProxylessEndToEnd_AppHost),
215224
resourceEndpoints: new() { { "api", ["/alive", "/health", "/redis"] } },
225+
enableParameterRandomisation: false,
216226
waitForTexts: [
217227
new ("redis", "Ready to accept connections"),
218228
new("api", "Application started"),
219229
new("api2", "Application started")
220230
]),
221231
new TestEndpoints(typeof(Projects.Qdrant_AppHost),
222232
resourceEndpoints: new() { { "apiservice", ["/alive", "/health"] } },
233+
enableParameterRandomisation: false,
223234
waitForTexts: [
224235
new ("qdrant", "Qdrant HTTP listening"),
225236
new ("apiservice", "Application started")
226237
]),
227238
new TestEndpoints(typeof(Projects.Seq_AppHost),
228239
resourceEndpoints: new() { { "api", ["/alive", "/health"] } },
240+
enableParameterRandomisation: false,
229241
waitForTexts: [
230242
new ("seq", "Seq listening"),
231243
new ("api", "Application started")
232244
]),
233245
// Invoke "/" first to create the databases
234246
new TestEndpoints(typeof(Projects.SqlServerEndToEnd_AppHost),
235247
resourceEndpoints: new() { { "api", ["/", "/alive", "/health"] } },
248+
enableParameterRandomisation: false,
236249
waitForTexts: [
237250
new ("sql1", "SQL Server is now ready for client connections"),
238251
new ("sql2", "SQL Server is now ready for client connections"),
@@ -242,6 +255,7 @@ public static IList<TestEndpoints> GetAllTestEndpoints()
242255
{ "catalogdbapp", ["/alive", "/health"] },
243256
{ "frontend", ["/alive", "/health"] }
244257
},
258+
enableParameterRandomisation: false,
245259
waitForTexts: [
246260
new ("messaging", "started TCP listener"),
247261
new ("basketcache", "Ready to accept connections"),
@@ -279,15 +293,19 @@ public class TestEndpoints
279293
{
280294
public TestEndpoints(Type appHostType,
281295
Dictionary<string, List<string>> resourceEndpoints,
296+
bool enableParameterRandomisation,
282297
List<ReadyStateText>? waitForTexts = null)
283298
{
284299
AppHostType = appHostType;
285300
ResourceEndpoints = resourceEndpoints;
286301
WaitForTexts = waitForTexts;
302+
EnableParameterRandomisation = enableParameterRandomisation;
287303
}
288304

289305
public Type AppHostType { get; set; }
290306

307+
public bool EnableParameterRandomisation { get; set; }
308+
291309
public List<ResourceWait>? WaitForResources { get; set; }
292310

293311
public List<ReadyStateText>? WaitForTexts { get; set; }

tests/Aspire.Playground.Tests/Infrastructure/DistributedApplicationTestFactory.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal static class DistributedApplicationTestFactory
1515
/// <summary>
1616
/// Creates an <see cref="IDistributedApplicationTestingBuilder"/> for the specified app host assembly.
1717
/// </summary>
18-
public static async Task<IDistributedApplicationTestingBuilder> CreateAsync(Type appHostProgramType, ITestOutputHelper? testOutput)
18+
public static async Task<IDistributedApplicationTestingBuilder> CreateAsync(Type appHostProgramType, ITestOutputHelper? testOutput, bool enableParameterRandomisation)
1919
{
2020
var builder = await DistributedApplicationTestingBuilder.CreateAsync(appHostProgramType);
2121

@@ -24,7 +24,11 @@ public static async Task<IDistributedApplicationTestingBuilder> CreateAsync(Type
2424
// always override.
2525
builder.Services.AddLifecycleHook<ContainerRegistryHook>();
2626

27-
builder.WithRandomParameterValues();
27+
if (enableParameterRandomisation)
28+
{
29+
builder.WithRandomParameterValues();
30+
}
31+
2832
builder.WithRandomVolumeNames();
2933

3034
builder.Services.AddLogging(logging =>

tests/Aspire.Playground.Tests/ProjectSpecificTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ProjectSpecificTests(ITestOutputHelper _testOutput)
1919
[QuarantinedTest("https://github.com/dotnet/aspire/issues/9171")]
2020
public async Task WithDockerfileTest()
2121
{
22-
var appHost = await DistributedApplicationTestFactory.CreateAsync(typeof(Projects.WithDockerfile_AppHost), _testOutput);
22+
var appHost = await DistributedApplicationTestFactory.CreateAsync(typeof(Projects.WithDockerfile_AppHost), _testOutput, enableParameterRandomisation: false);
2323
await using var app = await appHost.BuildAsync();
2424

2525
await app.StartAsync();
@@ -36,7 +36,7 @@ await app.WaitForTextAsync($"I'm Batman. - Batman")
3636
[QuarantinedTest("https://github.com/dotnet/aspire/issues/6867")]
3737
public async Task KafkaTest()
3838
{
39-
var appHost = await DistributedApplicationTestFactory.CreateAsync(typeof(Projects.KafkaBasic_AppHost), _testOutput);
39+
var appHost = await DistributedApplicationTestFactory.CreateAsync(typeof(Projects.KafkaBasic_AppHost), _testOutput, enableParameterRandomisation: false);
4040
await using var app = await appHost.BuildAsync();
4141

4242
await app.StartAsync();
@@ -62,7 +62,7 @@ await WaitForAllTextAsync(app,
6262
[RequiresTools(["func"])]
6363
public async Task AzureFunctionsTest()
6464
{
65-
var appHost = await DistributedApplicationTestFactory.CreateAsync(typeof(Projects.AzureFunctionsEndToEnd_AppHost), _testOutput);
65+
var appHost = await DistributedApplicationTestFactory.CreateAsync(typeof(Projects.AzureFunctionsEndToEnd_AppHost), _testOutput, enableParameterRandomisation: false);
6666
await using var app = await appHost.BuildAsync();
6767

6868
await app.StartAsync();

0 commit comments

Comments
 (0)