Merge pull request #1936 from akka/wip-3738-memory-leaks-in-tests-patriknw
=act #3738 Fix memory leaks in tests
This commit is contained in:
commit
37eddd716c
6 changed files with 34 additions and 12 deletions
|
|
@ -18,7 +18,7 @@ import scala.annotation.tailrec
|
||||||
import scala.collection.immutable
|
import scala.collection.immutable
|
||||||
import scala.concurrent.duration.{ FiniteDuration, Duration }
|
import scala.concurrent.duration.{ FiniteDuration, Duration }
|
||||||
import scala.concurrent.{ Await, Awaitable, CanAwait, Future, ExecutionContext, ExecutionContextExecutor }
|
import scala.concurrent.{ Await, Awaitable, CanAwait, Future, ExecutionContext, ExecutionContextExecutor }
|
||||||
import scala.util.{ Failure, Success }
|
import scala.util.{ Failure, Success, Try }
|
||||||
import scala.util.control.{ NonFatal, ControlThrowable }
|
import scala.util.control.{ NonFatal, ControlThrowable }
|
||||||
|
|
||||||
object ActorSystem {
|
object ActorSystem {
|
||||||
|
|
@ -568,7 +568,7 @@ private[akka] class ActorSystemImpl(val name: String, applicationConfig: Config,
|
||||||
|
|
||||||
val scheduler: Scheduler = createScheduler()
|
val scheduler: Scheduler = createScheduler()
|
||||||
|
|
||||||
val provider: ActorRefProvider = {
|
val provider: ActorRefProvider = try {
|
||||||
val arguments = Vector(
|
val arguments = Vector(
|
||||||
classOf[String] -> name,
|
classOf[String] -> name,
|
||||||
classOf[Settings] -> settings,
|
classOf[Settings] -> settings,
|
||||||
|
|
@ -576,6 +576,10 @@ private[akka] class ActorSystemImpl(val name: String, applicationConfig: Config,
|
||||||
classOf[DynamicAccess] -> dynamicAccess)
|
classOf[DynamicAccess] -> dynamicAccess)
|
||||||
|
|
||||||
dynamicAccess.createInstanceFor[ActorRefProvider](ProviderClass, arguments).get
|
dynamicAccess.createInstanceFor[ActorRefProvider](ProviderClass, arguments).get
|
||||||
|
} catch {
|
||||||
|
case NonFatal(e) ⇒
|
||||||
|
Try(stopScheduler())
|
||||||
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
def deadLetters: ActorRef = provider.deadLetters
|
def deadLetters: ActorRef = provider.deadLetters
|
||||||
|
|
@ -602,7 +606,7 @@ private[akka] class ActorSystemImpl(val name: String, applicationConfig: Config,
|
||||||
def /(actorName: String): ActorPath = guardian.path / actorName
|
def /(actorName: String): ActorPath = guardian.path / actorName
|
||||||
def /(path: Iterable[String]): ActorPath = guardian.path / path
|
def /(path: Iterable[String]): ActorPath = guardian.path / path
|
||||||
|
|
||||||
private lazy val _start: this.type = {
|
private lazy val _start: this.type = try {
|
||||||
// the provider is expected to start default loggers, LocalActorRefProvider does this
|
// the provider is expected to start default loggers, LocalActorRefProvider does this
|
||||||
provider.init(this)
|
provider.init(this)
|
||||||
if (settings.LogDeadLetters > 0)
|
if (settings.LogDeadLetters > 0)
|
||||||
|
|
@ -611,6 +615,12 @@ private[akka] class ActorSystemImpl(val name: String, applicationConfig: Config,
|
||||||
loadExtensions()
|
loadExtensions()
|
||||||
if (LogConfigOnStart) logConfiguration()
|
if (LogConfigOnStart) logConfiguration()
|
||||||
this
|
this
|
||||||
|
} catch {
|
||||||
|
case NonFatal(e) ⇒
|
||||||
|
try {
|
||||||
|
shutdown()
|
||||||
|
} catch { case NonFatal(_) ⇒ Try(stopScheduler()) }
|
||||||
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
def start(): this.type = _start
|
def start(): this.type = _start
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import akka.actor.Status.Failure
|
||||||
/**
|
/**
|
||||||
* Tests the features of the Camel Producer.
|
* Tests the features of the Camel Producer.
|
||||||
*/
|
*/
|
||||||
class ProducerFeatureTest extends TestKit(ActorSystem("test", AkkaSpec.testConf)) with WordSpecLike with BeforeAndAfterAll with BeforeAndAfterEach with Matchers {
|
class ProducerFeatureTest extends TestKit(ActorSystem("ProducerFeatureTest", AkkaSpec.testConf)) with WordSpecLike with BeforeAndAfterAll with BeforeAndAfterEach with Matchers {
|
||||||
|
|
||||||
import ProducerFeatureTest._
|
import ProducerFeatureTest._
|
||||||
implicit def camel = CamelExtension(system)
|
implicit def camel = CamelExtension(system)
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,9 @@ import scala.collection.immutable.Seq
|
||||||
//#plugin-imports
|
//#plugin-imports
|
||||||
|
|
||||||
import com.typesafe.config._
|
import com.typesafe.config._
|
||||||
|
|
||||||
import org.scalatest.WordSpec
|
import org.scalatest.WordSpec
|
||||||
|
import scala.concurrent.duration._
|
||||||
|
import akka.testkit.TestKit
|
||||||
|
|
||||||
import akka.actor.ActorSystem
|
import akka.actor.ActorSystem
|
||||||
//#plugin-imports
|
//#plugin-imports
|
||||||
|
|
@ -69,8 +70,12 @@ class PersistencePluginDocSpec extends WordSpec {
|
||||||
//#snapshot-store-plugin-config
|
//#snapshot-store-plugin-config
|
||||||
"""
|
"""
|
||||||
|
|
||||||
val system = ActorSystem("doc", ConfigFactory.parseString(providerConfig).withFallback(ConfigFactory.parseString(PersistencePluginDocSpec.config)))
|
val system = ActorSystem("PersistencePluginDocSpec", ConfigFactory.parseString(providerConfig).withFallback(ConfigFactory.parseString(PersistencePluginDocSpec.config)))
|
||||||
val extension = Persistence(system)
|
try {
|
||||||
|
Persistence(system)
|
||||||
|
} finally {
|
||||||
|
TestKit.shutdownActorSystem(system, 10.seconds, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@
|
||||||
package docs.persistence
|
package docs.persistence
|
||||||
|
|
||||||
import com.typesafe.config._
|
import com.typesafe.config._
|
||||||
|
import scala.concurrent.duration._
|
||||||
import org.scalatest.WordSpec
|
import org.scalatest.WordSpec
|
||||||
|
|
||||||
import akka.actor.ActorSystem
|
import akka.actor.ActorSystem
|
||||||
import akka.serialization.{ Serializer, SerializationExtension }
|
import akka.serialization.{ Serializer, SerializationExtension }
|
||||||
|
import akka.testkit.TestKit
|
||||||
|
|
||||||
class PersistenceSerializerDocSpec extends WordSpec {
|
class PersistenceSerializerDocSpec extends WordSpec {
|
||||||
|
|
||||||
|
|
@ -29,7 +29,12 @@ class PersistenceSerializerDocSpec extends WordSpec {
|
||||||
//#custom-serializer-config
|
//#custom-serializer-config
|
||||||
""".stripMargin
|
""".stripMargin
|
||||||
|
|
||||||
SerializationExtension(ActorSystem("doc", ConfigFactory.parseString(customSerializerConfig)))
|
val system = ActorSystem("PersistenceSerializerDocSpec", ConfigFactory.parseString(customSerializerConfig))
|
||||||
|
try {
|
||||||
|
SerializationExtension(system)
|
||||||
|
} finally {
|
||||||
|
TestKit.shutdownActorSystem(system, 10.seconds, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyPayload
|
class MyPayload
|
||||||
|
|
|
||||||
|
|
@ -160,8 +160,8 @@ abstract class Ticket1978CommunicationSpec(val cipherConfig: CipherConfig) exten
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
"not be run when the cipher is not supported by the platform this test is currently being executed on" ignore {
|
"not be run when the cipher is not supported by the platform this test is currently being executed on" in {
|
||||||
|
pending
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,8 @@ abstract class AkkaSpec(_system: ActorSystem)
|
||||||
|
|
||||||
val log: LoggingAdapter = Logging(system, this.getClass)
|
val log: LoggingAdapter = Logging(system, this.getClass)
|
||||||
|
|
||||||
|
override val invokeBeforeAllAndAfterAllEvenIfNoTestsAreExpected = true
|
||||||
|
|
||||||
final override def beforeAll {
|
final override def beforeAll {
|
||||||
startCoroner
|
startCoroner
|
||||||
atStartup()
|
atStartup()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue