-
Notifications
You must be signed in to change notification settings - Fork 1.4k
zio-test: Ignored annotated suites should not trigger shared layer creation #10234
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
Conversation
fde50d0 to
caa3e4a
Compare
851a773 to
86dd7be
Compare
bb4d5ff to
44f562c
Compare
44f562c to
6755420
Compare
|
Could you provide an explanation on why / how this works? It's not obvious to me how this change affects the behaviour w.r.t. tags |
| Spec.scoped[R0] { | ||
| ZIO.scopeWith { scope => | ||
| import Spec.RichLayer | ||
|
|
||
| val scopedLayer: ZLayer[R0, E1, R] = | ||
| ZLayer.makeSome[R0, R]( | ||
| ZLayer.succeed(scope), | ||
| layer.extendScope | ||
| ) | ||
|
|
||
| scopedLayer.memoizeWithinScope(scope).map { memoizedLayer => | ||
| Spec.multiple(specs.map(_.provideLayer(memoizedLayer))) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to reuse memoize to avoid code duplication. Also let's chain the methods together, creating a separate val for the scoped layer feels like it should be used more than once:
Spec.scoped[R0] {
ZIO.scopeWith { scope =>
ZLayer
.makeSome[R0, R](
ZLayer.succeed(scope),
layer.extendScope
)
.memoize
.map { memoizedLayer =>
Spec.multiple(specs.map(_.provideLayer(memoizedLayer)))
}
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 🙂
| Spec.scoped[R0] { | ||
| ZIO.scopeWith { scope => | ||
| val scopedLayer: ZLayer[R0, E1, R1] = | ||
| ZLayer.makeSome[R0, R1]( | ||
| ZLayer.succeed(scope), | ||
| layer.extendScope | ||
| ) | ||
|
|
||
| scopedLayer.memoizeWithinScope(scope).map { memoizedLayer => | ||
| Spec.multiple(specs.map(_.provideSomeLayer[R0](memoizedLayer))) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 🙂
| private implicit final class RichLayer[RIn, E0, ROut](private val layer: ZLayer[RIn, E0, ROut]) extends AnyVal { | ||
|
|
||
| /** | ||
| * Version of `ZLayer::memoize` that uses the provided scope. | ||
| */ | ||
| def memoizeWithinScope(scope: Scope)(implicit trace: Trace): ZIO[Any, Nothing, ZLayer[RIn, E0, ROut]] = | ||
| layer.build(scope).memoize.map(ZLayer.fromZIOEnvironment(_)) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I need to be able to ignore some tests by tagging them and use
-ignore-tags <tag>But I noticed that if my tests use
.provideSharedthen the layers inside are launched even if my entire suite (including the.provideShared) is flagged to not be run.Example:
Before the changes in this PR, the
TestContainersPG.layerwas always started, even if I launched my tests with the-ignore-tags dontRunoptionWith these changes, the
TestContainersPG.layeris not started when I launch my tests with with the-ignore-tags dontRunoption 🎉My test launched in an env without Docker before these changes:
Same test with these changes: