Skip to content

Commit 3012e99

Browse files
charliewilliamsflovilmart
authored andcommitted
Remove PFEventuallyQueueTestHelper because (1) it was causing memory leaks in production code, and (2) it wasn't actually used in any tests. (#1188)
1 parent 33fc12d commit 3012e99

File tree

4 files changed

+1
-86
lines changed

4 files changed

+1
-86
lines changed

Parse/Internal/PFEventuallyQueue.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
@class BFTask<__covariant BFGenericType>;
1818
@class PFEventuallyPin;
19-
@class PFEventuallyQueueTestHelper;
2019
@class PFObject;
2120
@protocol PFCommandRunnerProvider;
2221

@@ -39,9 +38,6 @@ extern NSTimeInterval const PFEventuallyQueueDefaultTimeoutRetryInterval;
3938
@property (atomic, assign, readonly) BOOL monitorsReachability PF_WATCH_UNAVAILABLE;
4039
@property (nonatomic, assign, readonly, getter=isConnected) BOOL connected;
4140

42-
// Gets notifications of various events happening in the command cache, so that tests can be synchronized.
43-
@property (nonatomic, strong, readonly) PFEventuallyQueueTestHelper *testHelper;
44-
4541
///--------------------------------------
4642
#pragma mark - Init
4743
///--------------------------------------
@@ -71,26 +67,3 @@ extern NSTimeInterval const PFEventuallyQueueDefaultTimeoutRetryInterval;
7167
- (void)removeAllCommands NS_REQUIRES_SUPER;
7268

7369
@end
74-
75-
typedef enum {
76-
PFEventuallyQueueEventCommandEnqueued, // A command was placed into the queue.
77-
PFEventuallyQueueEventCommandNotEnqueued, // A command could not be placed into the queue.
78-
79-
PFEventuallyQueueEventCommandSucceded, // A command has successfully running on the server.
80-
PFEventuallyQueueEventCommandFailed, // A command has failed on the server.
81-
82-
PFEventuallyQueueEventObjectUpdated, // An object's data was updated after a command completed.
83-
PFEventuallyQueueEventObjectRemoved, // An object was removed because it was deleted before creation.
84-
85-
PFEventuallyQueueEventCount // The total number of items in this enum.
86-
} PFEventuallyQueueTestHelperEvent;
87-
88-
@interface PFEventuallyQueueTestHelper : NSObject {
89-
dispatch_semaphore_t events[PFEventuallyQueueEventCount];
90-
}
91-
92-
- (void)clear;
93-
- (void)notify:(PFEventuallyQueueTestHelperEvent)event;
94-
- (BOOL)waitFor:(PFEventuallyQueueTestHelperEvent)event;
95-
96-
@end

Parse/Internal/PFEventuallyQueue.m

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ - (instancetype)initWithDataSource:(id<PFCommandRunnerProvider>)dataSource
7373
_commandEnqueueTaskQueue = [[PFTaskQueue alloc] init];
7474

7575
_taskCompletionSources = [NSMutableDictionary dictionary];
76-
_testHelper = [[PFEventuallyQueueTestHelper alloc] init];
7776

7877
[self _startMonitoringNetworkReachability];
7978

@@ -103,14 +102,11 @@ - (BFTask *)enqueueCommandInBackground:(id<PFNetworkCommand>)command withObject:
103102
object:object
104103
identifier:identifier] continueWithBlock:^id(BFTask *task) {
105104
if (task.faulted || task.cancelled) {
106-
[self.testHelper notify:PFEventuallyQueueEventCommandNotEnqueued];
107105
if (task.error) {
108106
taskCompletionSource.error = task.error;
109107
} else if (task.cancelled) {
110108
[taskCompletionSource cancel];
111109
}
112-
} else {
113-
[self.testHelper notify:PFEventuallyQueueEventCommandEnqueued];
114110
}
115111

116112
return task;
@@ -337,12 +333,6 @@ - (BFTask *)_didFinishRunningCommand:(id<PFNetworkCommand>)command
337333
[_taskCompletionSources removeObjectForKey:identifier];
338334
});
339335

340-
if (resultTask.faulted || resultTask.cancelled) {
341-
[self.testHelper notify:PFEventuallyQueueEventCommandFailed];
342-
} else {
343-
[self.testHelper notify:PFEventuallyQueueEventCommandSucceded];
344-
}
345-
346336
return resultTask;
347337
}
348338

@@ -437,11 +427,6 @@ - (int)_commandsInMemory {
437427
return (int)_taskCompletionSources.count;
438428
}
439429

440-
/** Called by PFObject whenever an object has been updated after a saveEventually. */
441-
- (void)_notifyTestHelperObjectUpdated {
442-
[self.testHelper notify:PFEventuallyQueueEventObjectUpdated];
443-
}
444-
445430
- (void)_setMaxAttemptsCount:(NSUInteger)attemptsCount {
446431
_maxAttemptsCount = attemptsCount;
447432
}
@@ -465,33 +450,3 @@ - (void)reachability:(PFReachability *)reachability didChangeReachabilityState:(
465450
#endif
466451

467452
@end
468-
469-
// PFEventuallyQueueTestHelper gets notifications of various events happening in the command cache,
470-
// so that tests can be synchronized. See CommandTests.m for examples of how to use this.
471-
472-
@implementation PFEventuallyQueueTestHelper
473-
474-
- (instancetype)init {
475-
self = [super init];
476-
if (self) {
477-
[self clear];
478-
}
479-
return self;
480-
}
481-
482-
- (void)clear {
483-
for (int i = 0; i < PFEventuallyQueueEventCount; ++i) {
484-
events[i] = dispatch_semaphore_create(0);
485-
}
486-
}
487-
488-
- (void)notify:(PFEventuallyQueueTestHelperEvent)event {
489-
dispatch_semaphore_signal(events[event]);
490-
}
491-
492-
- (BOOL)waitFor:(PFEventuallyQueueTestHelperEvent)event {
493-
// Wait 1 second for a permit from the semaphore.
494-
return (dispatch_semaphore_wait(events[event], dispatch_time(DISPATCH_TIME_NOW, 10LL * NSEC_PER_SEC)) == 0);
495-
}
496-
497-
@end

Parse/Internal/PFEventuallyQueue_Private.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,7 @@ extern NSTimeInterval const PFEventuallyQueueDefaultTimeoutRetryInterval;
6464
- (void)_startMonitoringNetworkReachability;
6565
- (void)_stopMonitoringNetworkReachability;
6666

67-
///--------------------------------------
68-
#pragma mark - Test Helper
69-
///--------------------------------------
70-
71-
- (void)_setMaxAttemptsCount:(NSUInteger)attemptsCount;
72-
73-
- (void)_setRetryInterval:(NSTimeInterval)retryInterval;
74-
7567
- (void)_simulateReboot NS_REQUIRES_SUPER;
76-
77-
- (int)_commandsInMemory;
78-
79-
- (void)_notifyTestHelperObjectUpdated;
80-
8168
@end
8269

8370
@protocol PFEventuallyQueueSubclass <NSObject>

Parse/PFObject.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ - (BFTask *)_enqueueSaveEventuallyWithChildren:(BOOL)saveChildren {
10981098
}
10991099
return task;
11001100
} @finally {
1101-
[[Parse _currentManager].eventuallyQueue _notifyTestHelperObjectUpdated];
1101+
11021102
}
11031103
}];
11041104
return [BFTask taskWithResult:saveTask];

0 commit comments

Comments
 (0)