-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from bugsnag/thread-id
Capture trace of error reporting thread and identify with boolean flag
- Loading branch information
Showing
9 changed files
with
160 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Feature: Error Reporting Thread | ||
|
||
Scenario: Only 1 thread is flagged as the error reporting thread | ||
When I run "HandledErrorScenario" with the defaults on "iPhone8-11.2" | ||
Then I should receive a request | ||
And the request is a valid for the error reporting API | ||
And the thread with id "0" contains the error reporting flag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// Created by Jamie Lynch on 02/08/2018. | ||
// Copyright (c) 2018 Bugsnag. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <XCTest/XCTest.h> | ||
|
||
#import "BugsnagCrashReport.h" | ||
|
||
@interface BugsnagThreadTest : XCTestCase | ||
@end | ||
|
||
@interface BugsnagCrashReport () | ||
- (NSArray *)serializeThreadsWithException:(NSMutableDictionary *)exception; | ||
|
||
@property(nonatomic, readonly, copy, nullable) NSArray *threads; | ||
@end | ||
|
||
@implementation BugsnagThreadTest | ||
|
||
- (void)testEmptyThreads { | ||
BugsnagCrashReport *report = [self generateReportWithThreads:@[]]; | ||
NSArray *threads = [report serializeThreadsWithException:nil]; | ||
XCTAssertTrue(threads.count == 0); | ||
} | ||
|
||
- (void)testThreadSerialisation { | ||
NSArray *trace = @[ | ||
@{ | ||
@"backtrace": @{ | ||
@"contents": @[ | ||
@{ | ||
@"instruction_addr": @4438096107, | ||
@"object_addr": @4438048768, | ||
@"object_name": @"Bugsnag Test App", | ||
@"symbol_addr": @4438048768, | ||
@"symbol_name": @"_mh_execute_header", | ||
} | ||
], | ||
@"skipped": @NO, | ||
}, | ||
@"crashed": @YES, | ||
@"current_thread": @YES, | ||
@"index": @0 | ||
}, | ||
@{ | ||
@"backtrace": @{ | ||
@"contents": @[ | ||
@{ | ||
@"instruction_addr": @4510040722, | ||
@"object_addr": @4509921280, | ||
@"object_name": @"libsystem_kernel.dylib", | ||
@"symbol_addr": @4510040712, | ||
@"symbol_name": @"__workq_kernreturn", | ||
} | ||
], | ||
@"skipped": @NO, | ||
}, | ||
@"crashed": @NO, | ||
@"current_thread": @NO, | ||
@"index": @1 | ||
}, | ||
]; | ||
|
||
BugsnagCrashReport *report = [self generateReportWithThreads:trace]; | ||
NSArray *threads = [report serializeThreadsWithException:nil]; | ||
XCTAssertTrue(threads.count == 2); | ||
|
||
// first thread is crashed, should be serialised and contain 'errorReportingThread' flag | ||
NSDictionary *firstThread = threads[0]; | ||
XCTAssertEqualObjects(@0, firstThread[@"id"]); | ||
XCTAssertEqualObjects(@"cocoa", firstThread[@"type"]); | ||
XCTAssertNotNil(firstThread[@"stacktrace"]); | ||
XCTAssertTrue(firstThread[@"errorReportingThread"]); | ||
|
||
// second thread is not crashed, should not contain 'errorReportingThread' flag | ||
NSDictionary *secondThread = threads[1]; | ||
XCTAssertEqualObjects(@1, secondThread[@"id"]); | ||
XCTAssertEqualObjects(@"cocoa", secondThread[@"type"]); | ||
XCTAssertNotNil(secondThread[@"stacktrace"]); | ||
XCTAssertNil(secondThread[@"errorReportingThread"]); | ||
} | ||
|
||
- (BugsnagCrashReport *)generateReportWithThreads:(NSArray *)threads { | ||
return [[BugsnagCrashReport alloc] initWithKSReport:@{@"crash": @{@"threads": threads}}]; | ||
} | ||
|
||
|
||
@end |