Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Example/InstanceID/Tests/FIRInstanceIDCheckinServiceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ - (void)testCheckinServiceAddsFirebaseUserAgentToHTTPHeader {
}];
}

- (void)testCheckinServiceFailsWithErrorAfterStopFetching {
[self.checkinService stopFetching];

XCTestExpectation *checkinCompletionExpectation =
[self expectationWithDescription:@"Checkin Completion"];

[self.checkinService
checkinWithExistingCheckin:nil
completion:^(FIRInstanceIDCheckinPreferences *preferences, NSError *error) {
[checkinCompletionExpectation fulfill];
XCTAssertNil(preferences);
XCTAssertNotNil(error);
XCTAssertEqual(error.code, kFIRInstanceIDErrorCodeRegistrarFailedToCheckIn);
}];

[self waitForExpectationsWithTimeout:5
handler:^(NSError *error) {
if (error) {
XCTFail(@"Checkin Timeout Error: %@", error);
}
}];
}

#pragma mark - Stub

- (FIRInstanceIDCheckinPreferences *)stubCheckinCacheWithValidData {
Expand Down
1 change: 1 addition & 0 deletions Firebase/InstanceID/FIRIMessageCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typedef NS_ENUM(NSInteger, FIRInstanceIDMessageCode) {
kFIRInstanceIDMessageCodeService004 = 7004,
kFIRInstanceIDMessageCodeService005 = 7005,
kFIRInstanceIDMessageCodeService006 = 7006,
kFIRInstanceIDMessageCodeService007 = 7007,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we start giving the message code a meaning instead of a repeat number.
So you can do sth like kFIRIntsanceIDInvalidNetworkSession.

// FIRInstanceIDCheckinStore.m
// DO NOT USE 8002, 8004 - 8008
kFIRInstanceIDMessageCodeCheckinStore000 = 8000,
Expand Down
11 changes: 11 additions & 0 deletions Firebase/InstanceID/FIRInstanceIDCheckinService.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ - (void)checkinWithExistingCheckin:(FIRInstanceIDCheckinPreferences *)existingCh
completion:(FIRInstanceIDDeviceCheckinCompletion)completion {
_FIRInstanceIDDevAssert(completion != nil, @"completion required");

if (self.session == nil) {
FIRInstanceIDLoggerError(kFIRInstanceIDMessageCodeService007,
@"Inconsistent state: NSURLSession has been invalidated");
NSError *error =
[NSError errorWithFIRInstanceIDErrorCode:kFIRInstanceIDErrorCodeRegistrarFailedToCheckIn];
completion(nil, error);
return;
}

NSURL *url = [NSURL URLWithString:kDeviceCheckinURL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

Expand Down Expand Up @@ -179,6 +188,8 @@ - (void)checkinWithExistingCheckin:(FIRInstanceIDCheckinPreferences *)existingCh

- (void)stopFetching {
[self.session invalidateAndCancel];
// The session cannot be reused after invalidation. Dispose it to prevent accident reusing.
self.session = nil;
}

#pragma mark - Private
Expand Down