Skip to content

Instantly share code, notes, and snippets.

@tjoskar
Last active October 21, 2015 16:09
Show Gist options
  • Save tjoskar/c1f65bed89d67a503728 to your computer and use it in GitHub Desktop.
Save tjoskar/c1f65bed89d67a503728 to your computer and use it in GitHub Desktop.
PainlessHttp bug #1
  • Install GOT and hapi: $ npm install got hapi
  • Setup a MVC5 project and include ApiController.cs
  • Start test-server.js with node and start the MVC5 project
  • Run $ node test.js to run the test.

Expected result (order doesn't matter):

1: "1"
2: "2"
3: "3"

Actual result (the result varies):

1: "1"
2: "2"
3: "2"
namespace Demo.Controllers
{
public static class HttpSingleton
{
private static PainlessHttp.Client.HttpClient instance;
public static PainlessHttp.Client.HttpClient Instance
{
get
{
if (instance == null)
{
instance = new PainlessHttp.Client.HttpClient("http://localhost:8000");
}
return instance;
}
}
}
public class MyApiClass : ApiController
{
public MonitoringApiController() {}
[Route("api/test")]
[HttpGet]
public async Task<IHttpActionResult> Test(string id = "0")
{
var response = await HttpSingleton.Instance.GetAsync<string>(string.Format("/echo/{0}", id));
return Ok(response.Body);
}
}
}
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 8000
});
server.route({
method: 'GET',
path: '/echo/{user}',
handler: function (request, reply) {
setTimeout(function() {
reply(request.params.user);
}, Math.floor((Math.random() * 1000)));
}
});
server.start(function () {
console.log('Server running at:', server.info.uri);
});
var got = require('got');
var mvc5Url = 'http://localhost:50892/api/test?id='; // Your CS project url
got(mvc5Url + '1')
.then(response => {
console.log('1: ' + response.body);
})
.catch(function(e) {
console.log(e)
});
got(mvc5Url + '2')
.then(response => {
console.log('2: ' + response.body);
})
.catch(function(e) {
console.log(e)
});
got(mvc5Url + '3')
.then(response => {
console.log('3: ' + response.body);
})
.catch(function(e) {
console.log(e)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment