Skip to content

Commit

Permalink
Improve reliability of OOM test
Browse files Browse the repository at this point in the history
Capturing the battery and orientation values in the initial creation of the
BugsnagSystemState object ensures they will be there when the app is terminated
to simulate an OOM.

The test was sometimes failing because BugsnagSystemState queues up
asynchronous writes in the background and these do not always have time
to complete when running the test scenario.
  • Loading branch information
nickdowell committed Nov 25, 2020
1 parent 8034319 commit 175a443
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Bugsnag/BugsnagSystemState.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#define STATE_DIR @"bugsnag/state"
#define STATE_FILE @"system_state.json"

#if BSG_PLATFORM_IOS
NSString *BSGOrientationNameFromEnum(UIDeviceOrientation deviceOrientation)
#endif

static NSDictionary* loadPreviousState(BugsnagKVStore *kvstore, NSString *jsonPath) {
NSData *data = [NSData dataWithContentsOfFile:jsonPath];
if(data == nil) {
Expand Down Expand Up @@ -127,6 +131,12 @@ id blankIfNil(id value) {
device[@"simulator"] = @NO;
#endif
device[@"totalMemory"] = systemInfo[@BSG_KSSystemField_Memory][@"usable"];
#if BSG_PLATFORM_IOS
device[BSGKeyBatteryLevel] = @([UIDevice currentDevice].batteryLevel);
UIDeviceBatteryState batteryState = [UIDevice currentDevice].batteryState;
device[BSGKeyCharging] = @(batteryState == UIDeviceBatteryStateCharging || batteryState == UIDeviceBatteryStateFull);
device[BSGKeyOrientation] = BSGOrientationNameFromEnum([UIDevice currentDevice].orientation);
#endif

NSMutableDictionary *state = [NSMutableDictionary new];
state[BSGKeyApp] = app;
Expand Down

0 comments on commit 175a443

Please sign in to comment.