Skip to content

Commit

Permalink
add wait in Operations tests to add robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
voidZXL committed Dec 24, 2024
1 parent 02bf493 commit 60549a0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/test_7_ops/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from utilmeta.ops.client import OperationsClient
from utilmeta.core.api.plugins.retry import RetryPlugin
# test import client here, client should not depend on ops models
import utilmeta
from utilmeta.ops import __spec_version__
import os
from pathlib import Path
import django
import time

BASE_DIR = Path(os.path.dirname(__file__))

Expand Down Expand Up @@ -52,17 +52,20 @@
max_retries=3, max_retries_timeout=15, retry_interval=1
)

OPS_WAIT = 1.0
# add wait to make sure that the operations data are all setup


class TestOperations:
if django.VERSION >= (4, 0):
def test_django_operations(self, django_wsgi_process):
time.sleep(OPS_WAIT)
with OperationsClient(
base_url='http://127.0.0.1:9091/ops',
plugins=[retry]
) as client:
info = client.get_info()
assert info.result.utilmeta == __spec_version__

openapi_resp = client.get_openapi()
assert openapi_resp.status == 200
assert openapi_resp.result.openapi
Expand Down Expand Up @@ -98,6 +101,7 @@ def test_django_operations(self, django_wsgi_process):
assert isinstance(data, dict) and data.get('result') == 3

def test_django_asgi_operations(self, django_asgi_process):
time.sleep(OPS_WAIT)
with OperationsClient(
base_url='http://127.0.0.1:9100/ops',
plugins=[retry]
Expand Down Expand Up @@ -132,6 +136,7 @@ def test_django_asgi_operations(self, django_asgi_process):
assert '2.6.0' <= inst.utilmeta_version

def test_fastapi_operations(self, fastapi_process):
time.sleep(OPS_WAIT)
with OperationsClient(base_url='http://127.0.0.1:9092/api/v1/ops', base_headers={
'cache-control': 'no-cache'
}, plugins=[retry]) as client:
Expand Down Expand Up @@ -168,6 +173,7 @@ def test_fastapi_operations(self, fastapi_process):
assert 'Not Found' in str(not_found.data)

def test_flask_operations(self, flask_process):
time.sleep(OPS_WAIT)
with OperationsClient(base_url='http://127.0.0.1:9093/ops', base_headers={
'cache-control': 'no-cache'
}, plugins=[retry]) as client:
Expand Down Expand Up @@ -201,6 +207,7 @@ def test_flask_operations(self, flask_process):
assert 'Hello' in str(hello.data)

def test_sanic_operations(self, sanic_process):
time.sleep(OPS_WAIT)
with OperationsClient(base_url='http://127.0.0.1:9094/ops', base_headers={
'cache-control': 'no-cache'
}, plugins=[retry]) as client:
Expand Down Expand Up @@ -235,6 +242,7 @@ def test_sanic_operations(self, sanic_process):
assert 'Hello' in str(hello.data)

def test_tornado_operations(self, tornado_process):
time.sleep(OPS_WAIT)
with OperationsClient(base_url='http://127.0.0.1:9095/v1/ops', plugins=[retry]) as client:
info = client.get_info()
assert info.result.utilmeta == __spec_version__
Expand All @@ -257,6 +265,7 @@ def test_tornado_operations(self, tornado_process):
assert '2.6.0' <= inst.utilmeta_version

def test_utilmeta_operations(self, utilmeta_process):
time.sleep(OPS_WAIT)
with OperationsClient(base_url='http://127.0.0.1:9090/api/ops', plugins=[retry]) as client:
info = client.get_info()
assert info.result.utilmeta == __spec_version__
Expand Down

0 comments on commit 60549a0

Please sign in to comment.