From f23e16a57517ddf766b667f2ace54e538ca88c04 Mon Sep 17 00:00:00 2001 From: Christopher Fuller Date: Sun, 23 Feb 2025 15:40:09 -0800 Subject: [PATCH 1/3] Refactor deinit assertions --- Sources/Nodes/Core/AbstractContext.swift | 8 +++++--- Sources/Nodes/Core/AbstractFlow.swift | 8 +++++--- Sources/Nodes/Core/AbstractWorker.swift | 8 +++++--- Sources/Nodes/Internal/WorkerController.swift | 8 +++++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Sources/Nodes/Core/AbstractContext.swift b/Sources/Nodes/Core/AbstractContext.swift index 0931cf135..a98c25832 100644 --- a/Sources/Nodes/Core/AbstractContext.swift +++ b/Sources/Nodes/Core/AbstractContext.swift @@ -139,13 +139,15 @@ open class _BaseContext: Context { // swiftlint:disable:this type_name try workerController.withWorkers(ofType: type, perform: perform) } + #if DEBUG + deinit { - #if DEBUG if isActive { - assertionFailure("Lifecycle Violation: Expected `AbstractContext` to deactivate before it is deallocated.") + assertionFailure("Lifecycle Violation: Expected `AbstractContext` to deactivate before it is deallocated") } - #endif } + + #endif } /** diff --git a/Sources/Nodes/Core/AbstractFlow.swift b/Sources/Nodes/Core/AbstractFlow.swift index 96571ce89..99fdc12c1 100644 --- a/Sources/Nodes/Core/AbstractFlow.swift +++ b/Sources/Nodes/Core/AbstractFlow.swift @@ -279,13 +279,15 @@ open class AbstractFlow: Flow { try flowController.withFlows(ofType: type, perform: perform) } + #if DEBUG + deinit { - #if DEBUG if _isStarted { - assertionFailure("Lifecycle Violation: Expected `AbstractFlow` to end before it is deallocated.") + assertionFailure("Lifecycle Violation: Expected `AbstractFlow` to end before it is deallocated") } - #endif } + + #endif } // swiftlint:enable period_spacing diff --git a/Sources/Nodes/Core/AbstractWorker.swift b/Sources/Nodes/Core/AbstractWorker.swift index e244c7418..63cfab76d 100644 --- a/Sources/Nodes/Core/AbstractWorker.swift +++ b/Sources/Nodes/Core/AbstractWorker.swift @@ -70,13 +70,15 @@ open class _BaseWorker: Worker { // swiftlint:disable:this type_name isWorking = false } + #if DEBUG + deinit { - #if DEBUG if isWorking { - assertionFailure("Lifecycle Violation: Expected `AbstractWorker` to stop before it is deallocated.") + assertionFailure("Lifecycle Violation: Expected `AbstractWorker` to stop before it is deallocated") } - #endif } + + #endif } /** diff --git a/Sources/Nodes/Internal/WorkerController.swift b/Sources/Nodes/Internal/WorkerController.swift index 117fb97c0..9c470f2b6 100644 --- a/Sources/Nodes/Internal/WorkerController.swift +++ b/Sources/Nodes/Internal/WorkerController.swift @@ -93,16 +93,18 @@ public final class WorkerController { try workers(ofType: type).forEach(perform) } + #if DEBUG + deinit { - #if DEBUG for worker: Worker in workers { if worker.isWorking { assertionFailure(""" - Lifecycle Violation: Expected `Worker` to stop before `WorkerController` is deallocated. + Lifecycle Violation: Expected `Worker` to stop before `WorkerController` is deallocated """) } LeakDetector.detect(worker) } - #endif } + + #endif } From 7e2ce5ea2d96ee207f1f7437f90ef4dce25a6fdb Mon Sep 17 00:00:00 2001 From: Christopher Fuller Date: Sun, 23 Feb 2025 16:03:06 -0800 Subject: [PATCH 2/3] Revise message --- Sources/Nodes/Internal/WorkerController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Nodes/Internal/WorkerController.swift b/Sources/Nodes/Internal/WorkerController.swift index 9c470f2b6..69e35356c 100644 --- a/Sources/Nodes/Internal/WorkerController.swift +++ b/Sources/Nodes/Internal/WorkerController.swift @@ -99,7 +99,7 @@ public final class WorkerController { for worker: Worker in workers { if worker.isWorking { assertionFailure(""" - Lifecycle Violation: Expected `Worker` to stop before `WorkerController` is deallocated + Lifecycle Violation: Expected `Worker` instance to stop before `WorkerController` is deallocated """) } LeakDetector.detect(worker) From 9145cc2838250e0ee151c96bdb4af7d6c17f872a Mon Sep 17 00:00:00 2001 From: Christopher Fuller Date: Sun, 23 Feb 2025 16:10:38 -0800 Subject: [PATCH 3/3] Revise messages --- Sources/Nodes/Core/AbstractContext.swift | 2 +- Sources/Nodes/Core/AbstractFlow.swift | 2 +- Sources/Nodes/Core/AbstractWorker.swift | 2 +- Sources/Nodes/Internal/WorkerController.swift | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Nodes/Core/AbstractContext.swift b/Sources/Nodes/Core/AbstractContext.swift index a98c25832..7e59861a0 100644 --- a/Sources/Nodes/Core/AbstractContext.swift +++ b/Sources/Nodes/Core/AbstractContext.swift @@ -143,7 +143,7 @@ open class _BaseContext: Context { // swiftlint:disable:this type_name deinit { if isActive { - assertionFailure("Lifecycle Violation: Expected `AbstractContext` to deactivate before it is deallocated") + assertionFailure("Lifecycle Violation: Expect `AbstractContext` to deactivate before it is deallocated.") } } diff --git a/Sources/Nodes/Core/AbstractFlow.swift b/Sources/Nodes/Core/AbstractFlow.swift index 99fdc12c1..5468ed43f 100644 --- a/Sources/Nodes/Core/AbstractFlow.swift +++ b/Sources/Nodes/Core/AbstractFlow.swift @@ -283,7 +283,7 @@ open class AbstractFlow: Flow { deinit { if _isStarted { - assertionFailure("Lifecycle Violation: Expected `AbstractFlow` to end before it is deallocated") + assertionFailure("Lifecycle Violation: Expect `AbstractFlow` to end before it is deallocated.") } } diff --git a/Sources/Nodes/Core/AbstractWorker.swift b/Sources/Nodes/Core/AbstractWorker.swift index 63cfab76d..3e76a508b 100644 --- a/Sources/Nodes/Core/AbstractWorker.swift +++ b/Sources/Nodes/Core/AbstractWorker.swift @@ -74,7 +74,7 @@ open class _BaseWorker: Worker { // swiftlint:disable:this type_name deinit { if isWorking { - assertionFailure("Lifecycle Violation: Expected `AbstractWorker` to stop before it is deallocated") + assertionFailure("Lifecycle Violation: Expect `AbstractWorker` to stop before it is deallocated.") } } diff --git a/Sources/Nodes/Internal/WorkerController.swift b/Sources/Nodes/Internal/WorkerController.swift index 69e35356c..ec2f1841c 100644 --- a/Sources/Nodes/Internal/WorkerController.swift +++ b/Sources/Nodes/Internal/WorkerController.swift @@ -99,7 +99,7 @@ public final class WorkerController { for worker: Worker in workers { if worker.isWorking { assertionFailure(""" - Lifecycle Violation: Expected `Worker` instance to stop before `WorkerController` is deallocated + Lifecycle Violation: Expect `Worker` instance to stop before `WorkerController` is deallocated. """) } LeakDetector.detect(worker)