private void RunWorker(UnitTest test, CancellationToken cancelToken)
 {
     while (!cancelToken.IsCancellationRequested)
     {
         test.Execute();
     }
 }
Ejemplo n.º 2
0
        public async Task ExecuteTestAsync(UnitTest test, CancellationToken cancelToken)
        {
            TaskCompletionSource<object> executionCancelled = new TaskCompletionSource<object>();

            Task testTask = Task.Run(() => test.Execute());

            cancelToken.Register(() => executionCancelled.SetResult(null));

            //if the execution is cancelled before the test is complete that test will continue running
            //however this should only occur when the execution has run to duration so we return to allow the process to exit
            await Task.WhenAny(testTask, executionCancelled.Task);
        }
Ejemplo n.º 3
0
        public void SimpleLoad(CancellationToken cancelToken)
        {
            var unitTests = new UnitTest[] { new UnitTest(this.Foo), new UnitTest(this.Bar), new UnitTest(this.Shz), new UnitTest(this.Nit) };

            var testPattern = new RandomTestPattern();

            testPattern.Initialize(0, unitTests);

            var workerStrategy = new DedicatedThreadWorkerStrategy();

            var loadPattern = new StaticLoadPattern() { WorkerCount = 24 };

            Task t = loadPattern.ExecuteAsync(testPattern, workerStrategy, cancelToken);

            Task.Delay(3000).GetAwaiter().GetResult();

            var rootLoadPattern = new StaticLoadPattern() { WorkerCount = 500 };

            //add a burst of execution
            rootLoadPattern.Execute(new UnitTest(Root), workerStrategy, new CancellationTokenSource(10000).Token);

            //wait for original workers to complete
            t.GetAwaiter().GetResult();
        }
        public void SpawnWorker(UnitTest test, CancellationToken cancelToken)
        {
            Task t = new Task(() => RunWorker(test, cancelToken), TaskCreationOptions.LongRunning);

            t.Start();
        }