2023-02-21 16:29:35 +00:00
|
|
|
from typing import AsyncContextManager
|
2023-03-09 23:36:45 +00:00
|
|
|
import logging
|
2023-02-21 16:29:35 +00:00
|
|
|
|
2023-05-24 02:39:38 +00:00
|
|
|
import pytest
|
2023-03-09 19:54:46 +00:00
|
|
|
from elasticsearch import (
|
|
|
|
Elasticsearch,
|
|
|
|
ConnectionError,
|
|
|
|
)
|
2023-05-24 02:39:38 +00:00
|
|
|
import trio
|
2023-03-09 23:36:45 +00:00
|
|
|
|
2023-03-09 01:20:11 +00:00
|
|
|
from piker.service import marketstore
|
2023-03-09 23:36:45 +00:00
|
|
|
from piker.service import elastic
|
2023-03-09 01:20:11 +00:00
|
|
|
|
2023-02-21 16:58:04 +00:00
|
|
|
|
2023-06-20 22:22:56 +00:00
|
|
|
@pytest.mark.skip
|
2023-02-24 18:11:15 +00:00
|
|
|
def test_marketstore_startup_and_version(
|
2023-02-22 16:28:07 +00:00
|
|
|
open_test_pikerd: AsyncContextManager,
|
2023-03-09 17:23:46 +00:00
|
|
|
loglevel: str,
|
2023-05-23 16:17:55 +00:00
|
|
|
root_conf: dict,
|
2023-02-22 16:28:07 +00:00
|
|
|
):
|
|
|
|
'''
|
2023-03-09 17:23:46 +00:00
|
|
|
Verify marketstore tsdb starts up and we can
|
|
|
|
connect with a client to do basic API reqs.
|
2023-02-22 16:28:07 +00:00
|
|
|
|
|
|
|
'''
|
|
|
|
async def main():
|
2023-05-23 16:17:55 +00:00
|
|
|
user_conf: dict = {
|
|
|
|
'grpc_listen_port': 5995 + 6,
|
|
|
|
'ws_listen_port': 5993 + 6,
|
|
|
|
}
|
|
|
|
|
|
|
|
dname: str # service name
|
|
|
|
config: dict # service name
|
2023-02-21 16:29:35 +00:00
|
|
|
|
2023-02-22 16:28:07 +00:00
|
|
|
async with (
|
|
|
|
open_test_pikerd(
|
2023-02-24 18:11:15 +00:00
|
|
|
loglevel=loglevel,
|
2023-05-23 16:17:55 +00:00
|
|
|
# tsdb=True
|
2023-03-09 17:23:46 +00:00
|
|
|
) as (
|
|
|
|
_, # host
|
|
|
|
_, # port
|
2023-06-20 22:22:56 +00:00
|
|
|
_,
|
2023-03-09 17:23:46 +00:00
|
|
|
services,
|
|
|
|
),
|
2023-05-23 16:17:55 +00:00
|
|
|
|
|
|
|
marketstore.start_ahab_daemon(
|
|
|
|
services,
|
|
|
|
user_conf,
|
|
|
|
loglevel=loglevel,
|
|
|
|
|
|
|
|
) as (dname, config)
|
2023-02-22 16:28:07 +00:00
|
|
|
):
|
2023-05-23 16:17:55 +00:00
|
|
|
# ensure user config was applied
|
|
|
|
for k, v in user_conf.items():
|
|
|
|
assert config[k] == v
|
|
|
|
|
|
|
|
# netconf: dict = root_conf['network']
|
|
|
|
# tsdbconf = netconf['tsdb']
|
|
|
|
|
2023-03-09 23:36:45 +00:00
|
|
|
# TODO: we should probably make this connection poll
|
|
|
|
# loop part of the `get_client()` implementation no?
|
|
|
|
|
2023-03-09 17:23:46 +00:00
|
|
|
# XXX NOTE: we use a retry-connect loop because it seems
|
|
|
|
# that if we connect *too fast* to a booting container
|
|
|
|
# instance (i.e. if mkts's IPC machinery isn't up early
|
|
|
|
# enough) the client will hang on req-resp submissions. So,
|
|
|
|
# instead we actually reconnect the client entirely in
|
|
|
|
# a loop until we get a response.
|
|
|
|
for _ in range(3):
|
2023-02-21 16:29:35 +00:00
|
|
|
|
2023-03-09 17:23:46 +00:00
|
|
|
# NOTE: default sockaddr is embedded within
|
2023-05-23 16:17:55 +00:00
|
|
|
async with marketstore.get_client(
|
|
|
|
host='localhost',
|
|
|
|
port=user_conf['grpc_listen_port'],
|
|
|
|
|
|
|
|
) as client:
|
|
|
|
print(f'Client is up @ {user_conf}!')
|
2023-03-09 17:23:46 +00:00
|
|
|
|
|
|
|
with trio.move_on_after(1) as cs:
|
|
|
|
syms = await client.list_symbols()
|
|
|
|
|
|
|
|
if cs.cancelled_caught:
|
|
|
|
continue
|
|
|
|
|
2023-03-09 19:54:46 +00:00
|
|
|
# should be an empty db (for now) since we spawn
|
|
|
|
# marketstore in a ephemeral test-harness dir.
|
2023-03-09 17:23:46 +00:00
|
|
|
assert not syms
|
|
|
|
print(f'RX syms resp: {syms}')
|
|
|
|
|
|
|
|
assert (
|
|
|
|
len(await client.server_version()) ==
|
|
|
|
len('3862e9973da36cfc6004b88172c08f09269aaf01')
|
|
|
|
)
|
|
|
|
print('VERSION CHECKED')
|
|
|
|
|
2023-05-23 16:17:55 +00:00
|
|
|
|
2023-03-09 17:23:46 +00:00
|
|
|
break # get out of retry-connect loop
|
2023-05-23 16:17:55 +00:00
|
|
|
else:
|
|
|
|
raise RuntimeError('Failed to connect to {conf}!')
|
|
|
|
|
|
|
|
# gracefully teardown docker-daemon-service
|
|
|
|
print(f'Cancelling docker service {dname}')
|
2023-02-21 16:29:35 +00:00
|
|
|
|
2023-02-22 16:28:07 +00:00
|
|
|
trio.run(main)
|
2023-02-21 16:29:35 +00:00
|
|
|
|
|
|
|
|
2023-05-24 02:39:38 +00:00
|
|
|
@pytest.mark.skip
|
2023-02-24 18:11:15 +00:00
|
|
|
def test_elasticsearch_startup_and_version(
|
2023-02-21 16:58:04 +00:00
|
|
|
open_test_pikerd: AsyncContextManager,
|
2023-03-09 17:23:46 +00:00
|
|
|
loglevel: str,
|
2023-03-09 23:36:45 +00:00
|
|
|
log: logging.Logger,
|
2023-02-21 16:29:35 +00:00
|
|
|
):
|
2023-02-21 16:58:04 +00:00
|
|
|
'''
|
2023-03-09 23:36:45 +00:00
|
|
|
Verify elasticsearch starts correctly (like at some point before
|
|
|
|
infinity time)..
|
2023-02-21 16:29:35 +00:00
|
|
|
|
2023-02-21 16:58:04 +00:00
|
|
|
'''
|
|
|
|
async def main():
|
2023-05-23 16:17:55 +00:00
|
|
|
port: int = 19200
|
|
|
|
user_conf: dict = {
|
|
|
|
'port': port,
|
|
|
|
}
|
|
|
|
|
|
|
|
dname: str # service name
|
|
|
|
config: dict # service name
|
2023-02-21 16:29:35 +00:00
|
|
|
|
2023-03-09 19:54:46 +00:00
|
|
|
async with (
|
|
|
|
open_test_pikerd(
|
|
|
|
loglevel=loglevel,
|
|
|
|
) as (
|
|
|
|
_, # host
|
|
|
|
_, # port
|
|
|
|
pikerd_portal,
|
|
|
|
services,
|
|
|
|
),
|
2023-05-23 16:17:55 +00:00
|
|
|
elastic.start_ahab_daemon(
|
|
|
|
services,
|
|
|
|
user_conf,
|
|
|
|
loglevel=loglevel,
|
|
|
|
|
|
|
|
) as (dname, config)
|
2023-03-09 19:54:46 +00:00
|
|
|
):
|
2023-03-09 23:36:45 +00:00
|
|
|
# TODO: much like the above connect loop for mkts, we should
|
|
|
|
# probably make this sync start part of the
|
|
|
|
# ``open_client()`` implementation?
|
|
|
|
for i in range(240):
|
|
|
|
with Elasticsearch(
|
|
|
|
hosts=[f'http://localhost:{port}']
|
|
|
|
) as es:
|
|
|
|
try:
|
|
|
|
|
|
|
|
resp = es.info()
|
|
|
|
assert (
|
|
|
|
resp['version']['number']
|
|
|
|
==
|
|
|
|
elastic._config['version']
|
|
|
|
)
|
|
|
|
print(
|
|
|
|
"OMG ELASTIX FINALLY CUKCING CONNECTED!>!>!\n"
|
|
|
|
f'resp: {resp}'
|
|
|
|
)
|
|
|
|
break
|
|
|
|
|
|
|
|
except ConnectionError:
|
|
|
|
log.exception(
|
|
|
|
f'RETRYING client connection for {i} time!'
|
|
|
|
)
|
|
|
|
await trio.sleep(1)
|
|
|
|
continue
|
2023-02-21 16:29:35 +00:00
|
|
|
|
2023-02-21 16:58:04 +00:00
|
|
|
trio.run(main)
|