Hey - I have some code that uses ZIO Clock service.
It's a very simple service method which does the following:
get current nanos using Clock.currentTime
create a token with timeout (timeoutNanos)
store token & timeout in Redis: redis.set(token, currentNanos + timeoutNanos)
When I run tests (which then uses TestClock) and a real Redis container the SingleNodeExecutor hangs indefinitly and it gives me the following warning:
thread=#zio-fiber-236 message="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." location=zio.redis.SingleNodeExecutor.run file=SingleNodeExecutor.scala line=40
Relevant method from TokenService service:
def create(lifetime: Option[zio.Duration], refId: Option[String]): IO[TokenStoreError, Token] = (for {
nowNanos <- Clock.currentTime(TimeUnit.NANOSECONDS)
token <- generate()
maybeSuffix = refId.map("." + _).getOrElse("")
_ <- (lifetime match {
case Some(Duration.Infinity) => redis.set(Token.unwrap(token) + maybeSuffix, 0, None)
case Some(Duration.Zero) => ZIO.succeed(true)
case Some(finite) => redis.set(Token.unwrap(token) + maybeSuffix, (nowNanos + finite.toNanos), Some(finite))
case None => ZIO.succeed(true)
})
} yield token)
.logError(s"Failed to create new Token with lifetime $lifetime and refId $refId")
.mapError(e => TokenStoreError.TokenCreationFailed(e.getMessage))
Hey - I have some code that uses ZIO Clock service. It's a very simple service method which does the following:
When I run tests (which then uses TestClock) and a real Redis container the SingleNodeExecutor hangs indefinitly and it gives me the following warning:
Relevant method from
TokenService
service:code in zio-test spec (that test should fail):