-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interrupt effect when test finishes (#3416)
- Loading branch information
Showing
3 changed files
with
82 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
"@effect/vitest": patch | ||
--- | ||
|
||
Interrupt an effect when a test finishes. This ensures allocated resources | ||
will be correctly released even if the test times out. | ||
|
||
```ts | ||
import { it } from "@effect/vitest" | ||
import { Console, Effect, Layer } from "effect" | ||
|
||
class Database extends Effect.Tag("Database")<Database, {}>() { | ||
static readonly test = Layer.scoped( | ||
Database, | ||
Effect.acquireRelease( | ||
Effect.as(Console.log("database setup"), Database.of({})), | ||
() => Console.log("database teardown") | ||
) | ||
) | ||
} | ||
|
||
it.live( | ||
"testing with closable resources", | ||
() => | ||
Effect.gen(function* () { | ||
const database = yield* Database | ||
// performing some time consuming operations | ||
yield* Effect.sleep("500 millis") | ||
}).pipe(Effect.provide(Database.test)), | ||
{ timeout: 100 } | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters