Skip to content

Commit b124e68

Browse files
committed
Fix the test by looking until we've marked as seen all the indexes we're supposed to see, not until we see one that isn't supposed to be seen (because it may arrive out of order vs others we want to mark as seen.)
1 parent 6f78602 commit b124e68

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

TestFoundation/TestNSArray.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,26 @@ class TestNSArray : XCTestCase {
218218
var indexesForStaggeredEnumeration = indexesForHalfEnumeration
219219
indexesForStaggeredEnumeration.formIntersection(evenIndexes)
220220

221+
let finalCount = indexesForStaggeredEnumeration.count
222+
223+
let lockForSeenCount = NSLock()
224+
var seenCount = 0
225+
221226
testExpectingToSee(indexesForStaggeredEnumeration) { (indexesSeen) in
222227
array.enumerateObjects(at: evenIndexes, options: options, using: { (value, index, stop) in
223228
XCTAssertEqual(value as! NSNumber, array[index] as! NSNumber)
224229

225230
if (indexesForStaggeredEnumeration.contains(index)) {
226231
indexesSeen[index] = true
227-
} else {
228-
stop.pointee = true
232+
233+
lockForSeenCount.lock()
234+
seenCount += 1
235+
let currentCount = seenCount
236+
lockForSeenCount.unlock()
237+
238+
if currentCount == finalCount {
239+
stop.pointee = true
240+
}
229241
}
230242
})
231243
}

0 commit comments

Comments
 (0)