More unit tests and reenable XCBeautify

pull/941/head
Morgan Pretty 1 year ago
parent f5f112a593
commit 4dd1199da1

@ -92,7 +92,7 @@ local update_cocoapods_cache = {
name: 'Run Unit Tests',
commands: [
'mkdir build',
'NSUnbufferedIO=YES set -o pipefail && xcodebuild test -workspace Session.xcworkspace -scheme Session -derivedDataPath ./build/derivedData -parallelizeTargets -destination "platform=iOS Simulator,name=iPhone 14" -parallel-testing-enabled YES -parallel-testing-worker-count 2 -test-timeouts-enabled YES -maximum-test-execution-time-allowance 10 -collect-test-diagnostics never 2>&1'
'NSUnbufferedIO=YES set -o pipefail && xcodebuild test -workspace Session.xcworkspace -scheme Session -derivedDataPath ./build/derivedData -parallelizeTargets -destination "platform=iOS Simulator,name=iPhone 14" -parallel-testing-enabled YES -parallel-testing-worker-count 2 -test-timeouts-enabled YES -maximum-test-execution-time-allowance 10 -collect-test-diagnostics never 2>&1 | ./Pods/xcbeautify/xcbeautify --is-ci'
],
},
{

@ -103,14 +103,23 @@ class SynchronousStorage: Storage {
using dependencies: Dependencies = Dependencies(),
value: @escaping (Database) throws -> T
) -> AnyPublisher<T, Error> {
guard let result: T = self.read(fileName: fileName, functionName: functionName, lineNumber: lineNumber, using: dependencies, value) else {
guard isValid, let dbWriter: DatabaseWriter = testDbWriter else {
return Fail(error: StorageError.generic)
.eraseToAnyPublisher()
}
return Just(result)
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
// If 'forceSynchronous' is true then it's likely that we will access the database in
// a reentrant way, the 'unsafeReentrant...' functions allow us to interact with the
// database without worrying about reentrant access during tests because we can be
// confident that the tests are running on the correct thread
guard !dependencies.forceSynchronous else {
return Just(())
.setFailureType(to: Error.self)
.tryMap { _ in try dbWriter.unsafeReentrantRead(value) }
.eraseToAnyPublisher()
}
return super.readPublisher(fileName: fileName, functionName: functionName, lineNumber: lineNumber, using: dependencies, value: value)
}
override func writeAsync<T>(
@ -137,13 +146,22 @@ class SynchronousStorage: Storage {
using dependencies: Dependencies = Dependencies(),
updates: @escaping (Database) throws -> T
) -> AnyPublisher<T, Error> {
guard let result: T = super.write(fileName: fileName, functionName: functionName, lineNumber: lineNumber, using: dependencies, updates: updates) else {
guard isValid, let dbWriter: DatabaseWriter = testDbWriter else {
return Fail(error: StorageError.generic)
.eraseToAnyPublisher()
}
return Just(result)
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
// If 'forceSynchronous' is true then it's likely that we will access the database in
// a reentrant way, the 'unsafeReentrant...' functions allow us to interact with the
// database without worrying about reentrant access during tests because we can be
// confident that the tests are running on the correct thread
guard !dependencies.forceSynchronous else {
return Just(())
.setFailureType(to: Error.self)
.tryMap { _ in try dbWriter.unsafeReentrantWrite(updates) }
.eraseToAnyPublisher()
}
return super.writePublisher(fileName: fileName, functionName: functionName, lineNumber: lineNumber, using: dependencies, updates: updates)
}
}

Loading…
Cancel
Save