mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-23 09:51:30 +01:00
remove persistentstores during DataStack deinitialization to prevent warnings in Unit tests during teardown
This commit is contained in:
@@ -62,6 +62,9 @@ class BaseTestCase: XCTestCase {
|
|||||||
|
|
||||||
XCTFail(error.coreStoreDumpString)
|
XCTFail(error.coreStoreDumpString)
|
||||||
}
|
}
|
||||||
|
self.addTeardownBlock {
|
||||||
|
stack.unsafeRemoveAllPersistentStoresAndWait()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
|
|||||||
@@ -505,7 +505,12 @@ class DynamicModelTests: BaseTestDataTestCase {
|
|||||||
XCTFail()
|
XCTFail()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.waitAndCheckExpectations()
|
}
|
||||||
|
|
||||||
|
self.waitForExpectations(timeout: 10, handler: { _ in })
|
||||||
|
|
||||||
|
self.addTeardownBlock {
|
||||||
|
dataStack.unsafeRemoveAllPersistentStoresAndWait()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,8 +132,8 @@ final class FetchTests: BaseTestDataTestCase {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
self.waitAndCheckExpectations()
|
||||||
}
|
}
|
||||||
self.waitAndCheckExpectations()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
@@ -267,8 +267,8 @@ final class FetchTests: BaseTestDataTestCase {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
self.waitAndCheckExpectations()
|
||||||
}
|
}
|
||||||
self.waitAndCheckExpectations()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ class ObjectPublisherTests: BaseTestDataTestCase {
|
|||||||
XCTFail()
|
XCTFail()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.waitAndCheckExpectations()
|
self.waitAndCheckExpectations()
|
||||||
|
|
||||||
withExtendedLifetime(objectPublisher, {})
|
withExtendedLifetime(objectPublisher, {})
|
||||||
|
|||||||
@@ -622,8 +622,8 @@ final class TransactionTests: BaseTestCase {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
self.waitAndCheckExpectations()
|
||||||
}
|
}
|
||||||
self.waitAndCheckExpectations()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
@@ -755,8 +755,8 @@ final class TransactionTests: BaseTestCase {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
self.waitAndCheckExpectations()
|
||||||
}
|
}
|
||||||
self.waitAndCheckExpectations()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
@@ -896,8 +896,8 @@ final class TransactionTests: BaseTestCase {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
self.waitAndCheckExpectations()
|
||||||
}
|
}
|
||||||
self.waitAndCheckExpectations()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
|
|||||||
@@ -370,6 +370,44 @@ public final class DataStack: Equatable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Prepares deinitializing the `DataStack` by removing all persistent stores. This is not necessary, but can help silence SQLite warnings when actively releasing and recreating `DataStack`s.
|
||||||
|
- parameter completion: the closure to execute after all persistent stores are removed
|
||||||
|
*/
|
||||||
|
public func unsafeRemoveAllPersistentStores(completion: @escaping () -> Void = {}) {
|
||||||
|
|
||||||
|
let coordinator = self.coordinator
|
||||||
|
coordinator.performAsynchronously {
|
||||||
|
|
||||||
|
withExtendedLifetime(coordinator) { coordinator in
|
||||||
|
|
||||||
|
coordinator.persistentStores.forEach {
|
||||||
|
|
||||||
|
_ = try? coordinator.remove($0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DispatchQueue.main.async(execute: completion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Prepares deinitializing the `DataStack` by removing all persistent stores. This is not necessary, but can help silence SQLite warnings when actively releasing and recreating `DataStack`s.
|
||||||
|
*/
|
||||||
|
public func unsafeRemoveAllPersistentStoresAndWait() {
|
||||||
|
|
||||||
|
let coordinator = self.coordinator
|
||||||
|
coordinator.performSynchronously {
|
||||||
|
|
||||||
|
withExtendedLifetime(coordinator) { coordinator in
|
||||||
|
|
||||||
|
coordinator.persistentStores.forEach {
|
||||||
|
|
||||||
|
_ = try? coordinator.remove($0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: 3rd Party Utilities
|
// MARK: 3rd Party Utilities
|
||||||
|
|
||||||
@@ -509,16 +547,6 @@ public final class DataStack: Equatable {
|
|||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
|
||||||
let coordinator = self.coordinator
|
self.unsafeRemoveAllPersistentStores()
|
||||||
coordinator.performAsynchronously {
|
|
||||||
|
|
||||||
withExtendedLifetime(coordinator) { coordinator in
|
|
||||||
|
|
||||||
coordinator.persistentStores.forEach {
|
|
||||||
|
|
||||||
_ = try? coordinator.remove($0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user