Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
ci: Increase timeout, attempt to repair test
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Mar 6, 2022
1 parent 5b6987c commit 4e7aa8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 8 additions & 2 deletions health/db.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package health

import (
"fmt"
"github.com/pkg/errors"
"gorm.io/gorm"
"math/rand"
"time"
)

type DbValidator struct {
db *gorm.DB
}

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")
}

Expand Down
6 changes: 3 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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'])
4 changes: 2 additions & 2 deletions tests/test_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")

0 comments on commit 4e7aa8d

Please sign in to comment.