Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TestClock hangs on parallelism #9385

@mhverbakel

Description

@mhverbakel

When using the TestClock, the adjust (or more specifically, run) method synchronizes across fibers to only adjust when the system is at rest. However, due to this checking mechanism, two parallel adjusts will result in a livelock between the two freeze methods.

Reproduction:

import zio.*
import zio.test.*

object Test extends ZIOSpecDefault {
  override def spec: Spec[TestEnvironment with Scope, Any] =
    test("no problem on sequential calls")(
      (TestClock.adjust(1.second) *> TestClock.adjust(1.second)).as(assertCompletes)
    ) + test("livelock on parallel calls")(
      (TestClock.adjust(1.second) &> TestClock.adjust(1.second)).as(assertCompletes)
    ) @@ TestAspect.timeout(10.seconds)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions