Skip to content

Commit

Permalink
Fix initializer6 test
Browse files Browse the repository at this point in the history
  • Loading branch information
projedi committed Mar 26, 2020
1 parent 7295cc0 commit b419101
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions backend.native/tests/runtime/basic/initializers6.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlin.test.*

import kotlin.native.concurrent.*

val aWorkerId = 2
val aWorkerId = AtomicInt(0)
val bWorkersCount = 3

val aWorkerUnlocker = AtomicInt(0)
Expand All @@ -18,35 +18,34 @@ val bWorkerUnlocker = AtomicInt(0)
object A {
init {
// Must be called by aWorker only.
assertEquals(aWorkerId, Worker.current.id)
assertEquals(aWorkerId.value, Worker.current.id)
// Only allow b workers to run, when a worker has started initialization.
bWorkerUnlocker.increment()
// Only proceed with initialization, when all b workers have started executing.
while (aWorkerUnlocker.value < bWorkersCount) {}
// And now wait a bit, to increase probability of races.
Worker.current.park(1000 * 1000L)
Worker.current.park(100 * 1000L)
}
val a = produceA()
val b = produceB()
}

fun produceA(): String {
// Must've been called by aWorker only.
assertEquals(aWorkerId, Worker.current.id)
assertEquals(aWorkerId.value, Worker.current.id)
return "A"
}

fun produceB(): String {
// Must've been called by aWorker only.
assertEquals(aWorkerId, Worker.current.id)
assertEquals(aWorkerId.value, Worker.current.id)
// Also check that it's ok to get A.a while initializing A.b.
return "B+${A.a}"
}

@Test fun runTest() {
val aWorker = Worker.start()
// This test relies on aWorkerId value.
assertEquals(aWorkerId, aWorker.id)
aWorkerId.value = aWorker.id
val bWorkers = Array(bWorkersCount, { _ -> Worker.start() })

val aFuture = aWorker.execute(TransferMode.SAFE, {}, {
Expand Down

0 comments on commit b419101

Please sign in to comment.