@@ -224,4 +224,44 @@ public async Task CheckHealthAsync_WithKeyedService_ShouldUseKeyedService()
224224 _ = await Assert . That ( result . Description ) . IsEqualTo ( $ "{ testName } : Healthy") ;
225225 }
226226 }
227+
228+ [ Test ]
229+ public async Task CheckHealthAsync_WithKeyedService_PrefersKeyedOverDefault ( )
230+ {
231+ // Arrange
232+ const string testName = "Test" ;
233+ const string serviceKey = "test-key" ;
234+
235+ var options = new DaprOptions { KeyedService = serviceKey , Timeout = 100 } ;
236+
237+ var optionsMonitor = Substitute . For < IOptionsMonitor < DaprOptions > > ( ) ;
238+ _ = optionsMonitor . Get ( testName ) . Returns ( options ) ;
239+
240+ var defaultClient = Substitute . For < DaprClient > ( ) ;
241+ _ = defaultClient . CheckHealthAsync ( Arg . Any < CancellationToken > ( ) ) . Returns ( false ) ; // Returns unhealthy
242+
243+ var keyedClient = Substitute . For < DaprClient > ( ) ;
244+ _ = keyedClient . CheckHealthAsync ( Arg . Any < CancellationToken > ( ) ) . Returns ( true ) ; // Returns healthy
245+
246+ var serviceProvider = new ServiceCollection ( )
247+ . AddSingleton ( defaultClient )
248+ . AddKeyedSingleton ( serviceKey , keyedClient )
249+ . BuildServiceProvider ( ) ;
250+
251+ var healthCheck = new DaprHealthCheck ( serviceProvider , optionsMonitor ) ;
252+ var context = new HealthCheckContext
253+ {
254+ Registration = new HealthCheckRegistration ( testName , healthCheck , HealthStatus . Unhealthy , null ) ,
255+ } ;
256+
257+ // Act
258+ var result = await healthCheck . CheckHealthAsync ( context , CancellationToken . None ) ;
259+
260+ // Assert - Should be Healthy (from keyed service), not Degraded (from default)
261+ using ( Assert . Multiple ( ) )
262+ {
263+ _ = await Assert . That ( result . Status ) . IsEqualTo ( HealthStatus . Healthy ) ;
264+ _ = await Assert . That ( result . Description ) . IsEqualTo ( $ "{ testName } : Healthy") ;
265+ }
266+ }
227267}
0 commit comments