Skip to content

Commit

Permalink
Attempt fix crash in app state pretty print
Browse files Browse the repository at this point in the history
Closes #1002
  • Loading branch information
LeoNatan committed Nov 4, 2018
1 parent 7047c22 commit 6e6fd64
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
2 changes: 1 addition & 1 deletion detox/ios/Detox/EarlGreyStatistics.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void WXFixupIdlingResourceClasses()
Method m = class_getInstanceMethod(cls, @selector(isIdleNow));

BOOL (*origIsIdleNow)(id, SEL) = (BOOL(*)(id, SEL))method_getImplementation(m);
method_setImplementation(m, imp_implementationWithBlock(^ (id<GREYIdlingResource> _self) {
method_setImplementation(m, imp_implementationWithBlock(^ BOOL (id<GREYIdlingResource> _self) {
BOOL rv = origIsIdleNow(_self, @selector(isIdleNow));

if(rv == NO)
Expand Down
60 changes: 29 additions & 31 deletions detox/ios/Detox/GREYIdlingResourcePrettyPrint.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ @interface NSMapTable<KeyType, ObjectType> ()

@end

static NSMapTable<GREYAppStateTrackerObject*, __DTXDeallocSafeProxy*>* __tarckedObjectsMapping;
static NSMapTable<GREYAppStateTrackerObject*, NSObject*>* __tarckedObjectsMapping;
static dispatch_queue_t __tarckedObjectsQueue;

@interface GREYAppStateTracker (PrettyPrint) @end
Expand All @@ -63,10 +63,10 @@ - (GREYAppStateTrackerObject *)_pp__trackState:(GREYAppState)state forObject:(id
{
GREYAppStateTrackerObject* rv = [self _pp__trackState:state forObject:element];

__DTXDeallocSafeProxy* proxy = [[__DTXDeallocSafeProxy alloc] initWithObject:element];
// __DTXDeallocSafeProxy* proxy = [[__DTXDeallocSafeProxy alloc] initWithObject:element];

dispatch_sync(__tarckedObjectsQueue, ^{
[__tarckedObjectsMapping setObject:proxy forKey:rv];
[__tarckedObjectsMapping setObject:element forKey:rv];
});

return rv;
Expand Down Expand Up @@ -172,39 +172,37 @@ + (void)load
__block NSArray<__DTXDeallocSafeProxy*>* allElements;
dispatch_sync(__tarckedObjectsQueue, ^{
allElements = [__tarckedObjectsMapping.allValues copy];
});


NSMutableArray* elems = [NSMutableArray new];
NSMutableArray* URLs = [NSMutableArray new];

[allElements enumerateObjectsUsingBlock:^(__DTXDeallocSafeProxy* _Nonnull actualElement, NSUInteger idx, BOOL * _Nonnull stop) {
id actualObject = actualElement.object;
if(actualObject == nil)

NSMutableArray* elems = [NSMutableArray new];
NSMutableArray* URLs = [NSMutableArray new];

[allElements enumerateObjectsUsingBlock:^(id _Nonnull actualElement, NSUInteger idx, BOOL * _Nonnull stop) {
id actualObject = actualElement;
if(actualObject == nil)
{
return;
}

[elems addObject:[actualObject description]];

if([actualObject isKindOfClass:[NSURLSessionTask class]])
{
[URLs addObject:[(NSURLSessionTask*)actualObject originalRequest].URL.absoluteString];
}
}];

if(elems.count > 0)
{
return;
rv[@"elements"] = elems;
}

[elems addObject:[actualObject description]];

if([actualObject isKindOfClass:[NSURLSessionTask class]])
if(URLs.count > 0)
{
[URLs addObject:[(NSURLSessionTask*)actualObject originalRequest].URL.absoluteString];
rv[@"urls"] = URLs;
rv[@"prettyPrint"] = [NSString stringWithFormat:@"%@: %@", stateString, URLs];
}
}];

if(elems.count > 0)
{
rv[@"elements"] = elems;
}

if(URLs.count > 0)
{
rv[@"urls"] = URLs;
rv[@"prettyPrint"] = [NSString stringWithFormat:@"%@: %@", stateString, URLs];
}


});

return rv;
}

Expand Down

0 comments on commit 6e6fd64

Please sign in to comment.