44using System ;
55using System . Collections . Generic ;
66using System . IO ;
7+ using System . Net ;
78using System . Threading ;
89using System . Threading . Tasks ;
910using Microsoft . Extensions . Logging ;
@@ -169,7 +170,7 @@ public async Task RestartsFirstUnhealthyInstance()
169170 }
170171
171172 [ Fact ]
172- public async Task TreatsExceptionWhenGettingCommitTimestampAsUnknown ( )
173+ public async Task TreatsUnknownExceptionWhenGettingCommitTimestampAsUnknown ( )
173174 {
174175 _searchServiceClient
175176 . SetupSequence ( x => x . GetCommitDateTimeAsync ( It . IsAny < Instance > ( ) , It . IsAny < CancellationToken > ( ) ) )
@@ -195,6 +196,74 @@ public async Task TreatsExceptionWhenGettingCommitTimestampAsUnknown()
195196 _telemetryService . Verify ( x => x . TrackInstanceCount ( _region , 3 ) , Times . Once ) ;
196197 }
197198
199+ [ Theory ]
200+ [ InlineData ( HttpStatusCode . BadGateway ) ]
201+ [ InlineData ( HttpStatusCode . NotFound ) ]
202+ public async Task TreatsUnknownHttpStatusCodeExceptionWhenGettingCommitTimestampAsUnknown ( HttpStatusCode statusCode )
203+ {
204+ _searchServiceClient
205+ . SetupSequence ( x => x . GetCommitDateTimeAsync ( It . IsAny < Instance > ( ) , It . IsAny < CancellationToken > ( ) ) )
206+ . ThrowsAsync ( new HttpResponseException ( statusCode , "Service Unavailable" , "Some problem." ) )
207+ . ReturnsAsync ( DateTimeOffset . MaxValue )
208+ . ReturnsAsync ( DateTimeOffset . MaxValue ) ;
209+
210+ await _target . RunAsync ( _token ) ;
211+
212+ _azureManagementAPIWrapper . Verify (
213+ x => x . RebootCloudServiceRoleInstanceAsync (
214+ It . IsAny < string > ( ) ,
215+ It . IsAny < string > ( ) ,
216+ It . IsAny < string > ( ) ,
217+ It . IsAny < string > ( ) ,
218+ It . IsAny < string > ( ) ,
219+ It . IsAny < string > ( ) ,
220+ It . IsAny < CancellationToken > ( ) ) ,
221+ Times . Never ) ;
222+ _telemetryService . Verify ( x => x . TrackHealthyInstanceCount ( _region , 2 ) , Times . Once ) ;
223+ _telemetryService . Verify ( x => x . TrackUnhealthyInstanceCount ( _region , 0 ) , Times . Once ) ;
224+ _telemetryService . Verify ( x => x . TrackUnknownInstanceCount ( _region , 1 ) , Times . Once ) ;
225+ _telemetryService . Verify ( x => x . TrackInstanceCount ( _region , 3 ) , Times . Once ) ;
226+ }
227+
228+ [ Theory ]
229+ [ InlineData ( HttpStatusCode . InternalServerError ) ]
230+ [ InlineData ( HttpStatusCode . ServiceUnavailable ) ]
231+ public async Task TreatsSome500sHttpResponseExceptionAsUnhealthy ( HttpStatusCode statusCode )
232+ {
233+ _searchServiceClient
234+ . SetupSequence ( x => x . GetCommitDateTimeAsync ( It . IsAny < Instance > ( ) , It . IsAny < CancellationToken > ( ) ) )
235+ . ThrowsAsync ( new HttpResponseException ( statusCode , "Service Unavailable" , "Some problem." ) )
236+ . ReturnsAsync ( DateTimeOffset . MaxValue )
237+ . ReturnsAsync ( DateTimeOffset . MaxValue ) ;
238+
239+ await _target . RunAsync ( _token ) ;
240+
241+ _azureManagementAPIWrapper . Verify (
242+ x => x . RebootCloudServiceRoleInstanceAsync (
243+ _subscription ,
244+ _resourceGroup ,
245+ _serviceName ,
246+ "Production" ,
247+ _role ,
248+ It . IsAny < string > ( ) ,
249+ It . IsAny < CancellationToken > ( ) ) ,
250+ Times . Once ) ;
251+ _azureManagementAPIWrapper . Verify (
252+ x => x . RebootCloudServiceRoleInstanceAsync (
253+ It . IsAny < string > ( ) ,
254+ It . IsAny < string > ( ) ,
255+ It . IsAny < string > ( ) ,
256+ It . IsAny < string > ( ) ,
257+ It . IsAny < string > ( ) ,
258+ It . IsAny < string > ( ) ,
259+ It . IsAny < CancellationToken > ( ) ) ,
260+ Times . Once ) ;
261+ _telemetryService . Verify ( x => x . TrackHealthyInstanceCount ( _region , 2 ) , Times . Once ) ;
262+ _telemetryService . Verify ( x => x . TrackUnhealthyInstanceCount ( _region , 1 ) , Times . Once ) ;
263+ _telemetryService . Verify ( x => x . TrackUnknownInstanceCount ( _region , 0 ) , Times . Once ) ;
264+ _telemetryService . Verify ( x => x . TrackInstanceCount ( _region , 3 ) , Times . Once ) ;
265+ }
266+
198267 [ Fact ]
199268 public async Task TreatsLagBetweenThresholdsAsUnknown ( )
200269 {
0 commit comments