Ejemplo n.º 1
0
        public void Test004_MultipleSuspendThreads_SuspendableDocumentLeafNode()
        {
            const int NumberOfRuns    = 5;
            const int NumberOfTesters = 20;

            for (int run = 0; run < NumberOfRuns; ++run)
            {
                var childNode  = new TestNodeWithoutChild_SuspendableDocumentLeafNode();
                var parentNode = new TestNodeWithoutChild_SuspendableDocumentNode(childNode);

                using (var parentSuspendToken = parentNode.SuspendGetToken())
                {
                    var tester = new SuspendTester[NumberOfTesters];
                    for (int i = 0; i < NumberOfTesters; ++i)
                    {
                        tester[i] = new SuspendTester(i % 2 == 0 ? childNode : (ISuspendableByToken)parentNode, 0.2);
                    }

                    Parallel.ForEach(tester, test => test.Worker());

                    Assert.IsTrue(parentNode.IsSuspended);
                    Assert.IsTrue(parentNode._NumberOfSuspended > 0);
                    Assert.IsTrue(parentNode._NumberOfResumesSilently == 0);
                    Assert.AreEqual(parentNode._NumberOfSuspended - 1, parentNode._NumberOfResumes);

                    parentSuspendToken.Resume();
                }

                Assert.IsFalse(childNode.IsSuspended);
                Assert.IsTrue(childNode._NumberOfSuspended > 0);
                Assert.IsTrue(childNode._NumberOfResumesSilently == 0);
                Assert.AreEqual(childNode._NumberOfSuspended, childNode._NumberOfResumes);

                Assert.IsFalse(parentNode.IsSuspended);
                Assert.IsTrue(parentNode._NumberOfSuspended > 0);
                Assert.IsTrue(parentNode._NumberOfResumesSilently == 0);
                Assert.AreEqual(parentNode._NumberOfSuspended, parentNode._NumberOfResumes);
                Assert.AreEqual(0, parentNode.NumberOfChildTokens);
            }
        }
Ejemplo n.º 2
0
        public void Test001_MultipleSuspendThreads_SuspendableDocumentNode()
        {
            const int NumberOfRuns    = 5;
            const int NumberOfTesters = 20;

            for (int run = 0; run < NumberOfRuns; ++run)
            {
                var node = new TestNodeWithoutChild_SuspendableDocumentNode();

                var tester = new SuspendTester[NumberOfTesters];
                for (int i = 0; i < NumberOfTesters; ++i)
                {
                    tester[i] = new SuspendTester(node, 0.2);
                }

                Parallel.ForEach(tester, test => test.Worker());

                Assert.IsFalse(node.IsSuspended);
                Assert.IsFalse(node.IsSuspendedOrResumeInProgress);
                Assert.IsTrue(node._NumberOfSuspended > 0);
                Assert.IsTrue(node._NumberOfResumesSilently == 0);
                Assert.AreEqual(node._NumberOfSuspended, node._NumberOfResumes);
            }
        }
Ejemplo n.º 3
0
		public void Test004_MultipleSuspendThreads_SuspendableDocumentLeafNode()
		{
			const int NumberOfRuns = 5;
			const int NumberOfTesters = 20;

			for (int run = 0; run < NumberOfRuns; ++run)
			{
				var childNode = new TestNodeWithoutChild_SuspendableDocumentLeafNode();
				var parentNode = new TestNodeWithoutChild_SuspendableDocumentNode(childNode);

				using (var parentSuspendToken = parentNode.SuspendGetToken())
				{
					var tester = new SuspendTester[NumberOfTesters];
					for (int i = 0; i < NumberOfTesters; ++i)
					{
						tester[i] = new SuspendTester(i % 2 == 0 ? (ISuspendableByToken)childNode : (ISuspendableByToken)parentNode, 0.2);
					}

					Parallel.ForEach(tester, test => test.Worker());

					Assert.IsTrue(parentNode.IsSuspended);
					Assert.IsTrue(parentNode._NumberOfSuspended > 0);
					Assert.IsTrue(parentNode._NumberOfResumesSilently == 0);
					Assert.AreEqual(parentNode._NumberOfSuspended - 1, parentNode._NumberOfResumes);

					parentSuspendToken.Resume();
				}

				Assert.IsFalse(childNode.IsSuspended);
				Assert.IsTrue(childNode._NumberOfSuspended > 0);
				Assert.IsTrue(childNode._NumberOfResumesSilently == 0);
				Assert.AreEqual(childNode._NumberOfSuspended, childNode._NumberOfResumes);

				Assert.IsFalse(parentNode.IsSuspended);
				Assert.IsTrue(parentNode._NumberOfSuspended > 0);
				Assert.IsTrue(parentNode._NumberOfResumesSilently == 0);
				Assert.AreEqual(parentNode._NumberOfSuspended, parentNode._NumberOfResumes);
				Assert.AreEqual(0, parentNode.NumberOfChildTokens);
			}
		}
Ejemplo n.º 4
0
		public void Test001_MultipleSuspendThreads_SuspendableDocumentNode()
		{
			const int NumberOfRuns = 5;
			const int NumberOfTesters = 20;

			for (int run = 0; run < NumberOfRuns; ++run)
			{
				var node = new TestNodeWithoutChild_SuspendableDocumentNode();

				var tester = new SuspendTester[NumberOfTesters];
				for (int i = 0; i < NumberOfTesters; ++i)
				{
					tester[i] = new SuspendTester(node, 0.2);
				}

				Parallel.ForEach(tester, test => test.Worker());

				Assert.IsFalse(node.IsSuspended);
				Assert.IsFalse(node.IsSuspendedOrResumeInProgress);
				Assert.IsTrue(node._NumberOfSuspended > 0);
				Assert.IsTrue(node._NumberOfResumesSilently == 0);
				Assert.AreEqual(node._NumberOfSuspended, node._NumberOfResumes);
			}
		}