Search code examples
continuous-integrationcpudnxappveyor

Microsoft.AspNet.TestHost.TestServer requires more than one Core/Processor?


Following an article on strathweb, I recently added some integration tests to my DNX project. Locally these run fine (yay for in memory web servers).

However when running the tests on a VM with only a single core, the integration tests hang indefinitely (and eventually fail because appveyor builds are capped to 60 minutes.

Curiously, when running the tests on a VM with more than one core everything runs fine.

The obvious conclusion is that maybe Microsoft.AspNet.TestHost.TestServer needs more than one Core (or at least more than one logical processor). Does anyone have any experience with this to be able to confirm/deny?


Solution

  • As @Tratcher replied as a comment: xUnit supports async so make your test async and return task (otherwise xUnit doesn't know the outcome of your test and it will pass even before it finishes running):

     [Fact]
            public async Task Get_hello_should_ignore_bob()
            {
                // Given a sample client
                var client = SampleClient();
    
                // When I call POST /account/signin
                var value = new StringContent("");
                var response = await client.PostAsync("/account/signin", value);
    
                // Then the result should be Hello
                string result = await response.Content.ReadAsStringAsync();
                result.Should().Be("\"Hello\"");
            }
    

    Now that your test is async, you can use await, instead of calling .Result on the task (which is what caused your issue):

    Also, it's worth noting why this happened. See more about dead-lock and SynchronizationContext