Commit Graph

159 Commits

Author SHA1 Message Date
Martin Duhem 5cce0e9d5d
Fix #5801: Remove duplicate TaskDefs in test agent
When forking, a test could be run as many times as its `TestDef` matched
`Fingerprint`s. When forking is disabled, sbt correctly runs the tests
only once.
2020-08-26 17:19:35 +02:00
Ethan Atkins 2e9805b9d0 Add internal multi logger implementation
Prior to these changes, sbt was leaking large amounts of memory via
log4j appenders. sbt has an unusual use case for log4j because it
creates many ephemeral loggers while also having a global logger that is
supposed to work for the duration of the sbt session. There is a lot of
shared global state in log4j and properly cleaning up the ephemeral task
appenders would break global logging. This commit fixes the behavior by
introducing an alternate logging implementation. Users can still use the
old log4j logging implementation but it will be off by default. The
internal implementation is very simple: it just blocks the current
thread and writes to all of the appenders. Nevertheless, I found the
performance to be roughly identical to that of log4j in my sample
project. As an experiment, I did the appending on a thread pool and got
a significant performance improvement but I'll defer that to a later PR
since parallel io is harder to reason about.

Background: I was testing sbt performance in
https://github.com/jtjeferreira/sbt-multi-module-sample and noticed that
performance rapidly degraded after I ran compile a few times. I took a
heap dump and it became obvious that sbt was leaking console appenders.
Further investigation revealed that all of the leaking appenders in the
project were coming from task streams. This made me think that the fix
would be to track what loggers were created during task evaluation and
clear them out when task evaluation completed. That almost worked except
that log4j has an internal append only data structure containing logger
names. Since we create unique logger names for each run, that internal
data structure grew without bound. It looked like this could be worked
around by creating a new log4j Configuration (where that data structure
was stored) but while creating new configurations with each task runs
did fix the leak, it also broke global logging, which was using a
different configuration. At this point, I decided to write an alternate
implementation of the appender api where I could be sure that the
appenders were cleaned up without breaking global logging.

Implementation: I made ConsoleAppender a trait and made it no longer
extends log4j AbstractAppender. To do this, I had to remove the one
log4j specific method, append(LogEvent). ConsoleAppender now has a
method toLog4J that, in most cases, will return a log4j Appender that is
almost identical to the Appenders that we previously used. To manage
the loggers created during task evaluation, I introduce a new class,
LoggerContext. The LoggerContext determines which logging backend to use
and keeps track of what appenders and loggers have been created. We can
create a fresh LoggerContext before each task evaluation and clear it
out, cleaning up all of its resources after task evaluation concludes.

In order to make this work, there were many places where we need to
either pass in a LoggerContext or create a new one. The main magic is
happening in the `next(State)` method in Main. This is where we create a
new LoggerContext prior to command evaluation and clean it up after the
evaluation completes.

Users can toggle log4j using the new useLog4J key. They also can set the
system property, sbt.log.uselog4j. The global logger will use the sbt
internal implementation unless the system property is set.

There are a fairly significant number of mima issues since I changed the
type of ConsoleAppender. All of the mima changes were in the
sbt.internal package so I think this should be ok.

Effects: the memory leaks are gone. I successfully ran 5000 no-op
compiles in the sbt-multi-module-sample above with no degradation of
performace. There was a noticeable degradation after 30 no-op compiles
before.

During the refactor, I had to work on TestLogger and in doing so I also
fixed https://github.com/sbt/sbt/issues/4480.

This also should fix https://github.com/sbt/sbt/issues/4773
2020-08-09 11:20:34 -07:00
Eugene Yokota 2396b449fe Contraband 0.4.6 2020-04-24 17:44:15 -04:00
Ethan Atkins cf745255e8 Apply javafmt in sbt project 2020-01-14 14:38:08 -08:00
Jannik Theiß af245d2494 SysProp sbt.testing.legacyreport: fix integration tests, JUnitXmlTestsListener backward binary compatibility 2020-01-08 15:29:48 +01:00
Jannik Theiß cea516175f introduce SysProp sbt.testing.legacyreport
either create test reports with legacy file names (legacyreport=true) or with standard file names (legacyreport=false or omitted) but not both as suggested in #4451
2020-01-08 12:23:09 +01:00
eugene yokota 215b16cde1
Merge pull request #5315 from olafurpg/forkmain-classloader
Add library-friendly entrypoint for sbt.ForkMain
2019-12-17 13:20:44 -05:00
Olafur Pall Geirsson fd658f38d3 Add library-friendly entrypoint for sbt.ForkMain
Previously, it was not possible to use `sbt.ForkMain` as a library since
* it called `System.exit`, shutting down the library client JVM process.
* it assumed that it was always running in the same classloader as where
  the test suites it was running causing "class not found: my.test.Suite"
  if the `ForkMain` class lives in a classloader above the test suite
  classes.
This commit adds a new `main(Array[String],ClassLoader])` entrypoint
that allows clients to call `ForkMain` as a library.
2019-12-17 10:51:10 +00:00
Ethan Atkins aecdc44909 Update contraband sources
In 8bfae66b9d I upgraded contraband but
not all of the sources were regenerated because I didn't run clean
before recompiling.
2019-12-12 11:34:53 -08:00
Eugene Yokota 54b3405f42 apply -Yno-lub
To demonstrate [-Yno-lub](http://eed3si9n.com/stricter-scala-with-ynolub), this shows the code changes that removes lubing (Not all subprojects are done).

After I made the changes, I switched the Scala back to normal 2.12.10.
2019-10-13 23:46:23 -04:00
Margus Sipria 108611ca25 Fix for JUnitXmlTestsListener that is removing part of test name when it contains dot (#5139)
Fix for JUnitXmlTestsListener removing part of test when it contains dot
Fixes https://github.com/sbt/sbt/issues/5114
Fixes https://github.com/sbt/sbt/issues/2949
2019-09-30 10:47:15 -04:00
Ethan Atkins 7c2a1c858b 1.3.0
-----BEGIN PGP SIGNATURE-----
 
 iQEcBAABAgAGBQJdbz/aAAoJEDeJDimNmiv6Am8IAKv23f6BPIWZFeokzJLkUt8v
 DDLyzIwzE0hTFKInCNhGDCFtACFFgoD8/7t9D5gmLttQr4F9ke94DqWBEP3kbgan
 Qb4rR8uwglPUJmOhzBj2Qs3A8fAXdg3wm/6OlllQzBwCYNxFf3MhmJc3hF4vd+jO
 93JqwbY50entqha9z299+NpLPTKWtVC5R+1pAF+LwObjLOYqlxiGvAcl7jWx1qte
 VN+BabBYT4Hw43kJCutglHu8vttG68m+fqYGxjAmZXYBAbn0NPyE7GHmqkQ5baAz
 DUbc0vU2nY6tpUFNlNfu9PTPnRwHdSjSJTa9Ug7hw24z2oTg2tapNDXIpt6n6ZA=
 =onwH
 -----END PGP SIGNATURE-----

Merge tag 'v1.3.0' into 1.3.x-merge

1.3.0
2019-09-05 10:15:41 -07:00
xuwei-k dfe789d7c6 avoid deprecated /: and :\
use foldLeft and foldRight

https://github.com/scala/scala/blob/v2.13.0/src/library/scala/collection/IterableOnce.scala#L682-L686
2019-08-30 11:20:53 +09:00
mkljakubowski d2b1426a1f evaluate test result only once 2019-08-29 15:40:22 +02:00
Ethan Atkins a3ac4c76a6 Bump scalafmt
Intellij had issues resolving 2.0.0-RCX so it will be nice to be using
the latest.
2019-07-18 12:40:21 -07:00
Ethan Atkins 1a8b9de625 Catch NoClassDefFoundErrors in tests
If a test threw a NoClassDefFoundError, it was uncaught and the user got
an obscure error. After this change, they will be warned that the
classloader layering strategy may be at fault and will get instructions
on how to fix it.
2019-05-28 09:53:35 -07:00
Eugene Yokota 1e157b991a apply formatting 2019-04-20 03:23:54 -04:00
Ethan Atkins 8ef5a67b64 Add better error message if run fails
It is possible with the new layering strategies that tests may fail if a
java package private class is accessed across classloader layers. This
will result in an IllegalAccessError that is hard to debug. With this
commit, I add an error message that will be displayed if run throws an
IllegalAccessError that suggests that the user try the
ScalaInstance layering strategy or the flat layering strategy.
2019-04-02 20:53:37 -07:00
Ethan Atkins 3a211710f9 Rename some layering related fields/classes
In code review, @eed3si9n suggested that I switch to a more verbose and
descriptive naming scheme. In addition to trying to make layers more
descriptive, I also made the various layer case objects extend the
relevant layers so it's more clear what the layer should look like.
2019-01-30 08:55:22 -08:00
Ethan Atkins a06f5435c6 Use layered ClassLoaders in run and test tasks
Using the data structures that I added in the previous commits, it is
now possible to rework the run and test task to use (configurable)
layered class loaders. The layering strategy is globally set to
LayeringStrategy.Default. The default strategy leads to what is
effectively a three layered ClassLoader for the both the test and run
tasks. The first layer contains the scala instance (and test framework
loader in the test task). The second layer contains all of the
dependencies for the configuration while the third layer contains the
project artifacts.

The layering strategy is very easily changed both at the Global or
Configuration level, e.g. adding
Test / layeringStrategy := LayeringStrategy.Flat
to the project build.sbt will make the test task not even use the scala
instance and instead a create a single layer containing the full
classpath of the test task.

I also tried to ensure that all of the ClassLoaders have good toString
overrides so that it's easy to see how the ClassLoader is constructed
with, e.g. `show testLoader`, in the sbt console.

In this commit, the ClassLoaderCache instances are settings. In the next
commit, I make them tasks so that we can easily clear out the caches
with a command.
2019-01-30 08:55:22 -08:00
Ethan Atkins 8cba83aebb Improve TestFramework error reporting
It is possible for the test task to fail because of issues with the
layered ClassLoaders. When this occurs and is detectable, I try to
provide a useful error message that will help the user fix the issue.
2019-01-30 08:55:22 -08:00
Ethan Atkins 6725b39a84 Bump io to 1.3.0-M3
I had to turn off -Xfatal-warnings in commandProj because after updating
io, commandProj depends on the deprecated EventMonitor class. In #4335,
I stop using EventMonitor, but deprecate the Watched class which is both
defined and used (as an unused attribute key) in commandProj. I think we
can probably get rid of Watched in 1.4.x and certainly in a hypothetical
2.x, so hopefully we can restore -Xfatal-warnings sooner than later.

I also had to replace uses of IO.classLocationFile with
IO.classLocationPath to avoid compilation failures due to
-Xfatal-warnings.
2018-10-08 13:59:34 -07:00
Eugene Yokota ef49a95b7d address more warnings 2018-09-18 17:45:24 -04:00
Eugene Yokota 4b23036c63 contraband 0.4.1 2018-09-18 16:56:19 -04:00
eugene yokota 8af7a5acae
Merge pull request #4358 from eed3si9n/wip/license
Apache License 2.0
2018-09-14 11:11:17 -04:00
Eugene Yokota 4ff4f6e45e Update header 2018-09-14 04:53:36 -04:00
Eugene Yokota f3424e265c Formatting 2018-09-14 00:59:01 -04:00
Ignasi Marimon-Clos 66b485f559 Duplicate reports for backwards-compat adding a name-compliant copy 2018-09-04 18:15:30 +02:00
xuwei-k 6936ca024e use Java 7 and 8 features
- diamond operator
- lambda
2018-07-08 22:32:26 +09:00
Daniel Riquelme aee10cf036 Fix CTRL-C exception 2018-06-22 05:04:30 -04:00
Ethan Atkins 27e93601b5 Add warning for slow hostname lookups on OS X
I spent a lot of time debugging why it took 5 seconds to run tests each
time. It turns out that if the hostname is not set explicitly on os x,
then getaddrinfo takes 5 seconds to try (and fail) to resolve the dns
entry for the localhostname. This is easily fixed by setting the
hostname, but it is not at all easy to figure out that a slow hostname
lookup is the reason why tests are slow to start.

I don't know if this is a common issue on other platforms, so only issue
the warning on OS X.
2018-06-06 10:53:46 -07:00
Tim Harper 5cc0038a65 Little better comment. Add timestamp to example. 2018-05-14 20:57:04 -06:00
Tim Harper 3702132019 Keep single parameter constructor for backwards bin compat. 2018-05-14 17:31:05 -06:00
Tim Harper 13085138a5 Remove milliseconds from format in order to comply with JUnit spec 2018-05-14 17:30:15 -06:00
Tim Harper add6bde396 Add timestamp field to JUnitXML report 2018-05-14 12:42:24 -06:00
Eugene Yokota 28e90ea09b Merge branch '1.1.x' into wip/merge-1.1.x 2018-04-29 14:31:30 -04:00
Dale Wijnand 8f4b8abb7b
Run scalafmt & test:scalafmt 2018-04-24 16:12:10 +01:00
OlegYch eeeb4c9ff2 Remove usage of DynamicVariable and fix memory leak, fixes https://github.com/sbt/sbt/issues/4112 2018-04-23 20:46:08 +03:00
Eugene Yokota c2837c7714 Merge branch 'wip/bumpsbt' into wip/merge-1.1.x 2018-03-27 10:16:10 -04:00
Ethan Atkins 9b24e9f9eb Use ConcurrentLinkedDeque for EventHandler
ArrayList::add is not thread safe. I ran into cases where async tests
using utests would fail even when all of the individual tests passed.
This was because multiple threads called back into the handle method of
the handler instance variable, which just delegated to eventList::add.
When this happened, one of the events would get added to the list as a
null reference, which would manifest as an NPE upstream on the master
process. After this change, my tests stopped failing.
2018-03-21 10:50:30 -07:00
Dale Wijnand dd4de14593
Upgrade to contraband 0.4.0 2018-03-12 15:39:07 +00:00
eugene yokota 92c95ce290
Merge pull request #3997 from eed3si9n/wip/test-status-thread-safety
Fix race condition in non-forked, parallel tests.
2018-03-07 16:18:55 -05:00
Jason Zaugg 0bea7e9e18 Fix race condition in non-forked, parallel tests.
Non forked tests that are run in parallel groups can call into
a single instance of TestStatusReporter concurrently.

This seems to be limited to the startGroup/endGroup/testEvent
methods called in:

  a41727fb17/testing/src/main/scala/sbt/TestFramework.scala (L100-L124)

Which itself is called within:

  a41727fb17/testing/src/main/scala/sbt/TestFramework.scala (L203-L229)

Creating the `runnables` that are run in parallel (in builds so configured):

  a6eb1260c8/main-actions/src/main/scala/sbt/Tests.scala (L222-L230)

We believe this to be the cause of the hang witnessed in
the a suite of Scalacheck-framework tests in the Scala
build:

  https://github.com/scala/scala-jenkins-infra/issues/249

This commit uses a concurrent map to support concurrent
status updates.
2018-03-05 18:23:03 +10:00
Dale Wijnand 113656aed1
Remove compile warnings 2018-01-16 11:17:01 +00:00
eugene yokota 34d311f9ce
Merge pull request #3807 from dwijnand/remove-warnings
Remove warnings
2017-12-19 13:18:59 -05:00
Eugene Yokota 40b86ae412 bump modules and plugins 2017-12-16 12:22:42 -05:00
Dale Wijnand 072366d48e
Remove all warnings from testingProj 2017-12-14 13:19:23 +00:00
Simon Schäfer 93e08b7ee7 Fix warnings about unused pattern vars in various projects 2017-10-19 13:07:24 +02:00
Dale Wijnand a41727fb17
Add, configure & enforce file headers 2017-10-05 09:03:40 +01:00
Răzvan Flavius Panda 0124a8ad0e Fix unused imports warnings 2017-09-15 16:35:08 +01:00