Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 27 23:55

    Baccata on revamp-framework

    Progressing through the tests (compare)

  • Nov 27 23:30
    scala-steward opened #140
  • Nov 27 19:16
    scala-steward opened #139
  • Nov 27 17:49

    Baccata on revamp-framework

    Replacing framework by new impl… (compare)

  • Nov 26 15:56

    Baccata on revamp-framework

    Re-wired global resources (compare)

  • Nov 26 14:59

    Baccata on revamp-framework

    Further abstraction * Adds an … (compare)

  • Nov 26 09:44
    Baccata synchronize #135
  • Nov 26 09:44

    Baccata on master

    Update sbt to 1.4.4 (compare)

  • Nov 26 09:44
    Baccata closed #136
  • Nov 26 09:43

    Baccata on master

    Update sbt-mdoc to 2.2.13 (compare)

  • Nov 26 09:43
    Baccata closed #138
  • Nov 25 17:34
    scala-steward opened #138
  • Nov 25 10:10

    Baccata on master

    Update fs2-core to 2.4.6 (compare)

  • Nov 25 10:10
    Baccata closed #137
  • Nov 24 21:31
    scala-steward opened #137
  • Nov 23 02:04
    scala-steward opened #136
  • Nov 21 23:26
    scala-steward opened #135
  • Nov 21 22:19

    Baccata on revamp-framework

    Make runner polymorphic * Runn… (compare)

  • Nov 21 18:30
    Baccata commented #126
  • Nov 21 17:23
    mr-git commented #126
Olivier Mélois
@Baccata
sorry it ain't easier :s We purposefully avoided to base any design decision on Scalatest to try and nudge our developers towards a more FP-abiding style of writing tests
Gavin Bisesi
@Daenyth
oh for sure - that's one of the reasons I want it. We have some custom mixins to make fp-ish tests easier to write, and I think adapting those bases would be my starting point. But I don't want to live in 'lava layer' refactors through the test suite if I can avoid it
bengraygh
@bengraygh

Hi, everyone.

I'm trying out weaver-test and am trying to make a database driver session accessible with GlobalResourcesInit. I'm a bit confused about how to do this. I have been able to run the example just fine (IO returning string), however, I want to share a Session[IO]. I've tried a bunch of things, and had the compiler complain about not receiving an implicit for ResourceTag, but I don't really understand what this means or how to fix it.

Can anyone point me in the right direction?

object SharedContainer extends GlobalResourcesInit {

  implicit val contextShift: ContextShift[IO] = IO.contextShift(ExecutionContext.global)

  implicit def unsafeLogger[F[_]: Sync]: SelfAwareStructuredLogger[F] = Slf4jLogger.getLogger[F]

  val neo4JContainer = GenericContainer( ... )
  val c = NeoConfig( ... )

  def session: Resource[IO, Session[IO]] = Neo.mkSession[IO](c)

  def sharedResources(store: GlobalResources.Write[IO]): Resource[IO, Unit] =
    for {
      s <- session
      _ <- store.putR(s) // obviously this doesn't work
    } yield ()

}
Olivier Mélois
@Baccata
@bengraygh hi, most straightforward way is for you to wrap Session[IO] in some monomorphic case class (ie a case class that doesn't have type parameters), and to store that :
case class SessionWrapper(session: Session[IO]) 

for {
  s <- session 
 _ <- session.putR(SessionWrapper(s)) 
}  yield ()
the reason is that indexing things by types in Scala (or any jvm language) is fairly tricky because of type erasure, which means that the information about the session being specific to IO is lost at runtime, therefore there would be issues if people started storing Session[IO] and Session[Task] for instance
bengraygh
@bengraygh
Thank you very much! This compiles, and I'm sure works. Thank you for the explanation too.
Olivier Mélois
@Baccata
anytime :)
bengraygh
@bengraygh

I have a similar problem on the other side where I need to access the shared resource:

class MySuite(globalResources: GlobalResources) extends IOSuite {

  type Res = LiveFooRepository[IO]

  def sharedResource: Resource[IO, LiveFooRepository[IO]] =
    globalResources.in[IO].getOrFailR[LiveFooRepository[IO]]()

}

Tried to wrap it but failed - not sure if that works here, or I'm not doing it right.

Changed the original to:

  case class RepoWrapper(r: LiveFooRepository[IO])

  def sharedResources(store: GlobalResources.Write[IO]): Resource[IO, Unit] = {
    for {
      s <- mkSession[IO](c)
      r <- store.putR(RepoWrapper(new LiveFooRepository[IO](s)))
    } yield ()
  }
bengraygh
@bengraygh
I tried this, but it doesn't work either:
  def sharedResource: Resource[IO, RepoWrapper] =
    globalResources.in[IO].getOrFailR[RepoWrapper]()
Anton Sviridov
@keynmol

this should work:

import weaver._
import cats.effect._

trait LiveFooRepository[F[_]]

case class RepoWrapper(r: LiveFooRepository[IO])

class MySuite(globalResources: GlobalResources) extends IOSuite {

  type Res = RepoWrapper

  def sharedResource: Resource[IO, RepoWrapper] =
    globalResources.in[IO].getOrFailR[RepoWrapper]()

}

Seems to compile - are you seeing runtime errors? https://scastie.scala-lang.org/quDjSzRdROmYkj8qojGKtg

and what sort of error did you see?
bengraygh
@bengraygh
This doesn't compile for me:
 found   : cats.effect.Resource[cats.effect.IO,MySuite.this.RepoWrapper]
 required: cats.effect.Resource[cats.effect.IO,MySuite.this.Res]
I'll make a scastie
Anton Sviridov
@keynmol
yeah, that'd be easier to work with :)
bengraygh
@bengraygh
Can you do scasties with multiple files?
maybe I don't need to for this
Anton Sviridov
@keynmol
don't think so and you shouldn't need it if it's just the compilation that we're testing
bengraygh
@bengraygh
true
bengraygh
@bengraygh

Ah, I'm an idiot. I didn't have type Res = RepoWrapper

Thank you very much @keynmol and @Baccata !

Anton Sviridov
@keynmol
Awesome :) hope you have fun with weaver :)
Olivier Mélois
@Baccata
@bengraygh btw, you can unwrap on the suite side :
type Res = LiveFooRepository[IO]

def sharedResource: Resource[IO, LiveFooRepository[IO] =
    globalResources.in[IO].getOrFailR[RepoWrapper]().map(_.r)
bengraygh
@bengraygh

Thanks, @Baccata . That's even better.

How long did you work on weaver-test before releasing it? It is really nice using this with cats effect, and it is quick.

Olivier Mélois
@Baccata
first prototype happened around 2 years ago. We've been using it internally on a few projects since, before deciding to release it
Olivier Mélois
@Baccata

Hi folks, we've published a 0.5.0-RC1 pre-release, with monix-integration and an intellij-plugin for people who like running things from the IDE

https://disneystreaming.github.io/weaver-test/docs/intellij

Olivier Mélois
@Baccata

Also I've got a blogpost out on testing asynchronous pipelines (kafka/kinesis)

https://medium.com/disney-streaming/testing-asynchronous-pipelines-with-fs2-and-weaver-test-f0ffd37676d

bengraygh
@bengraygh

Hi folks, we've published a 0.5.0-RC1 pre-release, with monix-integration and an intellij-plugin for people who like running things from the IDE

https://disneystreaming.github.io/weaver-test/docs/intellij

This is great, I'll try it out for the IntelliJ integration.

bengraygh
@bengraygh
I'm trying out the IntelliJ integration. I bumped the dependency to 0.5.0-RC1 and installed the plugin, but I'm not able to get this to work. I tried to add a test configuration in IntelliJ, found the 'weaver-test' option, and added it. Set the test kind to class and pointed it to my DAO test suite but I get an error: "No suite class is found for X in Y". There's an icon that appears next to each test, but when I click it the drop down has 'nothing', so I can't run the test through the ide. My IOSuite object does not have an icon next to it to run the tests within for some reason. Everything works from sbt still.
Olivier Mélois
@Baccata
Hi @bengraygh , thanks for the feedback.
  1. what's your intellij version ?
  2. Is your project opened as an SBT project or a BSP project ?
  3. can you share your suite (or a minimal representation of it) ?
bengraygh
@bengraygh
  1. 2020.2.1
  2. SBT project
  3. yes, I can share it
class LiveFooSuite(globalResources: GlobalResources) extends IOSuite with IOCheckers {

  implicit def unsafeLogger[F[_]: Sync]: SelfAwareStructuredLogger[F] =
    Slf4jLogger.getLogger[F]

  type Res = LiveFooRepository[IO]

  def sharedResource: Resource[IO, LiveFooRepository[IO]] =
    globalResources.in[IO].getOrFailR[RepoWrapper]().map(_.r)

  test("Adding an thing works") { fooRepo =>
    forall(Generators.fooAddParamsGen) { addParams =>
      for {
        _ <- fooRepo.add(
          fooProps = addParams.fooProps,
          a = addParams.a,
          b = addParams.b,
          c = Set.empty,
          d = Set.empty,
          e = Set.empty
        )
        result <- fooRepo.find(addParams.fooProps.uuid)
      } yield expect(result.uuid == addParams.fooProps.uuid)
    }
  }
}
Olivier Mélois
@Baccata
@bengraygh I've created an issue disneystreaming/weaver-test#80
Bruno Fernandes
@bfdes

Whats the best way to load this project in Intellij to contribute?
Having a lot of problems with import detection for modules outside core, so coding blind at times.
Bloop and metals in VSCode is a little imperfect, so I stopped using it.

(Probably a general question for multi-module projects TBH.)

Anton Sviridov
@keynmol
I think the main issue is that IntelliJ is not so hot on projects that build to multiple platforms
I can make a blind bet that you'll have a better experience with metals now (depends on when you stopped using it)
Olivier Mélois
@Baccata
that's a question for the intellij channel, I'm afraid
Gavin Bisesi
@Daenyth

:wave: I'm looking at parallelism stuff in the docs, and I see https://disneystreaming.github.io/weaver-test/docs/common_usage#controlling-parallelism

The wording there implies to me that the setting described controls the parallelism used by test cases within one spec class.

I'd like to know how weaver controls cross-suite parallelism - between classes, etc. How is that controlled?

Olivier Mélois
@Baccata
@Daenyth hi. We've made the decision to not do anything specific in that regard, in an effort to respect whatever the user's define in their build definition
if you're using SBT, in theory you would just have to follow this page to define whether suites should run sequentially or in parallel
Gavin Bisesi
@Daenyth
How does that work with the cross-suite resources? There's some kind of global state at play there..
but that's not awful...
Olivier Mélois
@Baccata
there is indeed. We're kind of abusing the test-interface semantics to allow for it (we're openly disclosing it in the documentation)
Gavin Bisesi
@Daenyth
yes
I guess I was just thrown by how scalatest does cross-suite parallel control (it runs 2*corecount in parallel and you can't really control it)
Olivier Mélois
@Baccata
the test-interface expects you to return a list of "tasks" that the build-tool should decide how to run. We're just taking advantage of the fact the tasks are still gonna run on the same jvm (in the case of sbt, bloop and mill anyway), using a semaphore to detect when the build tool is finished with the tasks.
Gavin Bisesi
@Daenyth
gotcha
Olivier Mélois
@Baccata
it's hacky, but we're very much limited by the test-interface itself (which hasn't budged for the last 7 years or so)
Olivier Mélois
@Baccata

:wave: Hi folks, I've just released v0.5.0 of weaver

https://github.com/disneystreaming/weaver-test/releases/tag/v0.5.0

bengraygh
@bengraygh
I just picked up a concurrency problem in my project because of weaver-test running everything in parallel. Quite enjoying the framework, so thanks again!
Anton Sviridov
@keynmol
:tada: nice
Olivier Mélois
@Baccata
@bengraygh our pleasure ;)