Specflow/xUnit tests using async Task and await are hanging TeamCity build
I am using TeamCity to build a .dll containing a test suite for an api. The api is composed of asynchronous calls to create/read/update/delete values in a database. The tests in the .dll were created using specflow, xUnit and c#. Some of my step definitions call the api methods with non-asynchronous code, like so:
public void DoSomething()
{
Task.Run(() => client.ApiCall()).Result;
}
The tests that call the api in this fashion are executed successfully by TeamCity.
If however I change the code for that same api call, so that the calling code is asynchronous,
public async Task DoSomething()
{
await client.ApiCall();
}
the build will hang on that test.
Please sign in to leave a comment.
Additional information:
I have created a separate project, using XUnit but not specflow, and made the same api call with async and await. This version of the test does not hang the TeamCity build.