diff --git a/servicefabric.go b/servicefabric.go index 8183d94..c231534 100644 --- a/servicefabric.go +++ b/servicefabric.go @@ -303,7 +303,7 @@ func isPrimary(instance replicaInstance) bool { } func isHealthy(instanceData *sf.ReplicaItemBase) bool { - return instanceData != nil && (instanceData.ReplicaStatus == "Ready" || instanceData.HealthState != "Error") + return instanceData != nil && (instanceData.ReplicaStatus == "Ready" && instanceData.HealthState != "Error") } func hasHTTPEndpoint(instanceData *sf.ReplicaItemBase) bool { diff --git a/servicefabric_test.go b/servicefabric_test.go index f231324..f2bbf28 100644 --- a/servicefabric_test.go +++ b/servicefabric_test.go @@ -254,6 +254,22 @@ func TestIsHealthy(t *testing.T) { }, expected: false, }, + { + desc: "When replica down but health only warning", + replica: &sf.ReplicaItem{ + ReplicaItemBase: &sf.ReplicaItemBase{ + Address: `{"Endpoints":{"":"localhost:30001+bce46a8c-b62d-4996-89dc-7ffc00a96902-131496928082309293"}}`, + HealthState: "Warning", + LastInBuildDurationInSeconds: "1", + NodeName: "_Node_0", + ReplicaRole: "Primary", + ReplicaStatus: "Down", + ServiceKind: "Stateful", + }, + ID: "131496928082309293", + }, + expected: false, + }, } for _, test := range testCases {