@@ -39,11 +39,10 @@ public async Task ImdsFails404TwiceThenSucceeds200Async(
3939 . WithHttpManager ( httpManager )
4040 . WithRetryPolicyFactory ( _testRetryPolicyFactory ) ;
4141
42- // Disable cache to avoid pollution
43-
44-
4542 IManagedIdentityApplication mi = miBuilder . Build ( ) ;
4643
44+ ManagedIdentityTests . MockImdsV1Probe ( httpManager , ManagedIdentitySource . Imds , userAssignedIdentityId , userAssignedId ) ;
45+
4746 // Simulate two 404s (to trigger retries), then a successful response
4847 const int Num404Errors = 2 ;
4948 for ( int i = 0 ; i < Num404Errors ; i ++ )
@@ -98,11 +97,10 @@ public async Task ImdsFails410FourTimesThenSucceeds200Async(
9897 . WithHttpManager ( httpManager )
9998 . WithRetryPolicyFactory ( _testRetryPolicyFactory ) ;
10099
101- // Disable cache to avoid pollution
102-
103-
104100 IManagedIdentityApplication mi = miBuilder . Build ( ) ;
105101
102+ ManagedIdentityTests . MockImdsV1Probe ( httpManager , ManagedIdentitySource . Imds , userAssignedIdentityId , userAssignedId ) ;
103+
106104 // Simulate four 410s (to trigger retries), then a successful response
107105 const int Num410Errors = 4 ;
108106 for ( int i = 0 ; i < Num410Errors ; i ++ )
@@ -157,11 +155,10 @@ public async Task ImdsFails410PermanentlyAsync(
157155 . WithHttpManager ( httpManager )
158156 . WithRetryPolicyFactory ( _testRetryPolicyFactory ) ;
159157
160- // Disable cache to avoid pollution
161-
162-
163158 IManagedIdentityApplication mi = miBuilder . Build ( ) ;
164159
160+ ManagedIdentityTests . MockImdsV1Probe ( httpManager , ManagedIdentitySource . Imds , userAssignedIdentityId , userAssignedId ) ;
161+
165162 // Simulate permanent 410s (to trigger the maximum number of retries)
166163 const int Num410Errors = 1 + TestImdsRetryPolicy . LinearStrategyNumRetries ; // initial request + maximum number of retries
167164 for ( int i = 0 ; i < Num410Errors ; i ++ )
@@ -213,11 +210,10 @@ public async Task ImdsFails504PermanentlyAsync(
213210 . WithHttpManager ( httpManager )
214211 . WithRetryPolicyFactory ( _testRetryPolicyFactory ) ;
215212
216- // Disable cache to avoid pollution
217-
218-
219213 IManagedIdentityApplication mi = miBuilder . Build ( ) ;
220214
215+ ManagedIdentityTests . MockImdsV1Probe ( httpManager , ManagedIdentitySource . Imds , userAssignedIdentityId , userAssignedId ) ;
216+
221217 // Simulate permanent 504s (to trigger the maximum number of retries)
222218 const int Num504Errors = 1 + TestImdsRetryPolicy . ExponentialStrategyNumRetries ; // initial request + maximum number of retries
223219 for ( int i = 0 ; i < Num504Errors ; i ++ )
@@ -269,11 +265,10 @@ public async Task ImdsFails400WhichIsNonRetriableAndRetryPolicyIsNotTriggeredAsy
269265 . WithHttpManager ( httpManager )
270266 . WithRetryPolicyFactory ( _testRetryPolicyFactory ) ;
271267
272- // Disable cache to avoid pollution
273-
274-
275268 IManagedIdentityApplication mi = miBuilder . Build ( ) ;
276269
270+ ManagedIdentityTests . MockImdsV1Probe ( httpManager , ManagedIdentitySource . Imds , userAssignedIdentityId , userAssignedId ) ;
271+
277272 httpManager . AddManagedIdentityMockHandler (
278273 ManagedIdentityTests . ImdsEndpoint ,
279274 ManagedIdentityTests . Resource ,
@@ -321,11 +316,10 @@ public async Task ImdsFails500AndRetryPolicyIsDisabledAndNotTriggeredAsync(
321316 . WithHttpManager ( httpManager )
322317 . WithRetryPolicyFactory ( _testRetryPolicyFactory ) ;
323318
324- // Disable cache to avoid pollution
325-
326-
327319 IManagedIdentityApplication mi = miBuilder . Build ( ) ;
328320
321+ ManagedIdentityTests . MockImdsV1Probe ( httpManager , ManagedIdentitySource . Imds , userAssignedIdentityId , userAssignedId ) ;
322+
329323 httpManager . AddManagedIdentityMockHandler (
330324 ManagedIdentityTests . ImdsEndpoint ,
331325 ManagedIdentityTests . Resource ,
@@ -367,11 +361,10 @@ public async Task ImdsRetryPolicyLifeTimeIsPerRequestAsync()
367361 . WithHttpManager ( httpManager )
368362 . WithRetryPolicyFactory ( _testRetryPolicyFactory ) ;
369363
370- // Disable cache to avoid pollution
371-
372-
373364 IManagedIdentityApplication mi = miBuilder . Build ( ) ;
374365
366+ ManagedIdentityTests . MockImdsV1Probe ( httpManager , ManagedIdentitySource . Imds ) ;
367+
375368 // Simulate permanent errors (to trigger the maximum number of retries)
376369 const int Num504Errors = 1 + TestImdsRetryPolicy . ExponentialStrategyNumRetries ; // initial request + maximum number of retries
377370 for ( int i = 0 ; i < Num504Errors ; i ++ )
0 commit comments