-
-
Save cbrammer/0505f733422c60ddc6fbd9755e62b70b to your computer and use it in GitHub Desktop.
Fusillade failing once cancelled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.Http; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Fusillade; | |
using NUnit.Framework; | |
using Refit; | |
namespace FusilladeTests | |
{ | |
public interface ISampleApi | |
{ | |
[Get ("/countryCodeJSON?formatted=true&lat=47.03&lng=10.2&username=demo&style=full")] | |
Task<CountryCode> GetCountryCode (CancellationToken token = default (CancellationToken)); | |
} | |
public class CountryCode | |
{ | |
public string languages { get; set; } | |
public string distance { get; set; } | |
public string countryCode { get; set; } | |
public string countryName { get; set; } | |
} | |
[TestFixture] | |
public class Fusillade | |
{ | |
ISampleApi api; | |
[SetUp] | |
public void Setup () | |
{ | |
var rateLimitedHandler = new RateLimitedHttpMessageHandler (new HttpClientHandler(), Priority.UserInitiated); | |
var client = new HttpClient (rateLimitedHandler) { | |
BaseAddress = new Uri ("http://api.geonames.org") | |
}; | |
api = RestService.For<ISampleApi> (client); | |
} | |
// This should pass just fine (note how it is the exact same as the third item) | |
[Test] | |
public async Task Fusillade_Cancel_First () | |
{ | |
var result = await api.GetCountryCode (); | |
Assert.NotNull (result); | |
} | |
// This should also pass just fine, but now all subsequent requests hang | |
[Test] | |
public void Fusillade_Cancel_Second () | |
{ | |
var cts = new CancellationTokenSource (); | |
cts.Cancel (); | |
Assert.ThrowsAsync<TaskCanceledException> (async () => await api.GetCountryCode (cts.Token)); | |
} | |
// This _should_ pass, it is an exact copy of the first one above, but it just hangs | |
[Test] | |
public async Task Fusillade_Cancel_Third () | |
{ | |
var result = await api.GetCountryCode (); | |
Assert.NotNull (result); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment