Exemplo n.º 1
0
        public void Test_Data_Is_Batched_Correctly()
        {
            var batchSize = 24;
            var batcher = new TestMethodBatcher(batchSize);
            var data = CreateTestData(batchSize);

            var firstBatch = GetBatch(data, batcher);
            Assert.Equal(10, firstBatch.Count);
            Assert.Equal(0, firstBatch.First());
            Assert.Equal(9, firstBatch.Last());

            var secondBatch = GetBatch(data, batcher);
            Assert.Equal(10, secondBatch.Count);
            Assert.Equal(10, secondBatch.First());
            Assert.Equal(19, secondBatch.Last());

            var thirdBatch = GetBatch(data, batcher);
            Assert.Equal(4, thirdBatch.Count);
            Assert.Equal(20, thirdBatch.First());
            Assert.Equal(23, thirdBatch.Last());
        }
Exemplo n.º 2
0
        static int RunProject(XunitProject project, bool teamcity, bool silent, string[] args)
        {
            var defaultArgs = args.Aggregate((a, b) => a + " " + b);

            var mate = new MultiAssemblyTestEnvironment();
            foreach (XunitProjectAssembly assembly in project.Assemblies)
            {
                TestAssembly testAssembly = mate.Load(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy);
                var methods = new List<TestMethod>(testAssembly.EnumerateTestMethods(project.Filters.Filter));
                var methodsCount = methods.Count;

                ParallelXunitCommandLine.DeleteResultFiles(assembly.AssemblyFilename);

                using (var waiter = new ProcessWaiter())
                {
                    waiter.DefaultArgs = defaultArgs;
                    waiter.TeamCity = teamcity;
                    waiter.Silent = silent;

                    Console.WriteLine("Running with {0} threads.", waiter.MaximumNumberOfProcesses);
                    Console.WriteLine("Total number of tests: {0}.", methodsCount);

                    IParallelTestMethodRunnerCallback callback = CreateCallback(teamcity, silent, methodsCount);
                    callback.ParentAssemblyStart(testAssembly);

                    TestBatch batch;
                    var batcher = new TestMethodBatcher(methodsCount);
                    while ((batch = batcher.GetNextBatch()).Size > 0)
                    {
                        waiter.StartProcess(batch);
                    }

                    if (!teamcity)
                    {
                        waiter.PrintSummary();
                    }
                    else
                    {
                        waiter.WaitForAllProcesses();
                    }

                    var testResult = ParallelXunitCommandLine.AggregateTestResults(assembly.AssemblyFilename);
                    callback.ParentAssemblyFinished(testAssembly, testResult.Total, testResult.Failed, testResult.Skiped);

                    mate.Unload(testAssembly);
                }
            }

            return 0;
        }
Exemplo n.º 3
0
 public TestMethodBatcherTests()
 {
     _batcher = new TestMethodBatcher(14);
 }
Exemplo n.º 4
0
        private IList<int> GetBatch(IList<int> data, TestMethodBatcher batcher)
        {
            var batch = batcher.GetNextBatch();

            return data.Skip(batch.Start).Take(batch.Size).ToList();
        }
Exemplo n.º 5
0
        static int RunProject(XunitProject project, bool teamcity, bool silent, string[] args)
        {
            var defaultArgs = args.Aggregate((a, b) => a + " " + b);

            var mate = new MultiAssemblyTestEnvironment();
            foreach (XunitProjectAssembly assembly in project.Assemblies)
            {
                TestAssembly testAssembly = mate.Load(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy);
                var methods = new List<TestMethod>(testAssembly.EnumerateTestMethods(project.Filters.Filter));

                var batcher = new TestMethodBatcher(methods.Count);

                var waiter = new ProcessWaiter();
                waiter.DefaultArgs = defaultArgs;
                waiter.TeamCity = teamcity;
                waiter.Silent = silent;

                Console.WriteLine("Running with {0} threads.", waiter.MaximumNumberOfProcesses);
                Console.WriteLine("Total number of tests: {0}.", methods.Count);

                TestBatch batch;
                while ((batch = batcher.GetNextBatch()).Size > 0)
                {
                    waiter.StartProcess(batch);
                }

                waiter.PrintSummary();

                mate.Unload(testAssembly);
            }

            return 0;
        }