Skip to content

Commit 8ceaa27

Browse files
committed
Add ES client polling to ensure eventual connectivity..
1 parent 97290fc commit 8ceaa27

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

tests/test_databases.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import trio
2-
31
from typing import AsyncContextManager
2+
import logging
43

4+
import trio
55
from elasticsearch import (
66
Elasticsearch,
77
ConnectionError,
88
)
9+
910
from piker.service import marketstore
11+
from piker.service import elastic
1012

1113

1214
def test_marketstore_startup_and_version(
@@ -31,6 +33,9 @@ async def main():
3133
services,
3234
),
3335
):
36+
# TODO: we should probably make this connection poll
37+
# loop part of the `get_client()` implementation no?
38+
3439
# XXX NOTE: we use a retry-connect loop because it seems
3540
# that if we connect *too fast* to a booting container
3641
# instance (i.e. if mkts's IPC machinery isn't up early
@@ -67,9 +72,11 @@ async def main():
6772
def test_elasticsearch_startup_and_version(
6873
open_test_pikerd: AsyncContextManager,
6974
loglevel: str,
75+
log: logging.Logger,
7076
):
7177
'''
72-
Verify elasticsearch starts correctly
78+
Verify elasticsearch starts correctly (like at some point before
79+
infinity time)..
7380
7481
'''
7582
async def main():
@@ -86,14 +93,32 @@ async def main():
8693
services,
8794
),
8895
):
89-
90-
for _ in range(240):
91-
try:
92-
es = Elasticsearch(hosts=[f'http://localhost:{port}'])
93-
except ConnectionError:
94-
await trio.sleep(1)
95-
continue
96-
97-
assert es.info()['version']['number'] == '7.17.4'
96+
# TODO: much like the above connect loop for mkts, we should
97+
# probably make this sync start part of the
98+
# ``open_client()`` implementation?
99+
for i in range(240):
100+
with Elasticsearch(
101+
hosts=[f'http://localhost:{port}']
102+
) as es:
103+
try:
104+
105+
resp = es.info()
106+
assert (
107+
resp['version']['number']
108+
==
109+
elastic._config['version']
110+
)
111+
print(
112+
"OMG ELASTIX FINALLY CUKCING CONNECTED!>!>!\n"
113+
f'resp: {resp}'
114+
)
115+
break
116+
117+
except ConnectionError:
118+
log.exception(
119+
f'RETRYING client connection for {i} time!'
120+
)
121+
await trio.sleep(1)
122+
continue
98123

99124
trio.run(main)

0 commit comments

Comments
 (0)