[tests] Enable Aspire.Hosting.Testing, and Aspire.Hosting tests that use docker to run on the build machine#4500
Conversation
.. on windows/build-machine on CI.
…ing can work To be specific, `category!=failing` is required.
- this allows the tests to run on the build machine
37f978c to
a85b721
Compare
Aspire.Hosting.Testing, and Aspire.Hosting tests using docker to run on the build machine
| public async Task HttpClientGetTest() | ||
| { | ||
| var httpClient = _app.CreateHttpClient("mywebapp1"); | ||
| await Task.Delay(3000); |
There was a problem hiding this comment.
@ReubenBond @DamianEdwards This PR enables the hosting.testing tests to run on CI. But two tests fail - HttpClientGetTest, and SelectsFirstLaunchProfile with connection refused. And it seems to be due to webapp not being ready. I added a Task.delay to confirm that, and it does work. But what is the correct way to have the test run only once the webapp is ready?
There was a problem hiding this comment.
You should configure the HttpClient with resilience so that it retries. Once #4444 goes in you'll be able to at least wait for the resource to transition to the "Running" state before attempting to send the request, but you still need the retries.
There was a problem hiding this comment.
Should that be added to the Aspire.Hosting.Testing api? I added that as an extension method in the test right now.
There was a problem hiding this comment.
HttpClient default resiliency pipelines aren't composable so we don't add it by default as there'd be no way to remove or modify it. The test templates have code in them that adds resiliency in the test itself.
There was a problem hiding this comment.
Looking at the template, I added this to the TestingAppHost1.AppHost/Program.cs:
builder.Services.ConfigureHttpClientDefaults(http =>
{
http.AddStandardResilienceHandler();
});Aspire.Hosting.Testing, and Aspire.Hosting tests using docker to run on the build machineAspire.Hosting.Testing, and Aspire.Hosting tests that use docker to run on the build machine
| // Relative to this project so that it doesn't changed based on | ||
| // where this code is referenced from. | ||
| var path = Path.Combine(Projects.TestProject_AppHost.ProjectPath, @"..\nodeapp"); | ||
| var path = Path.Combine(Projects.TestProject_AppHost.ProjectPath, "..", "nodeapp"); |
There was a problem hiding this comment.
If the nodeapp fails to start for some reason, then no error is being surfaced. @ReubenBond
… to wait for all the endpoints to get allocated
|
|
||
| var token = new CancellationTokenSource(TimeSpan.FromMinutes(1)).Token; | ||
|
|
||
| await Task.Delay(5000); |
There was a problem hiding this comment.
@ReubenBond I added a delay here because the first client.GetStringAsync($"{httpEndPoint}urls" returned only the http endpoint. But the second invocation got both http, and https. Does this need to wait for all the endpoints to get allocated?
There was a problem hiding this comment.
Should the API surface something (event?) for the endpoints getting allocated?
For this test, we could either use IDistributedApplicationLifecycleHook.AfterEndpointsAllocatedAsync or retry a few times in a loop.
There was a problem hiding this comment.
The tests have an existing class for the hook which I tried to use here - https://gist.github.com/radical/7ef257229178c36f6b72ffd09f7e0b79#file-test-cs-L22-L27
But running the test with CWLs added to print the results from /urls:
Got urls from http://localhost:1234/urls: ["http://localhost:1234"]
Got urls from https://localhost:57048/urls: ["http://localhost:1234","https://localhost:57051"]
The first call is missing the https endpoint. Did the AfterEndpointsAllocatedAsync get invoked too early? Or am I missing something else?
@ReubenBond @DamianEdwards
tests/Aspire.Hosting.Testing.Tests/DistributedApplicationHttpClientExtensionsForTests.cs
Outdated
Show resolved
Hide resolved
tests/TestingAppHost1/TestingAppHost1.AppHost/TestingAppHost1.AppHost.csproj
Outdated
Show resolved
Hide resolved
…AppHost.csproj Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
…build 0.5.3 (dotnet#4598) [main] Update dependencies from microsoft/usvc-apiserver
…t by using httpclient with resilience
tests/Aspire.Components.Common.Tests/RequiresDockerAttribute.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
|
Added some debug bits, so don't merge before that is removed. |
This reverts commit cb206dc.
Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=714974&view=codecoverage-tab |
|
How did the coverage go down here?!
How did the coverage go down here?! |
It could be due to the code coverage reporter not correctly reporting the numbers... ¯\_(ツ)_/¯ You'd need to look into the actual cobertura.xml. https://dev.azure.com/dnceng-public/public/_build/results?buildId=714972&view=logs&j=8cf0092d-1f6c-522b-3c27-9f632d33f4f3&t=b92e38fc-0165-5b68-b32b-2eef48c1a225&l=9 The thing is - the new version was broken and unusable, and I made numerous attempt to contact the team responsible in the past two years but they wouldn't listen.... |

There is work in progress to get tests like
Aspire.Hosting.Testing, andAspire.Hostingrunning on helix. Meanwhile, we can have the tests run on the build machine, at least for linux which hasdockerinstalled, by simply removing/updating the test attributes blocking them.[LocalOnlyFact/Theory]attributes in favor of[RequiresDocker]SkipOnHelixattributes fromSchemaTestsnodeappso it correctly works on linuxMicrosoft Reviewers: Open in CodeFlow