1
- import trio
2
-
3
1
from typing import AsyncContextManager
2
+ import logging
4
3
4
+ import trio
5
5
from elasticsearch import (
6
6
Elasticsearch ,
7
7
ConnectionError ,
8
8
)
9
+
9
10
from piker .service import marketstore
11
+ from piker .service import elastic
10
12
11
13
12
14
def test_marketstore_startup_and_version (
@@ -31,6 +33,9 @@ async def main():
31
33
services ,
32
34
),
33
35
):
36
+ # TODO: we should probably make this connection poll
37
+ # loop part of the `get_client()` implementation no?
38
+
34
39
# XXX NOTE: we use a retry-connect loop because it seems
35
40
# that if we connect *too fast* to a booting container
36
41
# instance (i.e. if mkts's IPC machinery isn't up early
@@ -67,9 +72,11 @@ async def main():
67
72
def test_elasticsearch_startup_and_version (
68
73
open_test_pikerd : AsyncContextManager ,
69
74
loglevel : str ,
75
+ log : logging .Logger ,
70
76
):
71
77
'''
72
- Verify elasticsearch starts correctly
78
+ Verify elasticsearch starts correctly (like at some point before
79
+ infinity time)..
73
80
74
81
'''
75
82
async def main ():
@@ -86,14 +93,32 @@ async def main():
86
93
services ,
87
94
),
88
95
):
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
98
123
99
124
trio .run (main )
0 commit comments