首页 > 解决方案 > 调整测试时钟时间时 Zio 测试计划不重复

问题描述

我正在尝试测试需要重复的逻辑(随着时间的推移)

我的测试代码如下所示:

 val repeatSchedule = Schedule.fixed(1 second) && Schedule.recurs(10) // 10 times, 1 second each time
 val logic = for {
    now <- ContextModule.now // ContextModule wraps several stuff among with a zio clock
    _ <- zio.console.putStrLn("now: " + now) // for debugging
    x <- [WHATEVER TESTING LOGIC]
    }
  } yield x

  for {
    fiber <- logic.provideCustomLayer(ContextModule.live).repeat(repeatSchedule).fork
    _ <- TestClock.adjust(10 second)
    x <- fiber.join
  } yield assert(x)(Assertion.equalTo(y))
})

我确实希望logic按照我提供的时间表重复(10 次,每秒一次),使用假时间,每次 10 秒都提前一次。但是,只执行一次,然后进程挂起(没有警告消息或任何东西,例如,当您忘记手动调整时间时logic,我没有分类)。A test is using time, but is not advancing the test clock在控制台中,我读到now: 1970-01-01T00:00:10Z测试时钟已正确注入,但重复从未发生。

我错过了什么?谢谢

标签: scalascheduleziozio-test

解决方案


推荐阅读