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

DisciplineFSuite: fix race condition #555

Merged
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
17 changes: 10 additions & 7 deletions modules/discipline/src/weaver/discipline/Discipline.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package weaver
package discipline

import scala.collection.mutable
import scala.util.control.NoStackTrace

import cats.data.Kleisli
Expand Down Expand Up @@ -49,9 +50,10 @@ trait DisciplineFSuite[F[_]] extends RunnableSuite[F] {
def maxRuleSetParallelism: Int = 10000

protected def registerTest(tests: Res => F[List[F[TestOutcome]]]): Unit =
testsSeq.synchronized {
registeredTests.synchronized {
if (isInitialized) throw initError()
testsSeq = testsSeq :+ tests
registeredTests += tests
()
}

def checkAll(
Expand All @@ -72,7 +74,7 @@ trait DisciplineFSuite[F[_]] extends RunnableSuite[F] {
executeProp(prop, name.location, parameters)
)
foundProps.synchronized {
foundProps = foundProps :+ name.copy(propTestName)
foundProps += name.copy(propTestName)
}
Test(propTestName, runProp)
}).run
Expand All @@ -86,12 +88,12 @@ trait DisciplineFSuite[F[_]] extends RunnableSuite[F] {
}

override def spec(args: List[String]): Stream[F, TestOutcome] =
testsSeq.synchronized {
registeredTests.synchronized {
if (!isInitialized) isInitialized = true
val suiteParallelism = math.max(1, maxSuiteParallelism)
val ruleSetParallelism = math.max(1, maxRuleSetParallelism)
Stream.resource(sharedResource).flatMap { resource =>
Stream.emits(testsSeq).covary[F]
Stream.emits(registeredTests).covary[F]
.parEvalMap(suiteParallelism)(_.apply(resource))
.map { ruleSet =>
Stream.emits(ruleSet).covary[F]
Expand All @@ -104,9 +106,10 @@ trait DisciplineFSuite[F[_]] extends RunnableSuite[F] {
override def plan: List[TestName] =
foundProps.synchronized { foundProps.toList }

private[this] var foundProps = Seq.empty[TestName]
private[this] val foundProps = mutable.Buffer.empty[TestName]

private[this] var testsSeq = Seq.empty[Res => F[List[F[TestOutcome]]]]
private[this] val registeredTests =
mutable.Buffer.empty[Res => F[List[F[TestOutcome]]]]

private[this] var isInitialized = false

Expand Down