Skip to content

Commit

Permalink
Merge pull request #10 from AbhitejJohn/in-assembly-parallel
Browse files Browse the repository at this point in the history
In assembly parallel
  • Loading branch information
AbhitejJohn authored Nov 24, 2017
2 parents 1b9a78b + d26387a commit 575ccc1
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ private void ExecuteTestsInSource(IEnumerable<TestCase> tests, IRunContext runCo
}

var tasks = new List<Task>();

for (int i = 0; i < parallelWorkers; i++)
{
tasks.Add(Task.Factory.StartNew(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Adapter/MSTest.CoreAdapter/Resources/Resource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
<value>[MSTest][Discovery][{0}] {1}</value>
</data>
<data name="TestParallelizationBanner" xml:space="preserve">
<value>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</value>
<value>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</value>
</data>
<data name="InvalidParallelScopeValue" xml:space="preserve">
<value>Invalid value '{0}' specified for 'Scope'. Supported scopes are {1}.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/MSTest.CoreAdapter/Resources/xlf/Resource.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<note></note>
</trans-unit>
<trans-unit id="TestParallelizationBanner">
<source>MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</source>
<source>MSTest Executor: Test Parallelization enabled. Workers: {0}, Scope: {1}.</source>
<target state="new">MSTest Executor: Test Parallelization enabled. Parallel Level {0}, Parallel Mode {1}</target>
<note></note>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,43 @@ public void RunTestsForTestShouldPreferParallelSettingsFromRunSettingsOverAssemb
}
}

[TestMethodV1]
[Ignore]
public void RunTestsForTestShouldRunTestsInTheParentDomainsApartmentState()
{
var testCase1 = this.GetTestCase(typeof(DummyTestClassWithDoNotParallelizeMethods), "TestMethod1");
var testCase2 = this.GetTestCase(typeof(DummyTestClassWithDoNotParallelizeMethods), "TestMethod2");
var testCase3 = this.GetTestCase(typeof(DummyTestClassWithDoNotParallelizeMethods), "TestMethod3");
var testCase4 = this.GetTestCase(typeof(DummyTestClassWithDoNotParallelizeMethods), "TestMethod4");

////testCase3.SetPropertyValue(MSTest.TestAdapter.Constants.DoNotParallelizeProperty, true);
testCase4.SetPropertyValue(MSTest.TestAdapter.Constants.DoNotParallelizeProperty, true);

TestCase[] tests = new[] { testCase1, testCase2, testCase3, testCase4 };
this.runContext.MockRunSettings.Setup(rs => rs.SettingsXml).Returns(
@"<RunSettings>
<MSTest>
<Parallelize>
<Workers>3</Workers>
<Scope>MethodLevel</Scope>
</Parallelize>
</MSTest>
</RunSettings>");

try
{
MSTestSettings.PopulateSettings(this.runContext);
this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, new TestRunCancellationToken());

Assert.AreEqual(1, DummyTestClassWithDoNotParallelizeMethods.ThreadApartmentStates.Count);
Assert.AreEqual(Thread.CurrentThread.GetApartmentState(), DummyTestClassWithDoNotParallelizeMethods.ThreadApartmentStates.ToArray()[0]);
}
finally
{
DummyTestClassWithDoNotParallelizeMethods.Cleanup();
}
}

#endregion

#region private methods
Expand Down Expand Up @@ -811,19 +848,13 @@ public static void Cleanup()
[UTF.TestMethod]
public void TestMethod1()
{
if (!threadIds.Contains(Thread.CurrentThread.ManagedThreadId))
{
threadIds.Add(Thread.CurrentThread.ManagedThreadId);
}
threadIds.Add(Thread.CurrentThread.ManagedThreadId);
}

[UTF.TestMethod]
public void TestMethod2()
{
if (!threadIds.Contains(Thread.CurrentThread.ManagedThreadId))
{
threadIds.Add(Thread.CurrentThread.ManagedThreadId);
}
threadIds.Add(Thread.CurrentThread.ManagedThreadId);
}
}

Expand All @@ -848,19 +879,13 @@ public static void Cleanup()
[UTF.TestMethod]
public void TestMethod1()
{
if (!threadIds.Contains(Thread.CurrentThread.ManagedThreadId))
{
threadIds.Add(Thread.CurrentThread.ManagedThreadId);
}
threadIds.Add(Thread.CurrentThread.ManagedThreadId);
}

[UTF.TestMethod]
public void TestMethod2()
{
if (!threadIds.Contains(Thread.CurrentThread.ManagedThreadId))
{
threadIds.Add(Thread.CurrentThread.ManagedThreadId);
}
threadIds.Add(Thread.CurrentThread.ManagedThreadId);
}
}

Expand All @@ -885,10 +910,7 @@ public static void Cleanup()
[UTF.TestMethod]
public void TestMethod1()
{
if (!threadIds.Contains(Thread.CurrentThread.ManagedThreadId))
{
threadIds.Add(Thread.CurrentThread.ManagedThreadId);
}
threadIds.Add(Thread.CurrentThread.ManagedThreadId);
}
}

Expand All @@ -897,6 +919,8 @@ private class DummyTestClassWithDoNotParallelizeMethods
{
private static HashSet<int> parallelizableTestsThreadIds = new HashSet<int>();
private static HashSet<int> unParallelizableTestsThreadIds = new HashSet<int>();
private static HashSet<ApartmentState> threadApartmentStates = new HashSet<ApartmentState>();
private static bool isFirstUnParallelizedTestRunTimeSet = false;

public static HashSet<int> ParallelizableTestsThreadIds
{
Expand All @@ -914,34 +938,40 @@ public static HashSet<int> UnParallelizableTestsThreadIds
}
}

public static HashSet<ApartmentState> ThreadApartmentStates
{
get
{
return threadApartmentStates;
}
}

public static DateTime LastParallelizableTestRun { get; set; }

public static DateTime? FirstUnParallelizableTestRun { get; set; }
public static DateTime FirstUnParallelizableTestRun { get; set; }

public static void Cleanup()
{
parallelizableTestsThreadIds.Clear();
unParallelizableTestsThreadIds.Clear();
threadApartmentStates.Clear();
isFirstUnParallelizedTestRunTimeSet = false;
}

[UTF.TestMethod]
public void TestMethod1()
{
if (!parallelizableTestsThreadIds.Contains(Thread.CurrentThread.ManagedThreadId))
{
parallelizableTestsThreadIds.Add(Thread.CurrentThread.ManagedThreadId);
}
parallelizableTestsThreadIds.Add(Thread.CurrentThread.ManagedThreadId);
threadApartmentStates.Add(Thread.CurrentThread.GetApartmentState());

LastParallelizableTestRun = DateTime.Now;
}

[UTF.TestMethod]
public void TestMethod2()
{
if (!parallelizableTestsThreadIds.Contains(Thread.CurrentThread.ManagedThreadId))
{
parallelizableTestsThreadIds.Add(Thread.CurrentThread.ManagedThreadId);
}
parallelizableTestsThreadIds.Add(Thread.CurrentThread.ManagedThreadId);
threadApartmentStates.Add(Thread.CurrentThread.GetApartmentState());

LastParallelizableTestRun = DateTime.Now;
}
Expand All @@ -950,30 +980,26 @@ public void TestMethod2()
[UTF.DoNotParallelize]
public void TestMethod3()
{
if (!FirstUnParallelizableTestRun.HasValue)
if (!isFirstUnParallelizedTestRunTimeSet)
{
FirstUnParallelizableTestRun = DateTime.Now;
}

if (!unParallelizableTestsThreadIds.Contains(Thread.CurrentThread.ManagedThreadId))
{
unParallelizableTestsThreadIds.Add(Thread.CurrentThread.ManagedThreadId);
}
unParallelizableTestsThreadIds.Add(Thread.CurrentThread.ManagedThreadId);
threadApartmentStates.Add(Thread.CurrentThread.GetApartmentState());
}

[UTF.TestMethod]
[UTF.DoNotParallelize]
public void TestMethod4()
{
if (!FirstUnParallelizableTestRun.HasValue)
if (!isFirstUnParallelizedTestRunTimeSet)
{
FirstUnParallelizableTestRun = DateTime.Now;
}

if (!unParallelizableTestsThreadIds.Contains(Thread.CurrentThread.ManagedThreadId))
{
unParallelizableTestsThreadIds.Add(Thread.CurrentThread.ManagedThreadId);
}
unParallelizableTestsThreadIds.Add(Thread.CurrentThread.ManagedThreadId);
threadApartmentStates.Add(Thread.CurrentThread.GetApartmentState());
}
}

Expand Down

0 comments on commit 575ccc1

Please sign in to comment.