Files
Vladislav Lisyanskiy 50aa8c51cc Fixed segmentation fault crash (#1198)
* Fixed glob segmentation fault

* Renamed AtomicDictionary to ThreadSafeDictionary

* Refactored ThreadSafeDictionary

* ThreadSafeDictionary replaced with ThreadSafeContainer

* Removed reader/writer

* ThreadSafeContainer replaced with Atomic
2022-03-31 16:15:58 +11:00

40 lines
932 B
Swift

//
// AtomicTests.swift
//
//
// Created by Vladislav Lisianskii on 27.03.2022.
//
import XCTest
@testable import XcodeGenCore
final class AtomicTests: XCTestCase {
@Atomic private var atomicDictionary = [String: Int]()
func testSimultaneousWriteOrder() {
let group = DispatchGroup()
for index in (0..<100) {
group.enter()
DispatchQueue.global().async {
self.$atomicDictionary.with { atomicDictionary in
atomicDictionary["\(index)"] = index
}
group.leave()
}
}
group.notify(queue: .main, execute: {
var expectedValue = [String: Int]()
for index in (0..<100) {
expectedValue["\(index)"] = index
}
XCTAssertEqual(
self.atomicDictionary,
expectedValue
)
})
}
}