-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Dtestng.thread.affinity=true do not work when running multiple insta…
…nce of test in parallel Closes #2321
- Loading branch information
1 parent
85d68c2
commit 159574e
Showing
5 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package test.testng2321; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.AfterSuite; | ||
import org.testng.annotations.BeforeSuite; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Factory; | ||
import org.testng.annotations.Test; | ||
|
||
public class TestMultipleInstance { | ||
private int part; | ||
|
||
private long threadId; | ||
@BeforeSuite | ||
public void setProperty() { | ||
System.setProperty("testng.thread.affinity", "true"); | ||
} | ||
|
||
@Factory(dataProvider = "dp") | ||
public TestMultipleInstance(int part) { | ||
this.part = part; | ||
} | ||
|
||
@Test | ||
public void independent() { | ||
threadId = Thread.currentThread().getId(); | ||
System.err.println(getClass().getSimpleName() + " part - " + part + " independent() running on " + threadId); | ||
} | ||
|
||
@Test(dependsOnMethods = "independent") | ||
public void dependent() { | ||
long currentThreadId = Thread.currentThread().getId(); | ||
System.err.println(getClass().getSimpleName() + " part - " + part + " dependent() running on " + currentThreadId); | ||
Assert.assertEquals(currentThreadId, threadId, "Thread Ids didn't match"); | ||
} | ||
|
||
|
||
@DataProvider(name = "dp") | ||
public static Object[][] getData() { | ||
return new Object[][]{ | ||
{1}, | ||
{2} | ||
}; | ||
} | ||
|
||
@AfterSuite | ||
public void removeProperty() { | ||
System.clearProperty("testng.thread.affinity"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"> | ||
<suite verbose="2" name="test_parallel_mode" parallel="instances"> | ||
<test thread-count="5" verbose="2" name="test_data_provider_in_instance_parallel_mode" parallel="instances"> | ||
<classes> | ||
<class name="test.testng2321.TestMultipleInstance"/> | ||
</classes> | ||
</test> | ||
</suite> |