Skip to content

Commit

Permalink
add test for cached unificator thread safety
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed Jul 6, 2020
1 parent 5dcdef4 commit d781ca0
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package it.unibo.tuprolog.unify

import it.unibo.tuprolog.core.Substitution
import it.unibo.tuprolog.unify.testutils.UnificatorUtils.successfulUnifications
import java.util.*
import java.util.concurrent.Executors
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
import kotlin.test.Test
import kotlin.test.assertTrue

class TestThreadSafety {
@Test
fun testCachedUnificatorThreadSafety() {
val executors = Executors.newFixedThreadPool(8)
val results: MutableList<Future<Substitution>> = Collections.synchronizedList(LinkedList())
val unificator = Unificator.cached(Unificator.strict())
for (i in 1 .. 100) {
for (equation in successfulUnifications.keys) {
results.add(executors.submit<Substitution> {
unificator.mgu(equation.lhs, equation.rhs)
})
}
}
executors.shutdown()
executors.awaitTermination(1, TimeUnit.MINUTES)
for (res in results) {
assertTrue { res.get() is Substitution.Unifier }
}
}
}

0 comments on commit d781ca0

Please sign in to comment.