Skip to content

Commit e6b9815

Browse files
authored
Fix for release build failure (#176)
* Fix for release build failure * Fix flaky tests
1 parent e3175b9 commit e6b9815

File tree

5 files changed

+34
-52
lines changed

5 files changed

+34
-52
lines changed

Sources/Atoms/Core/StoreContext.swift

+23-25
Original file line numberDiff line numberDiff line change
@@ -306,33 +306,29 @@ private extension StoreContext {
306306
updatedScopes[currentScope.key] = currentScope
307307
}
308308

309-
// Performs update of the given atom with the dependency's context.
310-
func performUpdate(for key: AtomKey, cache: some AtomCacheProtocol, dependency: some Atom) {
311-
dependency.producer.performUpdate {
312-
// Dependents must be updated with the scope at which they were initialised.
313-
let localContext = StoreContext(
314-
store: store,
315-
rootScope: rootScope,
316-
currentScope: cache.initializedScope
317-
)
318-
319-
let didUpdate = localContext.transitiveUpdate(for: key, cache: cache)
320-
321-
guard didUpdate else {
322-
// Record the atom to avoid downstream from being update.
323-
skippedDependencies.insert(key)
324-
return
325-
}
309+
func transitiveUpdate(for key: AtomKey, cache: some AtomCacheProtocol) {
310+
// Dependents must be updated with the scope at which they were initialised.
311+
let localContext = StoreContext(
312+
store: store,
313+
rootScope: rootScope,
314+
currentScope: cache.initializedScope
315+
)
326316

327-
if let scope = cache.initializedScope {
328-
updatedScopes[scope.key] = scope
329-
}
317+
let didUpdate = localContext.transitiveUpdate(for: key, cache: cache)
318+
319+
guard didUpdate else {
320+
// Record the atom to avoid downstream from being update.
321+
skippedDependencies.insert(key)
322+
return
323+
}
324+
325+
if let scope = cache.initializedScope {
326+
updatedScopes[scope.key] = scope
330327
}
331328
}
332329

333-
// Performs update of the given subscription with the dependency's context.
334-
func performUpdate(subscription: Subscription, dependency: some Atom) {
335-
dependency.producer.performUpdate(subscription.update)
330+
func performUpdate(dependency: some Atom, body: @MainActor () -> Void) {
331+
dependency.producer.performUpdate(body)
336332
}
337333

338334
func validEdge(_ edge: Edge) -> Edge? {
@@ -365,7 +361,9 @@ private extension StoreContext {
365361
let dependencyCache = store.state.caches[edge.from]
366362

367363
if let cache, let dependencyCache {
368-
performUpdate(for: key, cache: cache, dependency: dependencyCache.atom)
364+
performUpdate(dependency: dependencyCache.atom) {
365+
transitiveUpdate(for: key, cache: cache)
366+
}
369367
}
370368

371369
case .subscriber(let key):
@@ -377,7 +375,7 @@ private extension StoreContext {
377375
let dependencyCache = store.state.caches[edge.from]
378376

379377
if let subscription, let dependencyCache {
380-
performUpdate(subscription: subscription, dependency: dependencyCache.atom)
378+
performUpdate(dependency: dependencyCache.atom, body: subscription.update)
381379
}
382380
}
383381
}

Tests/AtomsTests/Atom/AsyncPhaseAtomTests.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ final class AsyncPhaseAtomTests: XCTestCase {
7070
await context.refresh(atom)
7171
}
7272

73-
Task {
74-
refreshTask.cancel()
75-
}
73+
refreshTask.cancel()
7674

7775
let phase = await refreshTask.value
7876
XCTAssertTrue(phase.isSuspending)

Tests/AtomsTests/Atom/TaskAtomTests.swift

+4-11
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,13 @@ final class TaskAtomTests: XCTestCase {
6666

6767
do {
6868
// Cancellation
69-
let refreshTask0 = Task {
69+
let refreshTask = Task {
7070
await context.refresh(atom)
7171
}
7272

73-
Task {
74-
refreshTask0.cancel()
75-
}
76-
77-
let task = await refreshTask0.value
73+
refreshTask.cancel()
7874

75+
let task = await refreshTask.value
7976
XCTAssertTrue(task.isCancelled)
8077
}
8178

@@ -89,19 +86,15 @@ final class TaskAtomTests: XCTestCase {
8986

9087
do {
9188
// Override cancellation
92-
9389
context.override(atom) { _ in Task { 400 } }
9490

9591
let refreshTask = Task {
9692
await context.refresh(atom)
9793
}
9894

99-
Task {
100-
refreshTask.cancel()
101-
}
95+
refreshTask.cancel()
10296

10397
let task = await refreshTask.value
104-
10598
XCTAssertTrue(task.isCancelled)
10699
}
107100
}

Tests/AtomsTests/Atom/ThrowingTaskAtomTests.swift

+5-12
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,9 @@ final class ThrowingTaskAtomTests: XCTestCase {
8585
await context.refresh(atom)
8686
}
8787

88-
Task {
89-
refreshTask.cancel()
90-
}
88+
refreshTask.cancel()
9189

9290
let task = await refreshTask.value
93-
9491
XCTAssertTrue(task.isCancelled)
9592
}
9693

@@ -104,20 +101,16 @@ final class ThrowingTaskAtomTests: XCTestCase {
104101

105102
do {
106103
// Override cancellation
107-
108104
context.override(atom) { _ in Task { 400 } }
109105

110-
let refreshTask1 = Task {
106+
let refreshTask = Task {
111107
await context.refresh(atom)
112108
}
113109

114-
Task {
115-
refreshTask1.cancel()
116-
}
117-
118-
let task1 = await refreshTask1.value
110+
refreshTask.cancel()
119111

120-
XCTAssertTrue(task1.isCancelled)
112+
let task = await refreshTask.value
113+
XCTAssertTrue(task.isCancelled)
121114
}
122115
}
123116

scripts/test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ while [[ $# -gt 0 ]]; do
4444
esac
4545
done
4646

47-
eval xcodebuild clean test "${options[@]-}" "${args[@]-}"
47+
eval xcodebuild clean test -configuration Release ENABLE_TESTABILITY=YES "${options[@]-}" "${args[@]-}"

0 commit comments

Comments
 (0)