@@ -62,17 +62,29 @@ object TestExecutor {
62
62
loop(label :: labels, spec, exec, ancestors, sectionId)
63
63
64
64
case Spec .ScopedCase (managed) =>
65
- ZIO
66
- .scoped(
67
- managed
68
- .flatMap(loop(labels, _, exec, ancestors, sectionId))
69
- )
70
- .catchAllCause { e =>
71
- val event =
72
- ExecutionEvent .RuntimeFailure (sectionId, labels, TestFailure .Runtime (e), ancestors)
65
+ Scope .make.flatMap { scope =>
66
+ scope
67
+ .extend(managed.flatMap(loop(labels, _, exec, ancestors, sectionId)))
68
+ .onExit { exit =>
69
+ val warning =
70
+ " Warning: ZIO Test is attempting to close the scope of suite " +
71
+ s " ${labels.reverse.mkString(" - " )} in $fullyQualifiedName, " +
72
+ " but closing the scope has taken more than 60 seconds to " +
73
+ " complete. This may indicate a resource leak."
74
+ for {
75
+ warning <-
76
+ ZIO .logWarning(warning).delay(60 .seconds).withClock(ClockLive ).interruptible.forkDaemon
77
+ finalizer <- scope.close(exit).ensuring(warning.interrupt).forkDaemon
78
+ exit <- warning.await
79
+ _ <- finalizer.join.when(exit.isInterrupted)
80
+ } yield ()
81
+ }
82
+ }.catchAllCause { e =>
83
+ val event =
84
+ ExecutionEvent .RuntimeFailure (sectionId, labels, TestFailure .Runtime (e), ancestors)
73
85
74
- processEvent(event)
75
- }
86
+ processEvent(event)
87
+ }
76
88
77
89
case Spec .MultipleCase (specs) =>
78
90
ZIO .uninterruptibleMask(restore =>
0 commit comments