Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,35 @@ public void CancelRequestViaProxy ()
Timeout = TimeSpan.FromMilliseconds (1)
};

try {
var restRequest = new HttpRequestMessage {
Method = HttpMethod.Post,
RequestUri = new Uri ("foo", UriKind.Relative),
Content = new StringContent ("", null, "application/json")
};
var restRequest = new HttpRequestMessage {
Method = HttpMethod.Post,
RequestUri = new Uri ("foo", UriKind.Relative),
Content = new StringContent ("", null, "application/json")
};

httpClient.PostAsync (restRequest.RequestUri, restRequest.Content).Wait (WaitTimeout);
Assert.Fail ("#1");
var task = httpClient.PostAsync (restRequest.RequestUri, restRequest.Content);
bool completed = false;
try {
completed = task.Wait (WaitTimeout);
} catch (AggregateException e) {
Console.WriteLine ("CancelRequestViaProxy exception: {0}", e);
Assert.IsTrue (e.InnerException is TaskCanceledException, "#2; threw: {0}", e);
Assert.IsTrue (e.InnerException is TaskCanceledException, $"Expected TaskCanceledException but got: {e.InnerException?.GetType ().FullName}: {e.InnerException?.Message}");
return; // Test passed - got expected exception
}

// If we reach here, the task completed or timed out without throwing
if (!completed) {
Assert.Inconclusive ($"Test timed out waiting for task. Task status: {task.Status}. This can happen due to timing issues on slow machines.");
}

// Task completed without throwing - this is unexpected
if (task.IsFaulted) {
Assert.Fail ($"Task faulted with unexpected exception: {task.Exception?.InnerException?.GetType ().FullName}: {task.Exception?.InnerException?.Message}");
} else if (task.IsCanceled) {
// This is actually fine - the task was canceled as expected
return;
} else {
Assert.Fail ($"Expected request to be canceled due to 1ms timeout with non-existent proxy, but task completed successfully with Status: {task.Status}");
}
}
}
Expand Down
Loading