public void ApplyScopeToTest(ParallelScope scope)
 {
     var test = new TestDummy();
     var attr = new ParallelizableAttribute(scope);
     attr.ApplyToTest(test);
     Assert.That(test.Properties.Get(PropertyNames.ParallelScope), Is.EqualTo(scope));
 }
        /// <summary>
        /// Construct a ParallelizableAttribute with a specified scope.
        /// </summary>
        /// <param name="scope">The ParallelScope associated with this attribute.</param>
        public ParallelizableAttribute(ParallelScope scope) : base()
        {
#if !NUNITLITE
            _scope = scope;
#endif
            Properties.Add(PropertyNames.ParallelScope, scope);
        }
        /// <summary>
        /// Construct a ParallelizableAttribute with a specified scope.
        /// </summary>
        /// <param name="scope">The ParallelScope associated with this attribute.</param>
        public ParallelizableAttribute(ParallelScope scope) : base()
        {
#if !NUNITLITE
            _scope = scope;
#endif
            Properties.Add(PropertyNames.ParallelScope, scope);
        }
Example #4
0
        private WorkItem MakeWorkItem(Test test, ParallelScope testScope, ParallelScope contextScope)
        {
            test.Properties.Set(PropertyNames.ParallelScope, testScope);
            _context.ParallelScope = contextScope;

            return(TestBuilder.CreateWorkItem(test, _context));
        }
 public void ApplyScopeToContext(ParallelScope scope)
 {
     var context = new TestExecutionContext();
     var attr = new ParallelizableAttribute(scope);
     attr.ApplyToContext(context);
     Assert.That(context.ParallelScope, Is.EqualTo(scope & ParallelScope.ContextMask));
 }
        public void SingleThreadedTestCase(ParallelScope testScope, ParallelScope contextScope)
        {
            _context.IsSingleThreaded = true;
            var strategy = MakeWorkItem(_testMethod, testScope, contextScope).ExecutionStrategy;

            Assert.That(strategy, Is.EqualTo(ParallelExecutionStrategy.Direct));
        }
 public void ApplyScopeToTestFixture(ParallelScope scope)
 {
     var fixture = new TestFixture(new TypeWrapper(typeof(FixtureClass)));
     var attr = new ParallelizableAttribute(scope);
     attr.ApplyToTest(fixture);
     if (scope == ParallelScope.Fixtures)
         scope |= ParallelScope.Self;
     Assert.That(fixture.Properties.Get(PropertyNames.ParallelScope), Is.EqualTo(scope));
 }
        public void AnalyzeWhenAssemblyAttributeIsNotParallelScopeSelf(ParallelScope parallelScope)
        {
            var enumValue = parallelScope.ToString();
            var testCode  = $@"
using NUnit.Framework;
[assembly: Parallelizable(ParallelScope.{enumValue})]";

            AnalyzerAssert.Valid <ParallelizableUsageAnalyzer>(testCode);
        }
        private WorkItem MakeWorkItem(ITest test, ParallelScope testScope, ParallelScope contextScope)
        {
            test.Properties.Set(PropertyNames.ParallelScope, testScope);
            _context.ParallelScope = contextScope;

            var work = WorkItemBuilder.CreateWorkItem(test, TestFilter.Empty);

            work.InitializeContext(_context);

            return(work);
        }
        public void AnalyzeWhenAttributeIsOnClass(ParallelScope parallelScope)
        {
            var enumValue = parallelScope.ToString();
            var testCode  = TestUtility.WrapClassInNamespaceAndAddUsing($@"
    [TestFixture]
    [Parallelizable(ParallelScope.{enumValue})]
    public sealed class AnalyzeWhenAttributeIsOnClass
    {{
    }}");

            AnalyzerAssert.Valid <ParallelizableUsageAnalyzer>(testCode);
        }
        public void ParallelExeutionStrategy_TestFixture(ParallelScope testScope, ParallelScope contextScope, string expectedStrategy)
        {
            _testFixture.Properties.Set(PropertyNames.ParallelScope, testScope);
            _context.ParallelScope = contextScope;

            WorkItem work = WorkItem.CreateWorkItem(_testFixture, TestFilter.Empty);

            work.InitializeContext(_context);

            // We use a string for expected because the ExecutionStrategy enum is internal and can't be an arg to a public method
            Assert.That(ParallelWorkItemDispatcher.GetExecutionStrategy(work).ToString(), Is.EqualTo(expectedStrategy));
        }
        public void ParallelExecutionStrategy_TestCase(ParallelScope testScope, ParallelScope contextScope, string expectedStrategy)
        {
            _testMethod.Properties.Set(PropertyNames.ParallelScope, testScope);
            _context.ParallelScope = contextScope;

            WorkItem work = WorkItem.CreateWorkItem(_testMethod, TestFilter.Empty);

            work.InitializeContext(_context);

            // We use a string for expected because the ExecutionStrategy enum is internal and can't be an arg to a public method
            Assert.That(ParallelWorkItemDispatcher.GetExecutionStrategy(work).ToString(), Is.EqualTo(expectedStrategy));

            // Make context single threaded - should always be direct
            _context.IsSingleThreaded = true;
            Assert.That(ParallelWorkItemDispatcher.GetExecutionStrategy(work).ToString(), Is.EqualTo("Direct"));
        }
Example #13
0
        private ParallelExecutionStrategy GetExecutionStrategy()
        {
            // If there is no fixture and so nothing to do but dispatch
            // grandchildren we run directly. This saves time that would
            // otherwise be spent enqueuing and dequeing items.
            if (Test.TypeInfo == null)
            {
                return(ParallelExecutionStrategy.Direct);
            }

            // If the context is single-threaded we are required to run
            // the tests one by one on the same thread as the fixture.
            if (Context.IsSingleThreaded)
            {
                return(ParallelExecutionStrategy.Direct);
            }

            // Check if item is explicitly marked as non-parallel
            if (ParallelScope.HasFlag(ParallelScope.None))
            {
                return(ParallelExecutionStrategy.NonParallel);
            }

            // Check if item is explicitly marked as parallel
            if (ParallelScope.HasFlag(ParallelScope.Self))
            {
                return(ParallelExecutionStrategy.Parallel);
            }

            // Item is not explicitly marked, so check the inherited context
            if (Context.ParallelScope.HasFlag(ParallelScope.Children) ||
                Test is TestFixture && Context.ParallelScope.HasFlag(ParallelScope.Fixtures))
            {
                return(ParallelExecutionStrategy.Parallel);
            }

            // There is no scope specified either on the item itself or in the context.
            // In that case, simple work items are test cases and just run on the same
            // thread, while composite work items and teardowns are non-parallel.
            return(this is SimpleWorkItem
                ? ParallelExecutionStrategy.Direct
                : ParallelExecutionStrategy.NonParallel);
        }
Example #14
0
        public void ConstructWithScopeArgument(ParallelScope scope)
        {
            var attr = new ParallelizableAttribute(scope);

            Assert.That(attr.Properties.Get(PropertyNames.ParallelScope), Is.EqualTo(scope));
        }
 public void ConstantMatchesValueInNUnit(int enumValue, ParallelScope parallelScope)
 {
     Assert.That(enumValue, Is.EqualTo((int)parallelScope));
 }
        public void AnalyzeWhenAttributeIsOnParametricTestMethodNotParallelScopeFixtures(ParallelScope parallelScope)
        {
            var enumValue = parallelScope.ToString();
            var testCode  = TestUtility.WrapClassInNamespaceAndAddUsing($@"
    [TestFixture]
    public sealed class AnalyzeWhenAttributeIsOnParametricTestMethodNotParallelScopeFixtures
    {{
        [Test]
        [Parallelizable(ParallelScope.{enumValue})]
        public void Test([Values(1, 2, 3)] int data)
        {{
        }}
    }}");

            AnalyzerAssert.Valid <ParallelizableUsageAnalyzer>(testCode);
        }
        public void AnalyzeWhenAttributeIsOnSimpleTestMethodContainsParallelScopeChildren(ParallelScope parallelScope)
        {
            var expectedDiagnostic = ExpectedDiagnostic.Create(
                AnalyzerIdentifiers.ParallelScopeChildrenOnNonParameterizedTestMethodUsage,
                ParallelizableUsageAnalyzerConstants.ParallelScopeChildrenOnNonParameterizedTestMethodMessage);

            var enumValue = parallelScope.ToString();
            var testCode  = TestUtility.WrapClassInNamespaceAndAddUsing($@"
    [TestFixture]
    public sealed class AnalyzeWhenAttributeIsOnSimpleTestMethodContainsParallelScopeChildren
    {{
        [Test]
        [↓Parallelizable(ParallelScope.{enumValue})]
        public void Test()
        {{
        }}
    }}");

            AnalyzerAssert.Diagnostics(analyzer, expectedDiagnostic, testCode);
        }
 public ParallelizableInheritedAttribute(ParallelScope scope) : base()
 {
     _scope = scope;
     Properties.Add(PropertyNames.ParallelScope, scope);
 }
Example #19
0
        public ParallelizableAttribute(ParallelScope scope) : base()
        {
            Scope = scope;

            Properties.Set(PropertyNames.ParallelScope, scope);
        }
        public void AnalyzeWhenAttributeIsOnTestCaseTestMethodNotParallelScopeFixtures(ParallelScope parallelScope)
        {
            var enumValue = parallelScope.ToString();
            var testCode  = TestUtility.WrapClassInNamespaceAndAddUsing($@"
    [TestFixture]
    public sealed class AnalyzeWhenAttributeIsOnTestCaseTestMethodNotParallelScopeFixtures
    {{
        [TestCase(1)]
        [Parallelizable(ParallelScope.{enumValue})]
        public void Test(int data)
        {{
        }}
    }}");

            RoslynAssert.Valid(this.analyzer, testCode);
        }
        public void TestFixtureStrategy(ParallelScope testScope, ParallelScope contextScope, ParallelExecutionStrategy expectedStrategy)
        {
            var strategy = MakeWorkItem(_testFixture, testScope, contextScope).ExecutionStrategy;

            Assert.That(strategy, Is.EqualTo(expectedStrategy));
        }
 /// <summary>
 /// Construct a ParallelizableAttribute with a specified scope.
 /// </summary>
 /// <param name="scope">The ParallelScope associated with this attribute.</param>
 public ParallelizableAttribute(ParallelScope scope) : base()
 {
     _scope = scope;
     Properties.Add(PropertyNames.ParallelScope, scope);
 }
 private static ParallelScope ApplyModeToParallelScope(ParallelScope scope)
 {
     return(TestEnvironment.GlobalTestMode == RecordedTestMode.Live ? scope : ParallelScope.None);
 }
 public LiveParallelizableAttribute(ParallelScope scope) : base(ApplyModeToParallelScope(scope))
 {
 }
Example #25
0
 public static bool HasFlag(this ParallelScope scope, ParallelScope value)
 {
     return((scope & value) != 0);
 }
        private static ParallelScope ApplyModeToParallelScope(ParallelScope scope)
        {
            RecordedTestMode mode = RecordedTestUtilities.GetModeFromEnvironment();

            return(mode == RecordedTestMode.Live ? scope : ParallelScope.None);
        }