/// <summary> /// Run an advanced load test with more options. /// </summary> /// <typeparam name="T">The load test class to invoke.</typeparam> /// <returns></returns> /// <exception cref="InvalidOperationException">Is thrown if you try to invoke it more than once</exception> public static async Task <int> Run <T>() where T : LoadTest, ILoadTest { if (Instances.Called && !Instances.CalledDisabled) { throw new InvalidOperationException("Run can only be called once pr test class. Split your test into multiple test classes"); } using (Instances.TelemetryListener) { Instances.Called = true; var startup = new LoaditStartup(); var hostBuilder = startup.CreateBuilder(Environment.GetCommandLineArgs(), services => { services.AddSingleton <ILoadTest, T>(); }); return(await RunEngine(hostBuilder)); } }
public static async Task <int> Run <T>(Action <LoadOptions> configure, Func <T, CancellationToken, Task> executeAsync) { var options = new LoadOptions() { VUs = 1 }; configure.Invoke(options); if (Instances.Called && !Instances.CalledDisabled) { throw new InvalidOperationException("Run can only be called once pr test class. Split your test into multiple test classes"); } using (Instances.TelemetryListener) { Instances.Called = true; var startup = new LoaditStartup(); var hostBuilder = startup.CreateBuilder(Environment.GetCommandLineArgs(), services => { services.AddSingleton(provider => ImplementationFactory(options, provider, executeAsync)); }); return(await Execute.RunEngine(hostBuilder)); } }