Mercurial > libervia-backend
comparison tests/e2e/libervia-cli/test_libervia-cli.py @ 3769:a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
the caching is triggered by `li.blog.get`, but it is done in parallel without blocking the
command, thus there is a possibility that the data is not yet in cache when the following
test is done.
A loop with delay is done, to be sure that cache is filled before doing the assertion.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 13 May 2022 19:27:21 +0200 |
parents | 7e51cfc36d4e |
children | f2a5936f2496 |
comparison
equal
deleted
inserted
replaced
3768:b443821399a3 | 3769:a75874df92b8 |
---|---|
19 import os | 19 import os |
20 import shutil | 20 import shutil |
21 import pytest | 21 import pytest |
22 import sh | 22 import sh |
23 from sh import li | 23 from sh import li |
24 from time import sleep | |
24 from sat.tools.common import uri | 25 from sat.tools.common import uri |
25 | 26 |
26 | 27 |
27 if os.getenv("LIBERVIA_TEST_ENV_E2E") is None: | 28 if os.getenv("LIBERVIA_TEST_ENV_E2E") is None: |
28 pytest.skip( | 29 pytest.skip( |
166 "-t", "travel", "-t", "south pacific", | 167 "-t", "travel", "-t", "south pacific", |
167 _in="this is a blog post about Australia", | 168 _in="this is a blog post about Australia", |
168 title=au_txt, | 169 title=au_txt, |
169 syntax="markdown" | 170 syntax="markdown" |
170 ) | 171 ) |
171 # we get the blog to be activate the cache for it | 172 # we get the blog to activate the cache for it |
172 li.blog.get(max_items=1) | 173 li.blog.get(max_items=1) |
173 # FTS | 174 # FTS |
174 found = li_json.pubsub.cache.search(type="blog", fts='Slovakia OR "New Caledonia"') | 175 found = [] |
176 for __ in range(5): | |
177 found = li_json.pubsub.cache.search( | |
178 type="blog", fts='Slovakia OR "New Caledonia"' | |
179 ) | |
180 if found: | |
181 break | |
182 else: | |
183 # retrieving blog triggers the caching, but it's done in parallel | |
184 # thus we may have nothing in cache yet | |
185 sleep(0.5) | |
175 assert len(found) == 2 | 186 assert len(found) == 2 |
176 assert all(i["content"] in (sk_txt, nc_txt) for i in found) | 187 assert all(i["content"] in (sk_txt, nc_txt) for i in found) |
177 # search by field | 188 # search by field |
178 found = li_json.pubsub.cache.search("-F", "tags", "overlap", "travel", type="blog") | 189 found = li_json.pubsub.cache.search( |
190 "-F", "tags", "overlap", "travel", type="blog" | |
191 ) | |
179 assert len(found) == 4 | 192 assert len(found) == 4 |
180 found = li_json.pubsub.cache.search("-F", "tags", "overlap", "europe", type="blog") | 193 found = li_json.pubsub.cache.search( |
194 "-F", "tags", "overlap", "europe", type="blog" | |
195 ) | |
181 assert len(found) == 2 | 196 assert len(found) == 2 |
182 assert all(i["content"] in (sk_txt, fr_txt) for i in found) | 197 assert all(i["content"] in (sk_txt, fr_txt) for i in found) |
183 found = li_json.pubsub.cache.search("-F", "tags", "ioverlap", "SOUTH PACIFIC", type="blog") | 198 found = li_json.pubsub.cache.search( |
199 "-F", "tags", "ioverlap", "SOUTH PACIFIC", type="blog" | |
200 ) | |
184 assert all(i["content"] in (nc_txt, au_txt) for i in found) | 201 assert all(i["content"] in (nc_txt, au_txt) for i in found) |
185 | 202 |
186 | 203 |
187 class TestLiberviaCliBlog: | 204 class TestLiberviaCliBlog: |
188 MICROBLOG_NS = "urn:xmpp:microblog:0" | 205 MICROBLOG_NS = "urn:xmpp:microblog:0" |