Reduce probability of MultipleAppTests failure (#1365)
- Decrease false-positive failure rate from 1 in 1,000 to 1 in 1,000,000 - Addresses #1350
This commit is contained in:
parent
9b5e34e197
commit
2f4172e7e7
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
|
@ -25,7 +26,19 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|||
[ConditionalTheory]
|
||||
[InlineData(AncmVersion.AspNetCoreModule)]
|
||||
[InlineData(AncmVersion.AspNetCoreModuleV2)]
|
||||
public async Task Startup(AncmVersion ancmVersion)
|
||||
public Task Startup(AncmVersion ancmVersion)
|
||||
{
|
||||
// ANCM v1 currently does *not* retry if an app fails to start the first time due to a port collision.
|
||||
// So, this test is expected to fail on v1 approximately 1 in 1,000 times (probably of at least one collision
|
||||
// when 10 sites choose a random port from the range 1025-48000). Adding one retry should reduce the failure
|
||||
// rate from 1 in 1,000 to 1 in 1,000,000. The previous product code (with "srand(GetTickCount())") should still
|
||||
// fail the test reliably.
|
||||
// https://github.com/aspnet/IISIntegration/issues/1350
|
||||
//
|
||||
// ANCM v2 does retry on port collisions, so no retries should be required.
|
||||
var attempts = (ancmVersion == AncmVersion.AspNetCoreModule) ? 2 : 1;
|
||||
|
||||
return Retry(async () =>
|
||||
{
|
||||
const int numApps = 10;
|
||||
|
||||
|
|
@ -61,6 +74,28 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|||
Assert.Equal("Hello World", responseText);
|
||||
}
|
||||
}
|
||||
},
|
||||
attempts: attempts);
|
||||
}
|
||||
|
||||
private async Task Retry(Func<Task> func, int attempts)
|
||||
{
|
||||
var exceptions = new List<Exception>();
|
||||
|
||||
for (var attempt = 0; attempt < attempts; attempt++)
|
||||
{
|
||||
try
|
||||
{
|
||||
await func();
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
exceptions.Add(e);
|
||||
}
|
||||
}
|
||||
|
||||
throw new AggregateException(exceptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue