Closed lkurzyniec closed 4 years ago
I achieved what I expected in .WithCheck()
, but it's kind of workaround.
.WithCheck(async response =>
{
if (!response.IsSuccessStatusCode)
{
Trace.TraceError(await response.Content.ReadAsStringAsync());
}
return response.IsSuccessStatusCode;
})
Here is my example including two steps: https://github.com/lkurzyniec/netcore-boilerplate/blob/master/test/HappyCode.NetCoreBoilerplate.Api.LoadTests/EmployeesControllerTests.cs
I got there:
var get = HttpStep.Create("get emp", ctx =>
{
var response = ctx.GetPreviousStepResponse<HttpResponseMessage>();
var content = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
var emp = content.Deserialize<EmployeeDto>();
Trace.WriteLine($"The previous step created employee with Id = {emp.Id}");
var getUrl = response.Headers.Location;
return Http.CreateRequest("GET", getUrl.ToString())
.WithHeader("Authorization", "ApiKey ABC-xyz")
.WithCheck(response => Task.FromResult(response.IsSuccessStatusCode));
});
I don't like this line: response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
Hi @lkurzyniec Why don't try using async await? https://github.com/PragmaticFlow/NBomber.Http/blob/dev/examples/NBomber.Http.CSharp/SequentialSteps.cs#L13
@AntyaDev you are right, I didn't notice that there is overload with Task
;)
@AntyaDev one more question - I would like to log both Request and Response that nbomber send and receive from API - how can I achieve that? With a Response I use .WithCheck()
as a workaround, but I feel there should be a better way. And how about Request?
Hi @lkurzyniec I recently added tracing for NBomber.Http plugin. please take a look at this example: https://github.com/PragmaticFlow/NBomber/blob/dev/examples/CSharp/HttpTests/TracingHttp.cs#L38
this functionality is builtin for 1.0.0-rc4
Right now I'm trying to write load test for POST method. My API returns some validation errors. When executing nbomber with
.RunTest()
there is no way to check the messages of any single response. By adding.WithCallback()
to HttpRequest, I can do sth like this.WithCallback(async (response) => { Console.WriteLine(await response.ReadAsStringAsync()) });