Add liveness check tests
This commit is contained in:
parent
6214f00b83
commit
13561378ab
@ -1,8 +0,0 @@
|
||||
import math
|
||||
|
||||
def num_serialize(n):
|
||||
if n == 0:
|
||||
return b'\x00'
|
||||
binlog = math.log2(n)
|
||||
bytelength = int(binlog / 8 + 1)
|
||||
return n.to_bytes(bytelength, 'big')
|
8
apps/cic-eth/tests/check/test_check_db.py
Normal file
8
apps/cic-eth/tests/check/test_check_db.py
Normal file
@ -0,0 +1,8 @@
|
||||
# local imports
|
||||
from cic_eth.check.db import health
|
||||
|
||||
def test_check_health(
|
||||
init_database,
|
||||
):
|
||||
|
||||
assert health()
|
20
apps/cic-eth/tests/check/test_check_gas.py
Normal file
20
apps/cic-eth/tests/check/test_check_gas.py
Normal file
@ -0,0 +1,20 @@
|
||||
# local imports
|
||||
from cic_eth.check.gas import health
|
||||
from cic_eth.db.models.role import AccountRole
|
||||
|
||||
def test_check_gas(
|
||||
config,
|
||||
init_database,
|
||||
default_chain_spec,
|
||||
eth_rpc,
|
||||
custodial_roles,
|
||||
whoever,
|
||||
):
|
||||
|
||||
config.add(str(default_chain_spec), 'CIC_CHAIN_SPEC', exists_ok=True)
|
||||
config.add(100, 'ETH_GAS_GIFTER_MINIMUM_BALANCE', exists_ok=True)
|
||||
assert health(config=config)
|
||||
|
||||
AccountRole.set('GAS_GIFTER', whoever, session=init_database)
|
||||
init_database.commit()
|
||||
assert not health(config=config)
|
16
apps/cic-eth/tests/check/test_check_redis.py
Normal file
16
apps/cic-eth/tests/check/test_check_redis.py
Normal file
@ -0,0 +1,16 @@
|
||||
# external imports
|
||||
import pytest
|
||||
|
||||
# local imports
|
||||
from cic_eth.check.redis import health
|
||||
|
||||
|
||||
def test_check_redis(
|
||||
config,
|
||||
have_redis,
|
||||
):
|
||||
|
||||
if have_redis != None:
|
||||
pytest.skip('cannot connect to redis, skipping test: {}'.format(have_redis))
|
||||
|
||||
assert health(unit='test', config=config)
|
13
apps/cic-eth/tests/check/test_check_signer.py
Normal file
13
apps/cic-eth/tests/check/test_check_signer.py
Normal file
@ -0,0 +1,13 @@
|
||||
# local imports
|
||||
from cic_eth.check.signer import health
|
||||
|
||||
|
||||
def test_check_signer(
|
||||
default_chain_spec,
|
||||
config,
|
||||
eth_signer,
|
||||
eth_rpc,
|
||||
):
|
||||
|
||||
config.add(str(default_chain_spec), 'CIC_CHAIN_SPEC', exists_ok=True)
|
||||
assert health(config=config)
|
@ -2,9 +2,11 @@
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
# external imports
|
||||
from eth_erc20 import ERC20
|
||||
import redis
|
||||
|
||||
# local imports
|
||||
from cic_eth.api import Api
|
||||
@ -55,3 +57,26 @@ def default_token(
|
||||
):
|
||||
BaseTask.default_token_symbol = foo_token_symbol
|
||||
BaseTask.default_token_address = foo_token
|
||||
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def have_redis(
|
||||
config,
|
||||
):
|
||||
|
||||
r = redis.Redis(
|
||||
host = config.get('REDIS_HOST'),
|
||||
port = config.get('REDIS_PORT'),
|
||||
db = config.get('REDIS_DB'),
|
||||
)
|
||||
k = str(uuid.uuid4())
|
||||
try:
|
||||
r.set(k, 'foo')
|
||||
r.delete(k)
|
||||
except redis.exceptions.ConnectionError as e:
|
||||
return e
|
||||
except TypeError as e:
|
||||
return e
|
||||
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user