by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Paul S.
    @pshirshov
    @umbreak : could you describe your usecase as precise as possible please?
    I mean what behaviour you wish to have?
    Didac
    @umbreak
    cool thanks. One other thing: allowReuse = false on DockerContainerModule will create a new Docker container for every single test block, right?
    I’ll detail it soon, I have to answer a call first. Thanks again
    Kai
    @neko-kai
    It will create a new container every time the resource is acquired - if it’s memoized, it will only be once per-run/per-memoization scope anyway
    Paul S.
    @pshirshov
    Nope, for every single test env
    Kai
    @neko-kai
    For every test if not memoized, for every test env if memoized
    reuse=true allows reusing the same container between multiple test runs on top of that
    Paul S.
    @pshirshov

    By the way, I had a quick look at your project and got surprised by the fact that you use LocatorRef: make[Cli[F]].tagged(Repo.Dummy).from { locatorRef: LocatorRef => new Cli[F](Some(locatorRef)) }

    I'm very curious why did you decide to use that feature?

    Paul S.
    @pshirshov
    That looks kinda strange. I need to dig deeper but I'm sure LocatorRef can be avoided for your usecase
    We implemented it as a last-resort feature, it is not expected to be needed under normal circumstances
    Didac
    @umbreak
    ok. probably you are right. We have just recently started using distage…maybe there are simlper ways
    Paul S.
    @pshirshov
    Also I noted that you use don't use distage to wire implicit arguments of your components. I would suggest to wire them with distage, it works well
    1 reply
    Kai
    @neko-kai
    This will (optionally) rebuild the entire application, right? distage has a mechanism ‘roles’ for the use-case of building parts of the application for sub-commands - https://izumi.7mind.io/latest/release/doc/distage/distage-framework.html#roles
    It’s possible they could be used to avoid the recursive design here, probably. e.g. you could pass parameters to influx cli subcommand like ./app :influx param1 —param2
    Didac
    @umbreak
    i’ll check into roles
    Didac
    @umbreak

    @neko-kai If I had something like you posted:

    trait AbstractTest extends DistageAbstractScalatestSpec[IO] {
      override def config = super.config.copy(
        memoizationRoots = super.config.memoizationRoots ++ Set(
          DIKey.get[Transactor[F]], DIKey.get[InfluxClient[F]]
        )
      ) 
    }

    And then I have 2 tests: PostgresSpec extends AbstractTest and InfluxSpec extends AbstractTest and I run testOnly *InfluxSpec I can see how the Postgres container is also started and the waitForPostgresReady is also running, even though I’m just running the InfluxSpec.

    Kai
    @neko-kai
    @umbreak Actually the problem here is that sbt testOnly doesn’t work correctly with distage-testkit – in reality all tests are run, not just the ones reported. Try running InfluxSpec class test from IntelliJ IDEA - it will work correctly. You can also run select test cases with testOnly — -z “<test-name-patter>”, but this will work for running specific test classes, not specific test suites
    Kai
    @neko-kai
    The problem here is that scalatest’s sbt runner does not pass information down to suites as to what suites it’s trying to launch – and distage-testkit relies on launching just once and does the rest of test discovery on its own. For intellij’s / scalatest’s own ScalaTestRunner, distage does not do discovery because they have a specific protocol - all test classes are constructed first and tests launch after everything is constructed – this allows distage-testkit to register during construction and once its’ run method is called, collect tests that are registered – this enables global sharing and all the features stemming from having a single entrypoint. Under sbt this doesn’t work because scalatest’s sbt runner launches tests one-by-one and does not pass any parameters to figure out the enabled suites, the only way to figure out which suites were selected would be to wait until there was a big enough pause between run calls, which would be pretty horrifying - so it instead it just launches everything
    Didac
    @umbreak
    Right, running the test though IntellIJ works
    Kai
    @neko-kai
    There’s currently an effort in zio to provide enough features to run distage-testkit on top of it, so we may at some point provide an implementation on top of ZIO Test’s runner that wouldn’t suffer the issue. Scalatest is nearly abandoned and extremely unresponsive to issues and PRs so we didn’t try to patch the issue upstream, also since we’re using Intellij for development fixing this wasn’t a very high priority yet
    Didac
    @umbreak
    We are also using Intellij. So it isn’t a problem for us to run the tests through the IDE. Thanks
    Paul S.
    @pshirshov
    We have some plans on implementing our own testkit (or integrating with zio test). Unfortunately scalatest is too limited to properly support our workflow with global planning. Though at the moment we have no ETA, it's not an easy task
    Bogdan Roman
    @bogdanromanx
    thanks @neko-kai and @pshirshov for the explanations on how to properly use the container support in distage; it’s really useful!
    to comment on the need for accessing on the locator directly:
    • we need to be able to configure the injection plan based on arguments that are passed to the CLI
    • unfortunately, due to the way that decline works, we’re only able to produce a configuration object only after evaluating all the subcommands and arguments / flags; a simple example would be the following: imagine some part of the code relies on having a Transactor[F] instance, but if you have something like —dbhost 127.0.0.1 as a possible argument, you can only assemble the configuration and bindings only after the evaluation of the command
    • this makes stuff a bit awkward since it would be a lot of code repetition for shared arguments if you’d like to benefit from the instance construction from distage; having access to the locator as a resource is quite cool, since you can decide what to execute and still benefit from the distage’s wiring
    on a separate note: what is your experience in using bifunctors over monofunctors in real applications; we’ve mostly used EitherT but it’s not really ergonomic
    Bogdan Roman
    @bogdanromanx
    we do prefer defering the decision on choosing an effect type, so most of our codebase is using tagless; since typeclasses for F[+_,+_] are not defined in something like cats-effect, it’s either monofunctor with cats typeclasses or zio without abstracting over the effect
    Adriani Furtado
    @Adriani277
    @bogdanromanx have looked into BIO as a means to use tagless with a bi-functor?
    You can covert your codebase to bi-functor tagless with BIO and use the interop whenever you need cats instances
    Paul S.
    @pshirshov

    on a separate note: what is your experience in using bifunctors over monofunctors in real applications; we’ve mostly used EitherT but it’s not really ergonomic

    It's awesome, use it, you won't regret

    Didac
    @umbreak
    Yes we are aware of BIO. However we haven’t used it yet. As @bogdanromanx said, we try to abstract on an effect type F[_] but in fact a lot of times we end up using F[Either[_, _]] on our signatures in order to catch errors not thrown on the F. And obviously is a pain to work with them directly. Probably using something like BIO would be better
    Bogdan Roman
    @bogdanromanx
    thanks for your thoughts!
    Adriani Furtado
    @Adriani277
    @umbreak I have recently gone through the change you guys are attempting. We where between BIO tagless, Cats EitherT or just committing to ZIO, we decided on BIO since we all really like tagless
    Kai
    @neko-kai

    @bogdanromanx
    I see what you mean by decline requiring executing the actions immediately inside the parser which makes it harder to decouple subcommands from wiring.
    Well, one thing you could do to combat that is to not return F[ExitCode] directly from the parser, but to parse into an ADT that describes the subcommand and the command-line arguments – that way you can do the wiring in one place where you pattern match on that ADT instead of in many places around the code.
    Another option would be to not spread the command-line parsers across multiple classes, but put them all into Cli[F] - this would again allow to centralize wiring and remove the LocatorRef parameter.

    I’ve looked at your project and implemented one way to get rid of recursion on LocatorRef that isn’t one of the suggestions above, but I think is minimally disruptive to the way it’s organized right now - I’ve opened a PR at BlueBrain/nexus#1176

    Also as the project is right now, I think Roles would actually cover its needs quite well, currently I found that the wiring is actually the same for all subcommands and the only difference is in command-line arguments, which roles cover too, you can check the examples here - https://github.com/7mind/distage-example/blob/develop/src/main/scala/leaderboard/LeaderboardRole.scala#L89
    Bogdan Roman
    @bogdanromanx
    @neko-kai many thanks for the pointers and the PR, it’s really useful! ;)
    Stan Sobolev
    @Jacke

    Hey guys, I new in BIO and I need assistance.

    I have

    def t[F[+_,+_]: BIOPrimitives: BIO : BIOApplicative, R[_] : Sync : MonadError[?[_], Throwable], B](t: R[B]): F[Throwable, Int] = ??? // How to get F[_,_] from R (which is cats effect IO instance)
    
    to be able to do something like this
    t(IO(1/0)) 
    // zio.IO[Throwable, Int]
    Kai
    @neko-kai
    @Jacke If R[_] is a different type that isn't F[Throwable, ?], you could do it like this:
    def t[F[+_, +_]: BIOAsync: BIOFork, R[_]: Effect, B](t: R[B]): F[Throwable, B] = {
      import Izumi.functional.bio.catz._
      Concurrent[F[Throwable, ?]].liftIO(Effect[R].toIO(t))
    }
    Stan Sobolev
    @Jacke
    yes, perfect
    thanks
    Kai
    @neko-kai
    :+1:
    Stan Sobolev
    @Jacke

    @Kai I getting:

    @ t(IO(1))
    cmd30.sc:1: type mismatch;
     found   : izumi.functional.bio.PredefinedHelper.Predefined.Of[izumi.functional.bio.BIOAsync3[zio.ZIO]]
        (which expands to)  izumi.functional.bio.BIOAsync3[zio.ZIO]{type IsPredefined = izumi.functional.bio.PredefinedHelper.Predefined}
     required: izumi.functional.bio.BIOAsync[[+E, +A]zio.ZIO[R,E,A]]
        (which expands to)  izumi.functional.bio.BIOAsync3[[-R, +E, +A]zio.ZIO[R,E,A]]
    val res30 = t(IO(1))

    Is there any workaround?

    Kai
    @neko-kai
    @Jacke Does it work if you specify the types explicitly? e.g. t[zio.IO, cats.effect.IO](cats.effect.IO(1))
    If you’re on 2.12 you might also be missing compiler options, you need these sbt settings for BIO to work on 2.12:
    scalacOptions += "-Ypartial-unification"
    scalacOptions += "-Xsource:2.13”
    Stan Sobolev
    @Jacke

    No, it's not

    @ t[zio.IO, cats.effect.IO](cats.effect.IO(1))
    cmd30.sc:1: wrong number of type parameters for method t: [F[+_, +_], R[_], B](t: R[B])(implicit evidence$1: izumi.functional.bio.BIOAsync[F], implicit evidence$2: izumi.functional.bio.BIOFork[F], implicit evidence$3: izumi.functional.bio.BIO[F], implicit evidence$4: cats.effect.Effect[R], implicit cs: cats.effect.ContextShift[R])F[Throwable,B]
    val res30 = t[zio.IO, cats.effect.IO](cats.effect.IO(1))
                 ^
    Compilation Failed

    I'm on 2.13.2 and it still very strange :]

    Kai
    @neko-kai
    t[zio.IO, cats.effect.IO, Int](cats.effect.IO(1))
    Stan Sobolev
    @Jacke

    Cool

    @ t[zio.IO, cats.effect.IO, Int](cats.effect.IO(1))
    res30: zio.package.IO[Throwable, Int] = zio.ZIO$EffectPartial@3c6e3104

    Oh, language things :)

    Kai
    @neko-kai
    @umbreak @bogdanromanx There’s just been a new release with pretty significant QoL improvements for both distage-testkit & distage-framework-docker - https://github.com/7mind/izumi/releases/tag/v0.10.9 - should make memoization behavior far better & more consistent within your project (and make it obvious through logs). Note: you can now turn off all logging incl. config loading in testkit by setting TestConfig#logLevel
    Bogdan Roman
    @bogdanromanx
    fantastic, thanks @neko-kai
    Stan Sobolev
    @Jacke

    Hey guys, I have another problem, I'm trying to use cats.IO resource in MainPlugin,
    but I getting this error

        Suppressed: izumi.distage.model.exceptions.IncompatibleEffectTypesException: Incompatible effect types: Can't execute effect in `λ %0 → cats.effect.IO[+0]` which is neither Identity, nor a subtype of the effect that Provisioner was launched in: `λ %1 → zio.ZIO[-Any,+Throwable,+1]`
    
    Clarification:
      - To execute `.fromEffect` and `.fromResource` bindings for effects other than `Identity` you need to use `Injector.produceF` method with F type corresponding to the type of effects/resources you inject
      - Subtype type constructors are allowed. e.g. when using ZIO you can execute actions with type IO[Nothing, ?] when running in IO[Throwable, ?]
    
            at izumi.distage.provisioning.PlanInterpreterDefaultRuntimeImpl.$anonfun$verifyEffectType$1(PlanInterpreterDefaultRuntimeImpl.scala:215)
            at izumi.distage.model.effect.DIEffect.$anonfun$traverse_$2(DIEffect.scala:44)
            at zio.internal.FiberContext.evaluateNow(FiberContext.scala:844)
            ... 19 more
    Caused by: zio.Cause$FiberTrace: Fiber failed.

    That's because

          make[Transactor[F[Throwable, ?]]].fromResource[TransactorResource[F[Throwable, ?]]]

    I can make this with zio.IO, but if I do

          //make[Transactor[R]].fromResource[TransactorResourceCats[R]]
    where R == cats.IO

    I got the error from above.
    Is it possible to get cats.IO Resource effect with IO{], rather then with F[,_]: TagKK : BIO?

    Kai
    @neko-kai

    @Jacke Yes, but you will need to move all other components to cats.effect.IO too. To change the effect type

    1. in app: change the RoleAppLauncher's effect in https://github.com/7mind/distage-example/blob/develop/src/main/scala/leaderboard/LeaderboardRole.scala#L121 - inherit from RoleAppLauncher.LauncherF[cats.effect.IO] instead of LauncherBIO[zio.IO]

    2. in tests change the testkit's effect in https://github.com/7mind/distage-example/blob/develop/src/test/scala/leaderboard/tests.scala#L14 - inherit from DistageSpecScalatest[cats.effect.IO] instead of DistageBIOEnvSpecScalatest[zio.IO]

    3. When using Injector directly, not via distage-framework or distage-testkit, the effect type is determined by the type parameter passed to Injector#produceF/#produceRunF/#produceGetF etc

    You will need to move all components to the new effect type, only one effect type can be used at a time.