diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1287f7de..090f61e0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,6 +20,4 @@ jobs: - name: Restore dependencies run: dotnet restore NBomber.sln - name: Build - run: dotnet build NBomber.sln --no-restore - - name: Test - run: dotnet test tests/NBomber.IntegrationTests/NBomber.IntegrationTests.fsproj --filter CI!=disable --configuration Release --verbosity normal + run: dotnet build NBomber.sln --no-restore \ No newline at end of file diff --git a/examples/Demo/Features/Timeouts/ScenarioCompletionTimeout.cs b/examples/Demo/Features/Timeouts/ScenarioCompletionTimeout.cs index c838cf87..d92fd702 100644 --- a/examples/Demo/Features/Timeouts/ScenarioCompletionTimeout.cs +++ b/examples/Demo/Features/Timeouts/ScenarioCompletionTimeout.cs @@ -6,6 +6,8 @@ public class ScenarioCompletionTimeout { public void Run() { + // Docs: https://nbomber.com/docs/nbomber/timeouts + // When NBomber finishes load tests, it waits for all running scenarios to complete their tasks. var scenario = Scenario.Create("scenario_1", async context => diff --git a/examples/Demo/HTTP/HttpWithTimeoutExample.cs b/examples/Demo/HTTP/HttpWithTimeoutExample.cs new file mode 100644 index 00000000..d3235623 --- /dev/null +++ b/examples/Demo/HTTP/HttpWithTimeoutExample.cs @@ -0,0 +1,48 @@ +using NBomber.CSharp; +using NBomber.Http; +using NBomber.Http.CSharp; +using NBomber.Plugins.Network.Ping; + +namespace Demo.HTTP; + +public class HttpWithTimeoutExample +{ + public void Run() + { + // Docs: https://nbomber.com/docs/nbomber/timeouts + + using var httpClient = new HttpClient(); + + var scenario = Scenario.Create("http_scenario", async context => + { + using var timeout = new CancellationTokenSource(); + timeout.CancelAfter(50); // the operation will be canceled after 50 ms + + var request = + Http.CreateRequest("GET", "https://nbomber.com") + .WithHeader("Content-Type", "application/json"); + //.WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json")); + + // HttpCompletionOption: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcompletionoption?view=net-7.0 + + var clientArgs = new HttpClientArgs( + httpCompletion: HttpCompletionOption.ResponseContentRead, // or ResponseHeadersRead + cancellationToken: timeout.Token + ); + + var response = await Http.Send(httpClient, clientArgs, request); + + return response; + }) + .WithoutWarmUp() + .WithLoadSimulations(Simulation.Inject(rate: 100, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30))); + + NBomberRunner + .RegisterScenarios(scenario) + .WithWorkerPlugins( + new PingPlugin(PingPluginConfig.CreateDefault("nbomber.com")), + new HttpMetricsPlugin(new [] { HttpVersion.Version1 }) + ) + .Run(); + } +} diff --git a/examples/Demo/HelloWorld/ScenarioWithTimeout.cs b/examples/Demo/HelloWorld/ScenarioWithTimeout.cs index 4f5def3f..b996b7b4 100644 --- a/examples/Demo/HelloWorld/ScenarioWithTimeout.cs +++ b/examples/Demo/HelloWorld/ScenarioWithTimeout.cs @@ -9,8 +9,11 @@ public void Run() var scenario = Scenario.Create("scenario_with_timeout", async context => { using var timeout = new CancellationTokenSource(); - timeout.CancelAfter(600); + timeout.CancelAfter(600); // the operation will be canceled after 600 ms + // here, we pass CancellationToken via timeout.Token + // and because Task.Delay(1000) is bigger than 600 ms + // the operation will be cancelled await Task.Delay(1000, timeout.Token); return Response.Ok(statusCode: "200", sizeBytes: 1000); diff --git a/examples/Demo/Program.cs b/examples/Demo/Program.cs index 6acbc7ec..07072e9a 100644 --- a/examples/Demo/Program.cs +++ b/examples/Demo/Program.cs @@ -52,6 +52,7 @@ // ---- Timeouts ---- // new ScenarioCompletionTimeout().Run(); +// new HttpWithTimeoutExample().Run(); // ---------------- // ----- HTTP -----