@@ -111,6 +111,54 @@ - (void)testExecuteWithRedirectResopnseAndMaxRetries {
111111 [self checkCompletionBlockCodeInvoked ];
112112}
113113
114+ - (void )testExecuteWithRetryResopnse503AndSuccessfullRetry {
115+ XCTestExpectation *retryWaitExpectation = [[XCTestExpectation alloc ] initWithDescription: @" Waiting for retry attempt execution" ];
116+
117+ HTTPRequestCompletionHandler requestCompletion = ^(id data, NSURLResponse * _Nullable response, NSError * _Nullable error){
118+ [self completionBlockCodeInvoked ];
119+ XCTAssertNil (error);
120+ XCTAssertNotNil (response);
121+ XCTAssertEqual (((NSHTTPURLResponse *)response).statusCode , MSExpectedResponseCodesOK);
122+ XCTAssertNotNil (data);
123+ [retryWaitExpectation fulfill ];
124+ };
125+
126+ __block NSHTTPURLResponse *retryResponseWith503 = [[NSHTTPURLResponse alloc ] initWithURL: [NSURL URLWithString: MSGraphBaseURL] statusCode: MSClientErrorCodeServiceUnavailable HTTPVersion: @" foo" headerFields: nil ];
127+ OCMStub ([self .mockHttpProvider execute: [OCMArg any ] withCompletionHandler: [OCMArg any ]]).andDo (^(NSInvocation *invocation){
128+ HTTPRequestCompletionHandler completionHandler;
129+ [invocation getArgument: &completionHandler atIndex: 3 ];
130+ completionHandler ([NSData new ], retryResponseWith503, nil );
131+ retryResponseWith503 = self->_OKResponse ;
132+ });
133+ [self .retryHandler execute: _mockDataTask withCompletionHandler: requestCompletion];
134+ [self waitForExpectations: @[retryWaitExpectation] timeout: 12.0 ];
135+ [self checkCompletionBlockCodeInvoked ];
136+ }
137+
138+ - (void )testExecuteWithRetryResopnse504AndSuccessfullRetry {
139+ XCTestExpectation *retryWaitExpectation = [[XCTestExpectation alloc ] initWithDescription: @" Waiting for retry attempt execution" ];
140+
141+ HTTPRequestCompletionHandler requestCompletion = ^(id data, NSURLResponse * _Nullable response, NSError * _Nullable error){
142+ [self completionBlockCodeInvoked ];
143+ XCTAssertNil (error);
144+ XCTAssertNotNil (response);
145+ XCTAssertEqual (((NSHTTPURLResponse *)response).statusCode , MSExpectedResponseCodesOK);
146+ XCTAssertNotNil (data);
147+ [retryWaitExpectation fulfill ];
148+ };
149+
150+ __block NSHTTPURLResponse *retryResponseWith504 = [[NSHTTPURLResponse alloc ] initWithURL: [NSURL URLWithString: MSGraphBaseURL] statusCode: MSClientErrorCodeGatewayTimeout HTTPVersion: @" foo" headerFields: nil ];
151+ OCMStub ([self .mockHttpProvider execute: [OCMArg any ] withCompletionHandler: [OCMArg any ]]).andDo (^(NSInvocation *invocation){
152+ HTTPRequestCompletionHandler completionHandler;
153+ [invocation getArgument: &completionHandler atIndex: 3 ];
154+ completionHandler ([NSData new ], retryResponseWith504, nil );
155+ retryResponseWith504 = self->_OKResponse ;
156+ });
157+ [self .retryHandler execute: _mockDataTask withCompletionHandler: requestCompletion];
158+ [self waitForExpectations: @[retryWaitExpectation] timeout: 12.0 ];
159+ [self checkCompletionBlockCodeInvoked ];
160+ }
161+
114162- (void )testExecuteWithNormalResponse {
115163 HTTPRequestCompletionHandler requestCompletion = ^(id data, NSURLResponse * _Nullable response, NSError * _Nullable error){
116164 [self completionBlockCodeInvoked ];
0 commit comments