File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed
Concurrency Utilities.xcodeproj
Concurrency UtilitiesTests Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 31317678E28F1F5D1B2500FE6D0B /* Concurrency_UtilitiesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Concurrency_UtilitiesTests.swift; sourceTree = "<group>"; };
32327678E2911F5D1B2500FE6D0B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
33337678E29B1F5D1DE500FE6D0B /* 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 */
55567678E2771F5D1B2500FE6D0B = {
5657isa = PBXGroup;
5758children = (
59+ 7678E29D1F5D2CD500FE6D0B /* README.md */,
58607678E2831F5D1B2500FE6D0B /* Concurrency Utilities */,
59617678E28E1F5D1B2500FE6D0B /* Concurrency UtilitiesTests */,
60627678E2821F5D1B2500FE6D0B /* Products */,
Original file line number Diff line number Diff line change @@ -10,28 +10,34 @@ import XCTest
1010@testable import Concurrency_Utilities
1111
1212class 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
You can’t perform that action at this time.
0 commit comments