Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 2801 - Only resolve hostname once #2802

Merged
merged 2 commits into from Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,6 +1,7 @@
Current
New: Ability to provide custom error message for assertThrows\expectThrows methods (Anatolii Yuzhakov)
Fixed: GITHUB-2780: Use SpotBugs instead of abandoned FindBugs
Fixed: GITHUB-2801: JUnitReportReporter is too slow

7.6.1
Fixed: GITHUB-2761: Exception: ERROR java.nio.file.NoSuchFileException: /tmp/testngXmlPathInJar-15086412835569336174 (Krishnan Mahadevan)
Expand Down
Expand Up @@ -60,6 +60,8 @@ public void generateReport(
}
}

final String hostname = getHostName();

for (Map.Entry<Class<?>, Set<ITestResult>> entry : results.entrySet()) {
Class<?> cls = entry.getKey();
Properties p1 = new Properties();
Expand Down Expand Up @@ -116,10 +118,8 @@ public void generateReport(
p1.setProperty(XMLConstants.ATTR_NAME, cls.getName());
p1.setProperty(XMLConstants.ATTR_TESTS, Integer.toString(testCount + ignored));
p1.setProperty(XMLConstants.ATTR_TIME, "" + formatTime(totalTime));
try {
p1.setProperty(XMLConstants.ATTR_HOSTNAME, InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException e) {
// ignore
if (hostname != null) {
p1.setProperty(XMLConstants.ATTR_HOSTNAME, hostname);
}

//
Expand Down Expand Up @@ -159,6 +159,15 @@ private static Collection<ITestResult> sort(Set<ITestResult> results) {
return Collections.unmodifiableList(sortedResults);
}

private static String getHostName() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
// ignore
return null;
}
}

private static int getDisabledTestCount(Set<ITestNGMethod> methods) {
int count = 0;
for (ITestNGMethod method : methods) {
Expand Down