mirror of
https://github.com/apple/pkl.git
synced 2026-09-13 21:31:52 +02:00
Improve thread safety for pkl:base (#1719)
Stdlib modules are singletons that are shared across multiple evaluators. This improves thread safety by evaluating its `output.bytes` during initialization, which initializes truffle nodes (e.g. TypeTestNode), and also initializes the member cache of the module output of `pkl:base`
This commit is contained in:
@@ -772,6 +772,23 @@ class EvaluatorTest {
|
||||
.doesNotThrowAnyException()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `concurrent evals`() {
|
||||
val exceptions = mutableListOf<Throwable>()
|
||||
val threads =
|
||||
(0..10).map {
|
||||
Thread { Evaluator.preconfigured().use { ev -> ev.evaluateOutputText(text("foo = 1")) } }
|
||||
.also { t ->
|
||||
t.uncaughtExceptionHandler = Thread.UncaughtExceptionHandler { _, e ->
|
||||
synchronized(exceptions) { exceptions.add(e) }
|
||||
}
|
||||
t.start()
|
||||
}
|
||||
}
|
||||
for (t in threads) t.join()
|
||||
exceptions.firstOrNull()?.let { throw it }
|
||||
}
|
||||
|
||||
private fun checkModule(module: PModule) {
|
||||
assertThat(module.properties.size).isEqualTo(2)
|
||||
assertThat(module.getProperty("name")).isEqualTo("pigeon")
|
||||
|
||||
Reference in New Issue
Block a user