|
4 | 4 | namespace Aspire.Hosting.Tests.Helpers; |
5 | 5 | public static class AllocatedEndpointAnnotationTestExtensions |
6 | 6 | { |
7 | | - public static async Task<string> HttpGetPidAsync(this IResourceBuilder<ProjectResource> builder, HttpClient client, string bindingName, CancellationToken cancellationToken) |
| 7 | + public static async Task<string> HttpGetAsync(this IResourceBuilder<ProjectResource> builder, HttpClient client, string bindingName, string path, CancellationToken cancellationToken) |
| 8 | + { |
| 9 | + // We have to get the allocated endpoint each time through the loop |
| 10 | + // because it may not be populated yet by the time we get here. |
| 11 | + var allocatedEndpoint = builder.Resource.Annotations.OfType<AllocatedEndpointAnnotation>().Single(a => a.Name == bindingName); |
| 12 | + var url = $"{allocatedEndpoint.UriString}{path}"; |
| 13 | + |
| 14 | + var response = await client.GetStringAsync(url, cancellationToken); |
| 15 | + return response; |
| 16 | + } |
| 17 | + |
| 18 | + public static async Task<string> WaitForHealthyStatus(this IResourceBuilder<ProjectResource> builder, HttpClient client, string bindingName, CancellationToken cancellationToken) |
8 | 19 | { |
9 | 20 | while (true) |
10 | 21 | { |
11 | 22 | try |
12 | 23 | { |
13 | | - // We have to get the allocated endpoint each time through the loop |
14 | | - // because it may not be populated yet by the time we get here. |
15 | | - var allocatedEndpoint = builder.Resource.Annotations.OfType<AllocatedEndpointAnnotation>().Single(a => a.Name == bindingName); |
16 | | - var url = $"{allocatedEndpoint.UriString}/pid"; |
| 24 | + return await builder.HttpGetAsync(client, bindingName, "/health", cancellationToken); |
| 25 | + } |
| 26 | + catch (HttpRequestException ex) |
| 27 | + { |
| 28 | + Console.WriteLine(ex); |
| 29 | + } |
| 30 | + catch |
| 31 | + { |
| 32 | + await Task.Delay(100, cancellationToken); |
| 33 | + } |
| 34 | + } |
| 35 | + } |
17 | 36 |
|
18 | | - var response = await client.GetStringAsync(url, cancellationToken); |
19 | | - return response; |
| 37 | + public static async Task<string> HttpGetPidAsync(this IResourceBuilder<ProjectResource> builder, HttpClient client, string bindingName, CancellationToken cancellationToken) |
| 38 | + { |
| 39 | + while (true) |
| 40 | + { |
| 41 | + try |
| 42 | + { |
| 43 | + return await builder.HttpGetAsync(client, bindingName, "/pid", cancellationToken); |
20 | 44 | } |
21 | 45 | catch (HttpRequestException ex) |
22 | 46 | { |
|
0 commit comments