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

Fixed RD-10460: LocalInferrerService is not stopped #329

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ object CompilerServiceProvider {
private[raw] def set(language: Set[String], instance: CompilerService): Unit = {
instanceLock.synchronized {
if (instance == null) {
instanceMap.remove((language, None))
// stop and remove entries that match the `language`, regardless the class loader.
instanceMap.filterKeys(_._1 == language).foreach {
case (key, compiler) =>
compiler.stop()
instanceMap.remove(key)
}
} else {
instanceMap.put((language, None), instance)
}
Expand Down
3 changes: 2 additions & 1 deletion snapi-client/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// Default to local credentials service.
raw.creds.impl = "local"
raw.creds.impl = "local"
raw.creds.impl = ${?CREDS_IMPL}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ class Rql2TruffleCompilerService(maybeClassLoader: Option[ClassLoader] = None)(
val inferrer = InferrerServiceProvider(maybeClassLoader)

// Initialize compiler context
new CompilerContext(language, user, inferrer, sourceContext, maybeClassLoader)
try {
new CompilerContext(language, user, inferrer, sourceContext, maybeClassLoader)
} catch {
case NonFatal(ex) =>
inferrer.stop()
throw ex
}
}

private def getProgramContext(user: AuthenticatedUser, environment: ProgramEnvironment): ProgramContext = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ trait Rql2CompilerServiceTestContext extends BeforeAndAfterAll {
}

override def afterAll(): Unit = {
instance.stop()
setCompilerService(null)
super.afterAll()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package raw.compiler.rql2.truffle

import raw.client.rql2.truffle.Rql2TruffleCompilerService
import raw.compiler.rql2.api.Rql2CompilerServiceTestContext
import raw.runtime.truffle.RawLanguage
import raw.utils.{RawTestSuite, RawUtils, SettingsTestContext}

trait Rql2TruffleCompilerServiceTestContext extends Rql2CompilerServiceTestContext {
Expand All @@ -23,6 +24,9 @@ trait Rql2TruffleCompilerServiceTestContext extends Rql2CompilerServiceTestConte

override def beforeAll(): Unit = {
super.beforeAll()
// Forcibly drop all language caches before each test suite.
RawLanguage.dropCaches()

property("raw.compiler.impl", "rql2-truffle")

rql2TruffleCompilerService = new Rql2TruffleCompilerService
Expand All @@ -34,6 +38,8 @@ trait Rql2TruffleCompilerServiceTestContext extends Rql2CompilerServiceTestConte
RawUtils.withSuppressNonFatalException(rql2TruffleCompilerService.stop())
rql2TruffleCompilerService = null
}
// Forcibly drop all language caches after each test suite.
RawLanguage.dropCaches()
super.afterAll()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package raw.compiler.rql2.truffle

import raw.compiler.rql2.api.Rql2OutputTestContext
import raw.compiler.rql2.tests.CompilerTestContext
import raw.runtime.truffle.RawLanguage

class TruffleCompilerTestContext
extends CompilerTestContext
Expand All @@ -23,13 +22,9 @@ class TruffleCompilerTestContext

override def beforeAll(): Unit = {
super.beforeAll()
// Forcibly drop all language caches before each test suite.
RawLanguage.dropCaches()
}

override def afterAll(): Unit = {
// Forcibly drop all language caches after each test suite.
RawLanguage.dropCaches()
super.afterAll()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ trait CredentialsTestContext extends BeforeAndAfterAll {
newHttpCreds.foreach { case (user, (name, cred)) => credentials.registerNewHttpCredential(user, name, cred) }
dropboxTokens.foreach { case (user, token) => credentials.registerDropboxToken(user, token) }
secrets.foreach { case (user, secret) => credentials.registerSecret(user, secret) }
// Set the system properties for the credentials so that this is overriding what RawLanguage
// runs with. This way, the credential server booted by the test framework is used.
for (property <- Seq("raw.creds.impl", "raw.creds.client.server-address")) {
System.clearProperty(property)
settings.getStringOpt(property).foreach(v => System.setProperty(property, v))
}
}

override def afterAll(): Unit = {
Expand Down
14 changes: 10 additions & 4 deletions utils/src/test/scala/raw/utils/RawTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,25 @@ trait RawTestSuite extends FixtureAnyFunSuite with BeforeAndAfterAll with Strict
}

override def beforeAll(): Unit = {
// If a previous test suite crashed, clean its leftovers anyway.
RawService.stopAll()
super.beforeAll()
}

protected def serviceCanBeRunning(service: RawService) = true

private def servicesAreStopped = RawService.services.asScala.forall(s => serviceCanBeRunning(s))

override def afterAll(): Unit = {
logger.info("Checking if all services have stopped")
var attempts = 10
while (!RawService.isStopped() && attempts > 0) {
while (!servicesAreStopped && attempts > 0) {
attempts -= 1
logger.debug(s"Waiting for services to terminate gracefully. Attempts left: $attempts")
Thread.sleep(1000)
}
assert(RawService.isStopped(), s"Not all services stopped properly. Still running: ${RawService.services}")
assert(
servicesAreStopped,
s"Not all services stopped properly. Still running:\n"
+ RawService.services.asScala.map(s => s"- $s: can be running = ${serviceCanBeRunning(s)}").mkString("\n")
)
}
}
Loading