diff --git a/health/db.go b/health/db.go index f648929a..a96d14eb 100644 --- a/health/db.go +++ b/health/db.go @@ -1,8 +1,11 @@ package health import ( + "fmt" "github.com/pkg/errors" "gorm.io/gorm" + "math/rand" + "time" ) type DbValidator struct { @@ -10,9 +13,12 @@ type DbValidator struct { } func (v DbValidator) Validate() error { + rand.Seed(time.Now().UnixNano()) + key := rand.Intn(8) var result int - err := v.db.Raw("SELECT 161").Scan(&result).Error - if err != nil || result != 161 { + + err := v.db.Raw(fmt.Sprintf("SELECT %v", key)).Scan(&result).Error + if err != nil || result != key { return errors.Wrapf(err, "cannot connect to database") } diff --git a/tests/__init__.py b/tests/__init__.py index 4316cf07..ba8606e8 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -8,12 +8,12 @@ class BaseTestCase(unittest.TestCase): _base_url: str = 'http://localhost:30080' - def get(self, url: str, auth: str = None) -> requests.Response: + def get(self, url: str, auth: str = None, timeout: int = 5) -> requests.Response: headers = {} if auth: headers['Authorization'] = f'Bearer {auth}' - return requests.get(f"{self._base_url}{url}", headers=headers) + return requests.get(f"{self._base_url}{url}", headers=headers, timeout=timeout) def post(self, url: str, data: any, additional_headers: dict = None, auth: str = None) -> requests.Response: headers = {} @@ -49,4 +49,4 @@ def wait_for(label: str, ready: bool = True): if ready: condition = "=False" - subprocess.check_call(['kubectl', 'wait', '--for=condition=ready' + condition, 'pod', '-l', label, '-n', 'backup-repository', '--timeout=120s']) + subprocess.check_call(['kubectl', 'wait', '--for=condition=ready' + condition, 'pod', '-l', label, '-n', 'backup-repository', '--timeout=300s']) diff --git a/tests/test_health.py b/tests/test_health.py index bf9d11b2..38535fa8 100644 --- a/tests/test_health.py +++ b/tests/test_health.py @@ -13,7 +13,7 @@ def test_readiness_when_postgresql_is_off(self): self.wait_for("app.kubernetes.io/instance=postgres", ready=False) response = self.get("/ready?code=changeme", auth=None) - assert response.status_code >= 500 + assert response.status_code >= 500, response.content finally: self.scale("sts", "postgres-postgresql", 1) self.wait_for("app.kubernetes.io/instance=postgres") @@ -24,7 +24,7 @@ def test_readiness_when_storage_is_off(self): self.wait_for("app=minio", ready=False) response = self.get("/ready?code=changeme", auth=None) - assert response.status_code >= 500 + assert response.status_code >= 500, response.content finally: self.scale("deployment", "minio", 1) self.wait_for("app=minio")