question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use `TestControl.executeEmbed` for time-based tests

See original GitHub issue

I noticed a flake in the server TimeoutSuite yesterday and realized that many/all of our time-based tests are actually running against real time, I believe.

In Cats Effect 3.3 TestControl.executeEmbed was introduced as a way of running an IO against “simulated” time instead of real time. This allows the test to run much more quickly (since it can simulate a sleep instantly, instead of actually sleeping) and more reliably.

Cats Effect docs: https://typelevel.org/cats-effect/docs/core/test-runtime#full-execution

I recently used executeEmbed in https://github.com/typelevel/fs2/pull/2922, as an example 😃

So executeEmbed should be sprinkled in the appropriate places in our test suite. The Timeout suite is a good place to start 😃

https://github.com/http4s/http4s/blob/08d219ba64f08a3741ebf2816f97a81b9561269a/server/shared/src/test/scala/org/http4s/server/middleware/TimeoutSuite.scala#L30

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
FrancescoSerracommented, Jun 14, 2022

thanks @armanbilge and sorry for all the trouble!

1reaction
danichegcommented, Jun 14, 2022

I’ve tried to apply TestControl in tests and many times faced with this. But sure, maybe I was doing something wrong, just wanted to add some nota bene 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

http4s - bytemeta
Use `TestControl.executeEmbed` for time-based tests. christiankjaer. christiankjaer CLOSED · Updated 5 months ago · AuthMiddleware with Ember backend ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found