8000 Shared Layers by adamgfraser · Pull Request #5563 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 5 commits into from
Sep 13, 2021
Merged

Shared Layers #5563

merged 5 commits into from
Sep 13, 2021

Conversation

adamgfraser
Copy link
Contributor

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.

@adamgfraser adamgfraser requested a review from jdegoes September 9, 2021 00:56

def spec: ZSpec[R with TestEnvironment with Has[ZIOAppArgs], Any]

def aspects: Chunk[TestAspect[Nothing, R with TestEnvironment with Has[ZIOAppArgs], Nothing, Any]] =
Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Member

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 =>
Copy link
Contributor Author

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.

Copy link
Contributor Author
10000

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.

Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member
@jdegoes jdegoes left a 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!

@jdegoes jdegoes merged commit 79837b0 into zio:series/2.x Sep 13, 2021
@adamgfraser adamgfraser deleted the shared branch September 16, 2021 23:34
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
0