Skip to content

Commit 155a8c7

Browse files
committed
Correction to Atomic tests
1 parent 77d0b0e commit 155a8c7

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

Concurrency Utilities.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
7678E28F1F5D1B2500FE6D0B /* Concurrency_UtilitiesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Concurrency_UtilitiesTests.swift; sourceTree = "<group>"; };
3232
7678E2911F5D1B2500FE6D0B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3333
7678E29B1F5D1DE500FE6D0B /* Atomic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Atomic.swift; sourceTree = "<group>"; };
34+
7678E29D1F5D2CD500FE6D0B /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
3435
/* End PBXFileReference section */
3536

3637
/* Begin PBXFrameworksBuildPhase section */
@@ -55,6 +56,7 @@
5556
7678E2771F5D1B2500FE6D0B = {
5657
isa = PBXGroup;
5758
children = (
59+
7678E29D1F5D2CD500FE6D0B /* README.md */,
5860
7678E2831F5D1B2500FE6D0B /* Concurrency Utilities */,
5961
7678E28E1F5D1B2500FE6D0B /* Concurrency UtilitiesTests */,
6062
7678E2821F5D1B2500FE6D0B /* Products */,

Concurrency UtilitiesTests/Concurrency_UtilitiesTests.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,34 @@ import XCTest
1010
@testable import Concurrency_Utilities
1111

1212
class Concurrency_UtilitiesTests: XCTestCase {
13-
func testGetSetUpdate() {
14-
var test = Atomic((0, 0))
15-
var error = Atomic(false)
16-
for i in 0 ..< 10 {
13+
func testAtomicGetSetUpdate() {
14+
let test = Atomic((0, 0)) // Test that two parts of tuple always have same value.
15+
let error = Atomic(false)
16+
let group = DispatchGroup()
17+
for i in 1 ... 10 {
18+
group.enter()
1719
DispatchQueue.global().async {
20+
defer { group.leave() }
1821
test.value = (i, i)
1922
}
23+
group.enter()
2024
DispatchQueue.global().async {
2125
test.update {
22-
($0.0 + 1, $0.1 + 1)
26+
defer { group.leave() }
27+
return ($0.0 + 1, $0.1 + 1)
2328
}
2429
}
30+
group.enter()
2531
DispatchQueue.global().async {
2632
error.update {
27-
guard !$0 else {
28-
return true
29-
}
33+
defer { group.leave() }
34+
guard !$0 else { return true } // Don't over-write an existing error.
3035
let t = test.value
31-
return t.0 != t.1
36+
return t.0 != t.1 // Test two parts of tuple have same value.
3237
}
3338
}
3439
}
40+
group.wait()
3541
XCTAssertFalse(error.value)
3642
}
3743

0 commit comments

Comments
 (0)