-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Shared Layers #5563
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
Shared Layers #5563
Conversation
|
||
def spec: ZSpec[R with TestEnvironment with Has[ZIOAppArgs], Any] | ||
|
||
def aspects: Chunk[TestAspect[Nothing, R with TestEnvironment with Has[ZIOAppArgs], Nothing, Any]] = |
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.
Combination of aspects is somewhat ill defined here. It doesn't really matter because a combined spec will run each individual spec with its own aspects, which is the right thing to do I think, but not clear what the interpretation of calling this on a combined spec should be. Perhaps it should be empty in the case of combined specs?
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.
If you think of this as a tree like structure and aspects
as representing aspects at that level of the tree then empty actually makes sense here. When we combine two specs each spec may have its own aspects but there are no aspects that apply to the entire tree at that point. We could potentially add an operator allowing adding additional aspects to the new root.
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.
I agree that in the composition, this should be empty since the aspects have been pushed into the tests. Really, aspects
is just a sort of "lazy application" of aspecs to those tests defined in spec
, so this is the only sensible composition.
import zio.test.render._ | ||
|
||
@EnableReflectiveInstantiation | ||
abstract class ZIOSpec[R <: Has[_]: Tag](val layer: ZLayer[TestEnvironment, Any, R]) extends ZIOApp { self => |
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.
Ideally would like to unify over the case where the environment is Any
. May be able to use Has.Union
to do this.
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.
May just be easier to have DefaultZIOSpec
and ZIOSpec
here.
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.
I think this val layer
could as well be a def
, since we are using def
style for spec
and it's odd to mix the two styles.
I agree on ZIOSpec
and ZIOSpecDefault
. I'd even suggest that the latter extend the former, so everything can be treated as a ZIOSpec
.
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.
import zio.test.environment.TestEnvironment | ||
import zio.test.render._ | ||
|
||
@EnableReflectiveInstantiation |
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.
This will only work with a non-polymorphic trait. Hence the need to have a dummy parent without type parameters (only type members).
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.
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.
Although this may be tweaked a bit in the future, it's a great step forward, will merge now. Thank you for your work on this!
Resolves #4519. Resolves #5093. Resolves #5536.
Implements
ZIOSpec
, a spec that includes a layer that will be globally shared. Combining specs results in a new spec where running the spec will build the layers from all of the specs and then provide them to all the tests, so memoization of layers will automatically take care of making sure we don't build the same layer twice.The next step, still to be done here, is to update the SBT test runner to reflectively instantiate all specs and then to combine them into a single spec to achieve global sharing of layers across tests.