Skip to content

Commit 1ec44e1

Browse files
authored
Merge pull request #649 from averevki/add-backoff-to-healthchecks
Add backoff to the health-check tests
2 parents 444731f + 5c8367f commit 1ec44e1

File tree

1 file changed

+21
-1
lines changed
  • testsuite/kuadrant/policy

1 file changed

+21
-1
lines changed

testsuite/kuadrant/policy/dns.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from dataclasses import dataclass
44
from typing import Optional, Literal
55

6+
import openshift_client as oc
7+
68
from testsuite.gateway import Referencable
79
from testsuite.kubernetes import KubernetesObject
810
from testsuite.kubernetes.client import KubernetesClient
@@ -54,8 +56,13 @@ class HealthCheck: # pylint: disable=invalid-name
5456
class DNSHealthCheckProbe(KubernetesObject):
5557
"""DNSHealthCheckProbe object"""
5658

59+
def _status_ready(self):
60+
"""Returns True if DNSHealthCheckProbe status.healthy field has appeared"""
61+
return self.wait_until(lambda obj: obj.model.status.healthy is not oc.Missing)
62+
5763
def is_healthy(self) -> bool:
5864
"""Returns True if DNSHealthCheckProbe endpoint is healthy"""
65+
assert self._status_ready(), "DNSHealthCheckProbe status wasn't ready in time"
5966
return self.refresh().model.status.healthy
6067

6168

@@ -93,10 +100,23 @@ def set_health_check(self, health_check: HealthCheck):
93100
"""Sets health check for DNSPolicy"""
94101
self.model["spec"]["healthCheck"] = asdict(health_check)
95102

103+
def _get_dns_record(self):
104+
"""Returns DNSRecord object for the created DNSPolicy"""
105+
with self.context:
106+
assert self.wait_until(
107+
lambda obj: len(obj.get_owned("dnsrecords.kuadrant.io")) > 0
108+
), "The corresponding DNSRecord object wasn't created in time"
109+
dns_record = self.get_owned("dnsrecords.kuadrant.io")[0]
110+
return KubernetesObject(dns_record.model, context=self.context)
111+
96112
def get_dns_health_probe(self) -> DNSHealthCheckProbe:
97113
"""Returns DNSHealthCheckProbe object for the created DNSPolicy"""
114+
dns_record = self._get_dns_record()
98115
with self.context:
99-
dns_probe = self.get_owned("dnsrecords.kuadrant.io")[0].get_owned("DNSHealthCheckProbe")[0]
116+
assert dns_record.wait_until(
117+
lambda obj: len(obj.get_owned("DNSHealthCheckProbe")) > 0
118+
), "The corresponding DNSHealthCheckProbe object wasn't created in time"
119+
dns_probe = dns_record.get_owned("DNSHealthCheckProbe")[0]
100120
return DNSHealthCheckProbe(dns_probe.model, context=self.context)
101121

102122
def wait_for_full_enforced(self, timelimit=300):

0 commit comments

Comments
 (0)