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

sealed ZHub - problem with test instance #5045

Closed
PawelJ-PL opened this issue May 5, 2021 · 4 comments
Closed

sealed ZHub - problem with test instance #5045

PawelJ-PL opened this issue May 5, 2021 · 4 comments

Comments

@PawelJ-PL
Copy link

Hi,

I've found a pretty fresh PR #4925 (already merged). This approach makes unit tests more complicated. Normally I would create my custom implementation of ZHub for the test which would use Ref to collect published messages (to verify them later in the test). But since this change it's impossible.
Now I have to implement not nice solution like:

 for {
      internalMessages    <- Ref.make[List[InternalMessage]](List.empty)
      internalTopic       <- Hub.bounded[InternalMessage](16)
      internalMessageCollector =
        ZStream.fromHub(internalTopic).run(ZSink.foreach(message => internalMessages.update(prev => prev :+ message)))
      serviceQuery = UsersService.createUser(newUserReq)
      user                <- internalMessageCollector.raceEither(serviceQuery).rightOrFail(new RuntimeException("Stream finished to soon"))
      sentMessages        <- internalMessages.get
    } yield assert(sentMessages)(hasSameElements(List(InternalMessage.UserRegistered(...)

I think, It may be worth considering treating ZHub as a regular trait instead of sealed

@adamgfraser
Copy link
Contributor

adamgfraser commented May 5, 2021

@PawelJ-PL ZHub was a sealed trait prior to that PR being merged so you wouldn't have been able to extend it even then. You can use contramapM to perform an effect like writing to a Ref for each value that is published to the hub. I am 👎 on removing the seal as I don't think the hub is meant to be extended by third party code and it creates binary compatibility issues.

@PawelJ-PL
Copy link
Author

Solution with contramapN will work as fine in tests as a custom implementation based on Ref.

@adamgfraser
Copy link
Contributor

adamgfraser commented May 6, 2021

@PawelJ-PL Awesome! Are we good to close this then? Thanks for trying out ZHub and for raising this.

@PawelJ-PL
Copy link
Author

Yes, I'll close issue. Thank you for suggestion.

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

No branches or pull requests

2 participants