-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters