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
CE3 Laws upgrade #3807
CE3 Laws upgrade #3807
Conversation
On EntityCodecTests, it seems to be only used at |
I don't think there are many external consumers of these laws, and I'm not terribly concerned about breaking changes (i.e., taking an explicit dispatcher) if it otherwise seems the right thing to do. Theoretically, it's nice to be able to test in an abstract I'd say whichever of those gets it compiling and gets us unblocked is great for now. Along with testing, a bunch of other things will open up after this, and we can refactor later. |
Thanks for both of your input. I've started implementing it as Fabio suggested, shouldn't take too long from here. |
I ended up fixing both issues by adding I'm not sure that's a real problem or not though. Should I try to eliminate one in favour of the other, or should I leave it as is? |
I think it makes sense to have a reference to both if you're running in the ticked executor. You need |
Atm the dispatcher is provided by the caller, so technically one could supply a dispatcher that isn't backed by TestContext. This only affects cogen instances though, so I'm not sure if that's an actual problem or not. |
Got it. I'm not completely sure how this stuff interacts with |
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 we're all set here, then?
@@ -9,12 +9,11 @@ package laws | |||
package discipline | |||
|
|||
import cats.Eq | |||
import cats.implicits._ | |||
// import cats.implicits._ |
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 delete the comment
I think it should be all good. Similarly as Raas I'm not certain about how |
As per the title. I spent a good chunk of time reading docs and sources and wasn't getting anywhere, so I though I'll take Fabio's advice and open a draft PR for guidance.
My troubles come from 2 places:
EntityCodecTests
ArbitraryInstances
I'll start with
EntityCodecTests
. To refresh your memory it currently looks like thisBecause I changed
Effect
forConcurrent
inEntityCodecLaws
nowentityCodecRoundTrip
is aIsEq[F[Either[Decodefailure, A]]
. And that is failing to be converted to a prop, and I wasn't sure what a good way forward would be.Admittedly I'm not very well practiced with
IsEq
. But my understanding is that forIsEq[A]
to be converted to a prop it needs anEq[A]
and aA => Pretty
. I could of course add those as implicits, but that doesn't seem like the right solution as it would shift a significant burden to the caller of this method that was previously handled internally. However, I'm not sure how to keep it inside this method either. In cats-effect tests theEq[IO[A]]
instance is defined by running theIO
. As such, one option would be to add a dispatcher implicit parameter and similarly define theEq[F[A]]
instance in terms of running theF
using the dispatcher. However, Daniel previously mentioned that passing a dispatcher around using implicits does not seem like a good idea. One could add an explicit parameter list withDispatcher
to remedy that, but that feels like it could have downstream implications that would result in requiring a not insignificant rewrite to accommodate the newDispatcher
requirement.Writing this all down the last option seems like it could be the most viable, but at this point my confidence of delivering a quality replacement here is pretty low, so I'd appreciate some advice.
Anyway, on to number 2:
ArbitraryInstances
. The problem here stems fromCogen[EntityBody[F]]
. Previously it requiredF[_]
to beEffect
and then defined the cogen in terms ofCogen[IO[A]]
imported from cats' ownarbitraries
. There is no moreCogen[IO[A]]
(and of course no moreEffect
) and as such this poses a problem.The problem here is very similar to
EntityCodecTests
. Now that cats-effect-laws (or the newtestkit
) do not provide theCogen[IO[A]]
, one has to introduce aCogen[F[A]]
. This can similarly be remedied with the help ofDispatcher
, however the question of where to source the dispatcher pops up once more. Here I thought about 4 potential solutions.First option is similar to that of
EntityCodecTests
: add an implicitDispatcher
, but as I mentioned - I have some reservations as per Daniel's advice.Second option is to define an abstract
Dispatcher
val on the whole trait and use that to define the cogens in terms of running unsafely. This has the huge downside of one not being able to just importarbitraries
- one would have to mixArbitraryInstances
in to provide the dispatcher or create per-test instances of some concrete implementation ofArbitraryInstances
which seems like it'd introduce significant boilerplate.Option no3 is the same as 2 except I'd extract cogens into their own trait.
Option no4 is basically 2 and 3 except the abstract val is a
Resource[Dispatcher[F]]
and is acquired in the cogen every time.Here I'm leaning towards the implicit since it is the least intrusive, but I am wary that it is the wrong choice.
Nonetheless, I implore you for guidance. This has been rattling around in my brain not going anywhere for a number of days now and I'm anxious about moving this forward. If it'd be too much time guiding me through getting this remedied I am perfectly fine handing this off to someone else too.
Thanks for sticking through to the end of this very long read😅