Skip to content

Commit

Permalink
test: Debug failing tests on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Nov 5, 2024
1 parent 4ffadcb commit 4271988
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 19 deletions.
2 changes: 2 additions & 0 deletions frontend/src/main/scala/bloop/data/ClientInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ object ClientInfo {

projectsToVisit.foreach {
case (project, client) =>
out.println(s"Parent ${client.parentForClientClassesDirectories(project)}")
client.parentForClientClassesDirectories(project) match {
case None =>
() // If owns build files, original generic classes dirs are used
Expand All @@ -289,6 +290,7 @@ object ClientInfo {
try {
Paths.list(bspClientClassesDir).foreach { clientDir =>
try {
out.println(s"Checking for orphan directory in ${clientDir}")
val dirName = clientDir.underlying.getFileName().toString
val attrs =
Files.readAttributes(clientDir.underlying, classOf[BasicFileAttributes])
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/main/scala/bloop/engine/State.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object State {
val opts = CommonOptions.default
val cwd = opts.workingPath
val clientInfo = ClientInfo.CliClientInfo(useStableCliDirs = true, () => true)
val results = ResultsCache.load(build, cwd, cleanOrphanedInternalDirs = false, logger)
val results = ResultsCache.load(build, cwd, cleanOrphanedInternalDirs = true, logger)
State(
build,
results,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ object ResultsCache {
fileName.startsWith(genericClassesName) &&
path != analysisClassesDir.underlying
if (isOrphan) {
logger.debug(
s"Discovered orphan directory $path"
)(DebugFilter.All)
orphanInternalDirs.+=(path)
}
}
Expand Down
41 changes: 24 additions & 17 deletions frontend/src/test/scala/bloop/bsp/BspCompileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import bloop.util.TestProject
import bloop.util.TestUtil

import coursierapi.Fetch
import scala.util.control.NonFatal

object TcpBspCompileSpec extends BspCompileSpec(BspProtocol.Tcp)
object LocalBspCompileSpec extends BspCompileSpec(BspProtocol.Local)
Expand Down Expand Up @@ -172,7 +173,7 @@ class BspCompileSpec(
}
}

testMac(
testNonWindows(
"create orphan client classes directory and make sure loading a BSP session cleans it up"
) {
TestUtil.withinWorkspace { workspace =>
Expand Down Expand Up @@ -207,22 +208,28 @@ class BspCompileSpec(
val _ = bspState.scalaOptions(`A`)
}

// Wait until the extra directory is finally deleted at the end of the bsp session
TestUtil.await(
FiniteDuration(10, TimeUnit.SECONDS),
bloop.engine.ExecutionContext.ioScheduler
) {
Task {
var check: Boolean = true
while (check) {
// The task cleaning up client classes directories should have removed the extra dir
check = orphanClientClassesDir.exists && orphanInternalClassesDir.exists
Thread.sleep(100)
}
}.timeoutTo(
FiniteDuration(5, TimeUnit.SECONDS),
Task(sys.error(s"Expected deletion of $orphanClientClassesDir"))
)
try {
// Wait until the extra directory is finally deleted at the end of the bsp session
TestUtil.await(
FiniteDuration(10, TimeUnit.SECONDS),
bloop.engine.ExecutionContext.ioScheduler
) {
Task {
var check: Boolean = true
while (check) {
// The task cleaning up client classes directories should have removed the extra dir
check = orphanClientClassesDir.exists && orphanInternalClassesDir.exists
Thread.sleep(100)
}
}.timeoutTo(
FiniteDuration(5, TimeUnit.SECONDS),
Task(sys.error(s"Expected deletion of $orphanClientClassesDir"))
)
}
} catch {
case NonFatal(e) =>
println(logger.render)
throw e
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions shared/src/main/scala/bloop/logging/FlushingOutputStream.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package bloop.logging

import java.io.ByteArrayOutputStream

class FlushingOutputStream(write: String => Unit) extends ByteArrayOutputStream {

override def flush(): Unit = {
// Write the contents of the internal byte array to the other OutputStream
write(this.toByteArray().toString())
}

override def close(): Unit = {
flush();
super.close();
}

}
5 changes: 4 additions & 1 deletion shared/src/main/scala/bloop/logging/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ abstract class Logger extends xsbti.Logger with BaseSbtLogger {

// Duplicate the standard output so that we get printlns from the compiler
protected def redirectOutputToLogs(out: PrintStream) = {
System.setOut(new TeeOutputStream(out))
val baos = new FlushingOutputStream(info)
val tee = new TeeOutputStream(out)
tee.addListener(baos)
System.setOut(tee)
}

/** The name of the logger */
Expand Down

0 comments on commit 4271988

Please sign in to comment.