Skip to content

Teardown not invoked on Ctrl-C / SIGINT #1037

@mwisnicki

Description

@mwisnicki

Originally reported as typelevel/munit-cats-effect#467

Looks like FunFixture.async teardown is not invoked when tests are interrupted with Ctrl-C or SIGINT

build.sbt

scalaVersion := "3.8.1"
libraryDependencies ++= Seq(
  "org.scalameta" %% "munit" % "1.2.1" % Test,
)
Test / fork := true // needed for Ctrl-C to gracefully terminate tests

src/test/scala/FunFixtureAsyncTest.scala

import munit.FunSuite
import scala.concurrent.Future

class FunFixtureAsyncTest extends FunSuite {

  val fixture = FunFixture.async[Unit](
    setup = { testOptions =>
      println("setup")
      Future.successful(())
    },
    teardown = { _ =>
      println("teardown")
      Future.successful(())
    }
  )

  fixture.test("async fixture test") { _ =>
    println("running test")
    Thread.sleep(5000)
    Future.successful {
      assert(true)
    }
  }
}

sbt "testOnly FunFixtureAsyncTest" and press Ctrl-C when sleeping

Result:

setup
running test
^C
[warn] Canceling execution...
Cancelled: testOnly FunFixtureAsyncTest
[error] Cancelled: testOnly FunFixtureAsyncTest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions