|
| 1 | +import pytest |
| 2 | +import yaml |
| 3 | +import time |
| 4 | +import jsondiff |
| 5 | + |
| 6 | +from validate import json_ordered |
| 7 | + |
| 8 | + |
| 9 | +if not pytest.config.getoption("--test-hge-scale-url"): |
| 10 | + pytest.skip("--test-hge-scale-url flag is missing, skipping tests", allow_module_level=True) |
| 11 | + |
| 12 | + |
| 13 | +class TestHorizantalScaleBasic(): |
| 14 | + |
| 15 | + @pytest.fixture(autouse=True, scope='class') |
| 16 | + def transact(self, hge_ctx): |
| 17 | + self.teardown = {"type": "clear_metadata", "args": {}} |
| 18 | + yield |
| 19 | + # teardown |
| 20 | + st_code, resp = hge_ctx.v1q(self.teardown) |
| 21 | + assert st_code == 200, resp |
| 22 | + |
| 23 | + def test_horizontal_scale_basic(self, hge_ctx): |
| 24 | + with open(self.dir() + "/steps.yaml") as c: |
| 25 | + conf = yaml.load(c) |
| 26 | + |
| 27 | + assert isinstance(conf, list) == True, 'Not an list' |
| 28 | + for _, step in enumerate(conf): |
| 29 | + # execute operation on 1st server |
| 30 | + st_code, resp = hge_ctx.v1q(step['operation']) |
| 31 | + assert st_code == 200, resp |
| 32 | + |
| 33 | + # wait for x sec |
| 34 | + time.sleep(0.3) |
| 35 | + # validate data on 2nd server |
| 36 | + response = hge_ctx.http.post( |
| 37 | + hge_ctx.hge_scale_url + "/v1alpha1/graphql", |
| 38 | + json=step['validate']['query'] |
| 39 | + ) |
| 40 | + st_code = response.status_code |
| 41 | + resp = response.json() |
| 42 | + assert st_code == 200, resp |
| 43 | + |
| 44 | + if 'response' in step['validate']: |
| 45 | + assert json_ordered(resp) == json_ordered(step['validate']['response']), yaml.dump({ |
| 46 | + 'response': resp, |
| 47 | + 'expected': step['validate']['response'], |
| 48 | + 'diff': jsondiff.diff(step['validate']['response'], resp) |
| 49 | + }) |
| 50 | + |
| 51 | + @classmethod |
| 52 | + def dir(cls): |
| 53 | + return 'queries/horizontal_scale/basic' |
0 commit comments