Skip to content

Commit b56f6de

Browse files
committed
chore: timeout and logging
1 parent c3fd5f9 commit b56f6de

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

.github/workflows/testinfra.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ jobs:
123123
# packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common.vars.pkr.hcl" -var "ansible_arguments=" -var "postgres-version=ci-ami-test" -var "region=ap-southeast-1" -var 'ami_regions=["ap-southeast-1"]' -var "force-deregister=true" amazon-arm64.pkr.hcl
124124

125125
- name: Run tests
126+
timeout-minutes: 5
126127
run: |
127128
# TODO: use poetry for pkg mgmt
128129
pip3 install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest pytest-testinfra[paramiko,docker] requests

testinfra/test_ami.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import base64
22
import boto3
33
import gzip
4+
import logging
45
import os
56
import pytest
67
import requests
@@ -149,6 +150,13 @@
149150
}}
150151
"""
151152

153+
logger = logging.getLogger("ami-tests")
154+
handler = logging.StreamHandler()
155+
formatter = logging.Formatter(
156+
'%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
157+
handler.setFormatter(formatter)
158+
logger.addHandler(handler)
159+
logger.setLevel(logging.DEBUG)
152160

153161
# scope='session' uses the same container for all the tests;
154162
# scope='function' uses a new container per test function.
@@ -245,30 +253,37 @@ def gzip_then_base64_encode(s: str) -> str:
245253
def is_healthy(host) -> bool:
246254
cmd = host.run("pg_isready -U postgres")
247255
if cmd.failed is True:
256+
logger.warn("pg not ready")
248257
return False
249258

250-
cmd = host.run(f"curl http://localhost:8085/health -H 'apikey: {supabase_admin_key}'")
259+
cmd = host.run(f"curl -sf -k https://localhost:8085/health -H 'apikey: {supabase_admin_key}'")
251260
if cmd.failed is True:
261+
logger.warn("adminapi not ready")
252262
return False
253263

254-
cmd = host.run("curl http://localhost:3001/ready")
264+
cmd = host.run("curl -sf http://localhost:3001/ready")
255265
if cmd.failed is True:
266+
logger.warn("postgrest not ready")
256267
return False
257268

258-
cmd = host.run("curl http://localhost:8081/health")
269+
cmd = host.run("curl -sf http://localhost:8081/health")
259270
if cmd.failed is True:
271+
logger.warn("gotrue not ready")
260272
return False
261273

262274
cmd = host.run("sudo kong health")
263275
if cmd.failed is True:
276+
logger.warn("kong not ready")
264277
return False
265278

266279
cmd = host.run("printf \\\\0 > '/dev/tcp/localhost/6543'")
267280
if cmd.failed is True:
281+
logger.warn("pgbouncer not ready")
268282
return False
269283

270284
cmd = host.run("sudo fail2ban-client status")
271285
if cmd.failed is True:
286+
logger.warn("fail2ban not ready")
272287
return False
273288

274289
return True

0 commit comments

Comments
 (0)