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

Add warning for slow hostname lookups on OS X #3766

Merged
merged 1 commit into from Jun 6, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -1039,7 +1039,9 @@ private[sbt] object Load {
// Grab all the settings we already loaded from sbt files
def settings(files: Seq[File]): Seq[Setting[_]] = {
if (files.nonEmpty)
log.info(s"${files.map(_.getName).mkString(s"Loading settings for project ${p.id} from ", ",", " ...")}")
log.info(
s"${files.map(_.getName).mkString(s"Loading settings for project ${p.id} from ", ",", " ...")}"
)
for {
file <- files
config <- (memoSettings get file).toSeq
@@ -30,6 +30,6 @@ object JUnitXmlReportPlugin extends AutoPlugin {
// It might be a good idea to derive this setting into specific test scopes.
override lazy val projectSettings: Seq[Setting[_]] =
Seq(
testListeners += new JUnitXmlTestsListener(target.value.getAbsolutePath)
testListeners += new JUnitXmlTestsListener(target.value.getAbsolutePath, streams.value.log)
)
}
@@ -13,8 +13,10 @@ import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import java.util.Hashtable
import java.util.concurrent.TimeUnit.NANOSECONDS

import scala.collection.mutable.ListBuffer
import scala.util.Properties
import scala.xml.{ Elem, Node => XNode, XML }
import testing.{
Event => TEvent,
@@ -23,21 +25,35 @@ import testing.{
OptionalThrowable,
TestSelector
}
import util.Logger
import sbt.protocol.testing.TestResult

/**
* A tests listener that outputs the results it receives in junit xml
* report format.
* @param outputDir path to the dir in which a folder with results is generated
*/
class JUnitXmlTestsListener(val outputDir: String) extends TestsListener {
class JUnitXmlTestsListener(val outputDir: String, logger: Logger) extends TestsListener {
// This constructor is for binary compatibility with older versions of sbt.
def this(outputDir: String) = this(outputDir, null)

/**Current hostname so we know which machine executed the tests*/
val hostname =
try InetAddress.getLocalHost.getHostName
val hostname = {
val start = System.nanoTime
val name = try InetAddress.getLocalHost.getHostName
catch {
case _: IOException => "localhost"
}
val elapsed = System.nanoTime - start
if ((NANOSECONDS.toSeconds(elapsed) >= 4) && Properties.isMac && logger != null) {
logger.warn(
s"Getting the hostname $name was slow (${elapsed / 1.0e6} ms). " +
"This is likely because the computer's hostname is not set. You can set the " +
"hostname with the command: scutil --set HostName $(scutil --get LocalHostName)."
)
}
name
}

/**The dir in which we put all result files. Is equal to the given dir + "/test-reports"*/
val targetDir = new File(outputDir + "/test-reports/")
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.