Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ServerRunner to use Resource, fix unsafe .allocated cases #4267

Merged
merged 3 commits into from
Jan 31, 2025

Conversation

ivan-klass
Copy link
Contributor

@ivan-klass ivan-klass commented Jan 14, 2025

The ServerRunner interface was refactored to provide more idiomatic Resource[IO, Unit] rather than unsafe IO[IO[Unit]].

The Cats-based test server now also provides a properly scoped server resource instead of unfair wrap Resource.eval(underlyingResource.allocated.map(_._2)). The previous approach was leaky — imagine

//  Underlying resource won't release!
resource.use(release => IO.raiseError(new AssertionError("test failed")) *> release)

Now, the resource is guaranteed to be released at the end of the test, regardless of whether it was released within the test scope or not.

@ivan-klass ivan-klass force-pushed the proper-cats-resources branch 2 times, most recently from 58201b8 to 84ea3d5 Compare January 15, 2025 08:03
@ivan-klass ivan-klass marked this pull request as draft January 22, 2025 15:37
@ivan-klass ivan-klass force-pushed the proper-cats-resources branch from 5ce6acd to d326dc4 Compare January 22, 2025 19:15
@ivan-klass ivan-klass force-pushed the proper-cats-resources branch from d326dc4 to 2044178 Compare January 22, 2025 19:17
@ivan-klass ivan-klass changed the title Cleanup cats.effect.Resource code for Http Server Refactor ServerRunner to use Resource, fix unsafe .allocated cases Jan 23, 2025
@ivan-klass ivan-klass marked this pull request as ready for review January 23, 2025 07:28
@adamw
Copy link
Member

adamw commented Jan 31, 2025

Great changes, thanks! :)

@adamw adamw merged commit 32ccf15 into softwaremill:master Jan 31, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants