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

Skip to content

[doc] Test hanging when try doc demo for zipWithLatest #4331

@counter2015

Description

@counter2015

According to doc here, I adjust a little as following:

import zio.Queue
import zio.duration._
import zio.test.Assertion.equalTo
import zio.test._
import zio.test.environment.TestClock
import zio.stream._
import zio.test.Eql.eqlReflexive

object ClockSpec extends DefaultRunnableSpec {
  def spec = suite("ClockSpec")(
    testM("zipWithLatest") {
      println("test start")
      val s1 = Stream.iterate(0)(_ + 1).fixed(100.milliseconds)
      val s2 = Stream.iterate(0)(_ + 1).fixed(70.milliseconds)
      val s3 = s1.zipWithLatest(s2)((_, _))

      for {
        q <- Queue.unbounded[(Int, Int)]
        _ <- s3.foreach(q.offer).fork
        a <- q.take
        _ <- TestClock.setTime(70.milliseconds)
        b <- q.take
        _ <- TestClock.setTime(100.milliseconds)
        c <- q.take
        _ <- TestClock.setTime(140.milliseconds)
        d <- q.take
        // it doesn't work too
        // _ <- TestClock.adjust(1.minute)
      } yield
        assert(a)(equalTo(0 -> 0)) &&
          assert(b)(equalTo(0 -> 1)) &&
          assert(c)(equalTo(1 -> 1)) &&
          assert(d)(equalTo(1 -> 2))
    }
  )
}

and then run sbt testOnly ClockSpec

testOnly ClockSpec
[info] done compiling
test start
Warning: A test is using time, but is not advancing the test clock, which may result in the test hanging. Use TestClock.adjust to manually advance the time.
In Suite "ClockSpec", test "zipWithLatest" has taken more than 1 m to execute. If this is not expected, consider using TestAspect.timeout to timeout runaway tests for faster diagnostics.

I tried add TestClock.adjust in for expressions, but it didn't work.

How could I run the test correctly?

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