コード例 #1
0
ファイル: Execute.cs プロジェクト: lilbaek/loadit
        /// <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));
            }
        }
コード例 #2
0
ファイル: ExecuteFunc.cs プロジェクト: lilbaek/loadit
        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));
            }
        }