@@ -633,5 +633,75 @@ public async Task Agent_Register_UseCustomCheckId()
633633 Assert . Equal ( check . Name , check1Name ) ;
634634 Assert . Equal ( check . CheckID , check1Id ) ;
635635 }
636+
637+ [ Fact ]
638+ public async Task Agent_Register_UseAliasCheck ( )
639+ {
640+ var ttl = TimeSpan . FromSeconds ( 5 ) ;
641+ var delay = TimeSpan . FromMilliseconds ( ttl . TotalMilliseconds / 2 ) ;
642+ var svcID = KVTest . GenerateTestKeyName ( ) ;
643+ var svcID1 = svcID + "1" ;
644+ var svcID2 = svcID + "2" ;
645+ var check1Id = svcID1 + "_checkId" ;
646+ var check1Name = svcID1 + "_checkName" ;
647+ var registration1 = new AgentServiceRegistration
648+ {
649+ ID = svcID1 ,
650+ Name = svcID1 ,
651+ Port = 8000 ,
652+ Checks = new [ ]
653+ {
654+ new AgentServiceCheck
655+ {
656+ Name = check1Name ,
657+ CheckID = check1Id ,
658+ TTL = ttl ,
659+ } ,
660+ }
661+ } ;
662+
663+ var check2Id = svcID2 + "_checkId" ;
664+ var check2Name = svcID2 + "_checkName" ;
665+ var registration2 = new AgentServiceRegistration
666+ {
667+ ID = svcID2 ,
668+ Name = svcID2 ,
669+ Port = 8000 ,
670+ Checks = new [ ]
671+ {
672+ new AgentServiceCheck
673+ {
674+ Name = check2Name ,
675+ CheckID = check2Id ,
676+ AliasService = svcID1 ,
677+ } ,
678+ } ,
679+ } ;
680+
681+ await _client . Agent . ServiceRegister ( registration1 ) ;
682+ await _client . Agent . ServiceRegister ( registration2 ) ;
683+
684+ var checks = await _client . Agent . Checks ( ) ;
685+ Assert . Equal ( HealthStatus . Critical , checks . Response [ check1Id ] . Status ) ;
686+ Assert . NotEqual ( "test is ok" , checks . Response [ check1Id ] . Output ) ;
687+ Assert . Equal ( HealthStatus . Critical , checks . Response [ check2Id ] . Status ) ;
688+ Assert . NotEqual ( "test is ok" , checks . Response [ check2Id ] . Output ) ;
689+
690+ await _client . Agent . PassTTL ( check1Id , "test is ok" ) ;
691+
692+ // wait for some time to make sure the checks status propagates
693+ await Task . Delay ( delay ) ;
694+ checks = await _client . Agent . Checks ( ) ;
695+ Assert . Equal ( HealthStatus . Passing , checks . Response [ check1Id ] . Status ) ;
696+ Assert . Equal ( "test is ok" , checks . Response [ check1Id ] . Output ) ;
697+ Assert . Equal ( HealthStatus . Passing , checks . Response [ check2Id ] . Status ) ;
698+ Assert . Equal ( "All checks passing." , checks . Response [ check2Id ] . Output ) ;
699+
700+ // wait for checks to expire
701+ await Task . Delay ( ttl ) ;
702+ checks = await _client . Agent . Checks ( ) ;
703+ Assert . Equal ( HealthStatus . Critical , checks . Response [ check1Id ] . Status ) ;
704+ Assert . Equal ( HealthStatus . Critical , checks . Response [ check2Id ] . Status ) ;
705+ }
636706 }
637707}
0 commit comments