Skip to content

Commit bbac0fd

Browse files
committed
make MockHashAlgorithm thread safe
1 parent c5b3735 commit bbac0fd

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Sources/SPMTestSupport/MockHashAlgorithm.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66

77
See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9-
*/
9+
*/
1010

11+
import Basics
1112
import TSCBasic
1213

1314
public class MockHashAlgorithm: HashAlgorithm {
1415
public typealias Hash = (ByteString) -> ByteString
1516

16-
public private(set) var hashes: [ByteString] = []
17+
public private(set) var hashes = ThreadSafeArrayStore<ByteString>()
1718
private var hashFunction: Hash!
1819

1920
public init(hash: Hash? = nil) {
20-
hashFunction = hash ?? { hash in
21+
self.hashFunction = hash ?? { hash in
2122
self.hashes.append(hash)
2223
return ByteString(hash.contents.reversed())
2324
}
2425
}
2526

2627
public func hash(_ bytes: ByteString) -> ByteString {
27-
return hashFunction(bytes)
28+
return self.hashFunction(bytes)
2829
}
2930
}

0 commit comments

Comments
 (0)