@@ -45,42 +45,6 @@ - (UIImage *)_testImage
4545 return [[[UIImage alloc ] initWithContentsOfFile: [self _testImageURL ].path] autorelease ];
4646}
4747
48- static BOOL ASInvokeConditionBlockWithBarriers (BOOL (^block)()) {
49- // In case the block does multiple comparisons, ensure it has a consistent view of memory by issuing read-write
50- // barriers on either side of the block.
51- OSMemoryBarrier ();
52- BOOL result = block ();
53- OSMemoryBarrier ();
54- return result;
55- }
56-
57- static BOOL ASRunRunLoopUntilBlockIsTrue (BOOL (^block)())
58- {
59- // Time out after 30 seconds.
60- CFTimeInterval timeoutDate = CACurrentMediaTime () + 30 .0f ;
61- BOOL passed = NO ;
62-
63- while (true ) {
64- passed = ASInvokeConditionBlockWithBarriers (block);
65-
66- if (passed) {
67- break ;
68- }
69-
70- CFTimeInterval now = CACurrentMediaTime ();
71- if (now > timeoutDate) {
72- break ;
73- }
74-
75- // Run 1000 times a second until the poll timeout or until timeoutDate, whichever is first.
76- CFTimeInterval runLoopTimeout = MIN (0.001 , timeoutDate - now);
77- CFRunLoopRunInMode (kCFRunLoopDefaultMode , runLoopTimeout, true );
78- }
79-
80- return passed;
81- }
82-
83-
8448#pragma mark -
8549#pragma mark Unit tests.
8650
@@ -360,14 +324,11 @@ - (void)testUncachedDownload
360324 [imageNode reloadImageIdentifierSources ];
361325
362326 // Wait until the image is loaded.
363- ASRunRunLoopUntilBlockIsTrue (^BOOL {
364- return [(id )imageNode.loadedImageIdentifier isEqual: imageIdentifier];
365- });
327+ [self expectationForPredicate: [NSPredicate predicateWithFormat: @" loadedImageIdentifier = %@" , imageIdentifier] evaluatedWithObject: imageNode handler: nil ];
328+ [self waitForExpectationsWithTimeout: 30 handler: nil ];
366329
367330 // Verify the delegation.
368331 [mockDelegate verify ];
369- // Also verify that it's acutally loaded (could be false if we timed out above).
370- XCTAssertEqualObjects (imageNode.loadedImageIdentifier , imageIdentifier, @" Failed to load image" );
371332
372333 [imageNode release ];
373334}
0 commit comments