Skip to content

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

Merged
adamw merged 3 commits into
softwaremill:masterfrom
ivan-klass:proper-cats-resources
Jan 31, 2025
Merged

Refactor ServerRunner to use Resource, fix unsafe .allocated cases#4267
adamw merged 3 commits into
softwaremill:masterfrom
ivan-klass:proper-cats-resources

Conversation

@ivan-klass

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

Copy link
Copy Markdown
Contributor

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

adamw commented Jan 31, 2025

Copy link
Copy Markdown
Member

Great changes, thanks! :)

@adamw adamw merged commit 32ccf15 into softwaremill:master Jan 31, 2025
@ivan-klass ivan-klass deleted the proper-cats-resources branch February 17, 2026 21:43
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