[Tests] If we have server errors. Mark test as inconclusive. (#7401)
If we are getting errors (500,401..) do not mark a link all test as a failure, but as inconclusive. Update the urls since msdn is giving always a 500. Fixes: https://github.com/xamarin/maccore/issues/2056
This commit is contained in:
Родитель
268f9e8c23
Коммит
ca98880277
|
@ -21,15 +21,27 @@ namespace LinkAnyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool waited;
|
static bool waited;
|
||||||
|
static bool requestError;
|
||||||
|
static HttpStatusCode statusCode;
|
||||||
|
|
||||||
|
|
||||||
// http://blogs.msdn.com/b/csharpfaq/archive/2012/06/26/understanding-a-simple-async-program.aspx
|
// http://blogs.msdn.com/b/csharpfaq/archive/2012/06/26/understanding-a-simple-async-program.aspx
|
||||||
// ref: https://bugzilla.xamarin.com/show_bug.cgi?id=7114
|
// ref: https://bugzilla.xamarin.com/show_bug.cgi?id=7114
|
||||||
static async Task GetWebPageAsync ()
|
static async Task GetWebPageAsync ()
|
||||||
{
|
{
|
||||||
Task<string> getWebPageTask = new HttpClient ().GetStringAsync ("http://msdn.microsoft.com");
|
// do not use GetStringAsync, we are going to miss useful data, such as the resul code
|
||||||
string content = await getWebPageTask;
|
using (var client = new HttpClient ()) {
|
||||||
waited = true;
|
HttpResponseMessage response = await client.GetAsync ("http://example.com");
|
||||||
bool success = !String.IsNullOrEmpty (content);
|
if(!response.IsSuccessStatusCode) {
|
||||||
Assert.IsTrue (success, $"received {content.Length} bytes");
|
requestError = true;
|
||||||
|
statusCode = response.StatusCode;
|
||||||
|
} else {
|
||||||
|
string content = await response.Content.ReadAsStringAsync ();
|
||||||
|
waited = true;
|
||||||
|
bool success = !String.IsNullOrEmpty (content);
|
||||||
|
Assert.IsTrue (success, $"received {content.Length} bytes");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -40,7 +52,11 @@ namespace LinkAnyTest {
|
||||||
// we do not want the async code to get back to the AppKit thread, hanging the process
|
// we do not want the async code to get back to the AppKit thread, hanging the process
|
||||||
SynchronizationContext.SetSynchronizationContext (null);
|
SynchronizationContext.SetSynchronizationContext (null);
|
||||||
GetWebPageAsync ().Wait ();
|
GetWebPageAsync ().Wait ();
|
||||||
Assert.IsTrue (waited, "async/await worked");
|
if (requestError) {
|
||||||
|
Assert.Inconclusive ($"Test cannot be trusted. Issues performing the request. Status code '{statusCode}'");
|
||||||
|
} else {
|
||||||
|
Assert.IsTrue (waited, "async/await worked");
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
SynchronizationContext.SetSynchronizationContext (current_sc);
|
SynchronizationContext.SetSynchronizationContext (current_sc);
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче