Skip to content

Commit 224ad26

Browse files
[tests] ignore network errors in CustomLinkDescriptionPreserve (#9915)
Context: 455ec0a Context: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=11188869&view=ms.vss-test-web.build-test-results-tab&runId=124545813&resultId=100000&paneView=debug The `InstallAndRunTests.CustomLinkDescriptionPreserve()` test can randomly fail with: I XALINKERTESTS: [FAIL] HttpClientTest.Post FAILED: System.Net.Http.HttpRequestException: net_http_message_not_success_statuscode_reason, 503, Service Temporarily Unavailable I XALINKERTESTS: at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() I XALINKERTESTS: at HttpClientTest.Post() I updated `HttpClientTest.Post()` to print an `[IGNORE]` result when it encounters HTTP-500 errors (.InternalServerError, .BadGateway, .ServiceUnavailable, .GatewayTimeout), similar to 455ec0a.
1 parent b11471b commit 224ad26

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

tests/MSBuildDeviceIntegration/Resources/LinkDescTest/HttpClientTest.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
using System;
22
using System.Text;
3+
using System.Net;
34
using System.Net.Http;
45

56
public class HttpClientTest
67
{
78
// [Test]
89
public static string Post ()
910
{
10-
try
11-
{
11+
try {
1212
var client = new HttpClient ();
1313
var data = new StringContent ("{\"foo\": \"bar\" }", Encoding.UTF8, "application/json");
1414
var response = client.PostAsync ("https://httpbin.org/post", data).Result;
15+
switch (response.StatusCode) {
16+
case HttpStatusCode.InternalServerError:
17+
case HttpStatusCode.BadGateway:
18+
case HttpStatusCode.ServiceUnavailable:
19+
case HttpStatusCode.GatewayTimeout:
20+
return $"[IGNORE] {nameof (HttpClientTest)}.{nameof (Post)} {response.StatusCode}";
21+
}
1522
response.EnsureSuccessStatusCode ();
1623
var json = response.Content.ReadAsStringAsync ().Result;
1724
return $"[PASS] {nameof (HttpClientTest)}.{nameof (Post)}";
18-
}
19-
catch (Exception ex)
20-
{
25+
} catch (Exception ex) {
2126
return $"[FAIL] {nameof (HttpClientTest)}.{nameof (Post)} FAILED: {ex}";
2227
}
2328
}

0 commit comments

Comments
 (0)