@@ -780,12 +780,28 @@ await WaitForConditionAsync(
780780 succeedConfigLog = _writer . ToString ( ) ;
781781 }
782782
783- HttpResponseMessage restResult = await _testClient . GetAsync ( "/rest/Book" ) ;
783+ // Retry REST request because metadata re-initialization happens asynchronously
784+ // after the "Validated hot-reloaded configuration file" message. The metadata provider
785+ // factory clears and re-initializes providers on the hot-reload thread, so requests
786+ // arriving before that completes will fail.
787+ HttpResponseMessage restResult = null ;
788+ bool restSucceeded = false ;
789+ for ( int attempt = 1 ; attempt <= 10 ; attempt ++ )
790+ {
791+ restResult = await _testClient . GetAsync ( "/rest/Book" ) ;
792+ if ( restResult . StatusCode == HttpStatusCode . OK )
793+ {
794+ restSucceeded = true ;
795+ break ;
796+ }
797+
798+ await Task . Delay ( 1000 ) ;
799+ }
784800
785801 // Assert
786802 Assert . IsTrue ( failedConfigLog . Contains ( HOT_RELOAD_FAILURE_MESSAGE ) ) ;
787803 Assert . IsTrue ( succeedConfigLog . Contains ( HOT_RELOAD_SUCCESS_MESSAGE ) ) ;
788- Assert . AreEqual ( HttpStatusCode . OK , restResult . StatusCode ) ;
804+ Assert . IsTrue ( restSucceeded , $ "REST request did not return OK after hot-reload. Last status: { restResult ? . StatusCode } " ) ;
789805 }
790806
791807 /// <summary>
@@ -838,12 +854,28 @@ await WaitForConditionAsync(
838854 succeedConfigLog = _writer . ToString ( ) ;
839855 }
840856
841- HttpResponseMessage restResult = await _testClient . GetAsync ( "/rest/Book" ) ;
857+ // Retry REST request because metadata re-initialization happens asynchronously
858+ // after the "Validated hot-reloaded configuration file" message. The metadata provider
859+ // factory clears and re-initializes providers on the hot-reload thread, so requests
860+ // arriving before that completes will fail.
861+ HttpResponseMessage restResult = null ;
862+ bool restSucceeded = false ;
863+ for ( int attempt = 1 ; attempt <= 10 ; attempt ++ )
864+ {
865+ restResult = await _testClient . GetAsync ( "/rest/Book" ) ;
866+ if ( restResult . StatusCode == HttpStatusCode . OK )
867+ {
868+ restSucceeded = true ;
869+ break ;
870+ }
871+
872+ await Task . Delay ( 1000 ) ;
873+ }
842874
843875 // Assert
844876 Assert . IsTrue ( failedConfigLog . Contains ( HOT_RELOAD_FAILURE_MESSAGE ) ) ;
845877 Assert . IsTrue ( succeedConfigLog . Contains ( HOT_RELOAD_SUCCESS_MESSAGE ) ) ;
846- Assert . AreEqual ( HttpStatusCode . OK , restResult . StatusCode ) ;
878+ Assert . IsTrue ( restSucceeded , $ "REST request did not return OK after hot-reload. Last status: { restResult ? . StatusCode } " ) ;
847879 }
848880
849881 /// <summary>
0 commit comments