Skip to content

Commit 1b978d4

Browse files
authored
Merge pull request #2802 from spkrka/issue-2801
Fix issue 2801 - Only resolve hostname once
2 parents c72d23a + e76ec27 commit 1b978d4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Current
22
New: Ability to provide custom error message for assertThrows\expectThrows methods (Anatolii Yuzhakov)
33
Fixed: GITHUB-2780: Use SpotBugs instead of abandoned FindBugs
4+
Fixed: GITHUB-2801: JUnitReportReporter is too slow
45

56
7.6.1
67
Fixed: GITHUB-2761: Exception: ERROR java.nio.file.NoSuchFileException: /tmp/testngXmlPathInJar-15086412835569336174 (Krishnan Mahadevan)

testng-core/src/main/java/org/testng/reporters/JUnitReportReporter.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public void generateReport(
6060
}
6161
}
6262

63+
final String hostname = getHostName();
64+
6365
for (Map.Entry<Class<?>, Set<ITestResult>> entry : results.entrySet()) {
6466
Class<?> cls = entry.getKey();
6567
Properties p1 = new Properties();
@@ -116,10 +118,8 @@ public void generateReport(
116118
p1.setProperty(XMLConstants.ATTR_NAME, cls.getName());
117119
p1.setProperty(XMLConstants.ATTR_TESTS, Integer.toString(testCount + ignored));
118120
p1.setProperty(XMLConstants.ATTR_TIME, "" + formatTime(totalTime));
119-
try {
120-
p1.setProperty(XMLConstants.ATTR_HOSTNAME, InetAddress.getLocalHost().getHostName());
121-
} catch (UnknownHostException e) {
122-
// ignore
121+
if (hostname != null) {
122+
p1.setProperty(XMLConstants.ATTR_HOSTNAME, hostname);
123123
}
124124

125125
//
@@ -159,6 +159,15 @@ private static Collection<ITestResult> sort(Set<ITestResult> results) {
159159
return Collections.unmodifiableList(sortedResults);
160160
}
161161

162+
private static String getHostName() {
163+
try {
164+
return InetAddress.getLocalHost().getHostName();
165+
} catch (UnknownHostException e) {
166+
// ignore
167+
return null;
168+
}
169+
}
170+
162171
private static int getDisabledTestCount(Set<ITestNGMethod> methods) {
163172
int count = 0;
164173
for (ITestNGMethod method : methods) {

0 commit comments

Comments
 (0)