2019-03-12 08:46:27 +03:00
|
|
|
import pytest
|
|
|
|
import time
|
2022-07-05 21:00:08 +03:00
|
|
|
import json
|
2019-03-12 08:46:27 +03:00
|
|
|
import jsondiff
|
2019-11-29 08:14:26 +03:00
|
|
|
from context import PytestConf
|
2022-01-17 10:39:59 +03:00
|
|
|
from ruamel.yaml import YAML
|
|
|
|
|
|
|
|
yaml=YAML(typ='safe', pure=True)
|
2019-03-12 08:46:27 +03:00
|
|
|
|
|
|
|
|
2019-11-29 08:14:26 +03:00
|
|
|
if not PytestConf.config.getoption("--test-hge-scale-url"):
|
2019-03-12 08:46:27 +03:00
|
|
|
pytest.skip("--test-hge-scale-url flag is missing, skipping tests", allow_module_level=True)
|
|
|
|
|
|
|
|
|
2022-02-08 19:53:30 +03:00
|
|
|
class TestHorizontalScaleBasic():
|
2019-03-12 08:46:27 +03:00
|
|
|
servers = {}
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True, scope='class')
|
|
|
|
def transact(self, hge_ctx):
|
|
|
|
self.servers['1'] = hge_ctx.hge_url
|
|
|
|
self.servers['2'] = hge_ctx.hge_scale_url
|
|
|
|
yield
|
|
|
|
# teardown
|
2022-07-05 21:00:08 +03:00
|
|
|
hge_ctx.v1q_f(self.dir() + '/teardown.yaml')
|
2019-04-08 10:22:38 +03:00
|
|
|
|
2019-03-12 08:46:27 +03:00
|
|
|
def test_horizontal_scale_basic(self, hge_ctx):
|
|
|
|
with open(self.dir() + "/steps.yaml") as c:
|
2022-01-17 10:39:59 +03:00
|
|
|
conf = yaml.load(c)
|
2019-04-08 10:22:38 +03:00
|
|
|
|
2019-11-29 08:14:26 +03:00
|
|
|
assert isinstance(conf, list) == True, 'Not a list'
|
2019-03-12 08:46:27 +03:00
|
|
|
for _, step in enumerate(conf):
|
|
|
|
# execute operation
|
|
|
|
response = hge_ctx.http.post(
|
|
|
|
self.servers[step['operation']['server']] + "/v1/query",
|
|
|
|
json=step['operation']['query']
|
|
|
|
)
|
|
|
|
resp = response.json()
|
2022-07-05 21:00:08 +03:00
|
|
|
assert \
|
|
|
|
response.status_code == 200, \
|
|
|
|
f'Expected {response.status_code} to be 200. Response:\n{json.dumps(resp, indent=2)}'
|
2019-03-12 08:46:27 +03:00
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
# wait for 20 sec
|
|
|
|
time.sleep(20)
|
2019-03-12 08:46:27 +03:00
|
|
|
# validate data
|
|
|
|
response = hge_ctx.http.post(
|
|
|
|
self.servers[step['validate']['server']] + "/v1alpha1/graphql",
|
|
|
|
json=step['validate']['query']
|
|
|
|
)
|
|
|
|
resp = response.json()
|
2022-07-05 21:00:08 +03:00
|
|
|
assert \
|
|
|
|
response.status_code == 200, \
|
|
|
|
f'Expected {response.status_code} to be 200. Response:\n{json.dumps(resp, indent=2)}'
|
2019-03-12 08:46:27 +03:00
|
|
|
|
|
|
|
if 'response' in step['validate']:
|
2019-09-04 18:02:35 +03:00
|
|
|
assert resp == step['validate']['response'], yaml.dump({
|
2019-03-12 08:46:27 +03:00
|
|
|
'response': resp,
|
|
|
|
'expected': step['validate']['response'],
|
|
|
|
'diff': jsondiff.diff(step['validate']['response'], resp)
|
|
|
|
})
|
2019-04-08 10:22:38 +03:00
|
|
|
|
2019-03-12 08:46:27 +03:00
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return 'queries/horizontal_scale/basic'
|