Skip to content
Snippets Groups Projects
Commit 48454890 authored by John Gerlock's avatar John Gerlock
Browse files

Fixes #66, fixes #69, fixes #70

parent 3c5d5211
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,7 @@ init: clean ## install project requrements into .venv
fi
pipenv run pre-commit install
Pipfile.lock:
Pipfile.lock: Pipfile
$(shell docker run $(PROJECT_DOCKER_TAG) /bin/bash -c 'pipenv lock && cat Pipfile.lock' > $@)
.PHONY: clean
......@@ -59,9 +59,9 @@ run-local: ## run the python app without docker
test: ## run all tests
pipenv run pytest
.PHONY: test-with-docker
.PHONY: build test-with-docker
test-with-docker: ## run tests that depend on docker
pipenv run pytest -m'docker'
pipenv run pytest --rundocker --jussiurl http://localhost:8080
.PHONY: lint
lint: ## lint python files
......@@ -100,29 +100,26 @@ pre-commit-all: ## run pre-commit against all files
prepare: test fmt fix-imports lint pre-commit-all ## test fmt fix-imports lint and pre-commit
.PHONY: prepare-and-build
prepare-and-build: prepare build Pipfile.lock ## run all tests, formatting and pre-commit checks, then build docker image
prepare-and-build: prepare Pipfile.lock test-with-docker ## run all tests, formatting and pre-commit checks, then build docker image
.PHONY: mypy
mypy: ## run mypy type checking on python files
pipenv run mypy --ignore-missing-imports --python-version $(PYTHON_VERSION) $(PROJECT_NAME)
.PHONY: curl-8080
curl-8080:
curl http://localhost:8080/
curl http://localhost:8080/health
curl http://localhost:8080/.well-known/healthcheck.json
curl -d '{"id":1,"jsonrpc":"2.0","method":"get_block","params":[1000]}' \
-H'Content-Type:application/json' \
localhost:8080
.PHONY: curl-9000
curl-9000:
curl http://localhost:9000/
curl http://localhost:9000/health
curl http://localhost:9000/.well-known/healthcheck.json
curl -d '{"id":1,"jsonrpc":"2.0","method":"get_block","params":[1000]}' \
-H'Content-Type:application/json' \
localhost:9000
.PHONY: 8080
8080:
http :8080/
http :8080/health
http :8080/.well-known/healthcheck.json
http --json id=1 jsonrpc="2.0" method=get_block params:='[1000]' :8080/
.PHONY: 9000
9000:
http :9000/
http :9000/health
http :9000/.well-known/healthcheck.json
http --json id:=1 jsonrpc=2.0 method=get_block params:='[1000]' :9000/
.PHONY: test-local-steemd-calls
......
......@@ -228,8 +228,8 @@ class Pool(asyncio.AbstractServer):
while self._free:
conn = self._free.popleft()
logger.debug(f'closing free connection {conn}')
yield from conn.close_connection(force=True)
conn.worker_task.cancel()
yield from conn.close_connection(after_handshake=False)
conn.transfer_data_task.cancel()
with (yield from self._cond):
while self.size > self.freesize:
......
......@@ -34,10 +34,8 @@ def pytest_collection_modifyitems(config, items):
for item in items:
if 'route' in item.nodeid:
item.add_marker(pytest.mark.test_app)
if not config.getoption("--rundocker") and not config.getoption(
"--jussiurl"):
skip_live = pytest.mark.skip(
reason="need --rundocker or --jussiurl option to run")
if not config.getoption("--rundocker") and not config.getoption("--jussiurl"):
skip_live = pytest.mark.skip(reason="need --rundocker or --jussiurl option to run")
for item in items:
if "live" in item.keywords:
item.add_marker(skip_live)
......@@ -46,6 +44,7 @@ def pytest_collection_modifyitems(config, items):
@pytest.fixture(scope='function')
def jussi_url(request):
if request.config.getoption("--rundocker"):
# request.config.getoption("--jussiurl")
return request.getfixturevalue('jussi_docker_service')
else:
return request.config.getoption("--jussiurl")
......@@ -732,6 +731,14 @@ for c in STEEMD_JSON_RPC_CALLS:
m for m in STEEMD_JSON_RPC_CALLS if m['method'] == method]
STEEMD_JSONRPC_CALL_PAIRS.append((c, new_method[0]))
LONG_REQUESTS = [
{
'id': 1,
'jsonrpc': '2.0',
'method': 'get_accounts',
'params': [["a-0", "a-00", "a-1", "a-100-great", "a-2", "a-3", "a-5", "a-7", "a-a", "a-a-7", "a-a-a", "a-a-a-a", "a-a-lifemix", "a-a-ron", "a-aka-assassin", "a-alice", "a-angel", "a-aron", "a-ayman", "a-b", "a-b-c-0", "a-big-sceret", "a-blockchain", "a-bold-user", "a-buz", "a-c", "a-c-s", "a-cakasaurus", "a-cat-named-joe", "a-chixywilson", "a-churchill", "a-condor", "a-diddy", "a-enoch", "a-eye", "a-f", "a-future", "a-guy-named-brad", "a-h", "a-harkness12", "a-hitler", "a-human", "a-jay", "a-jeffrey", "a-jimynguyen", "a-jns", "a-k11u", "a-kiran", "a-kopf", "a-kristin", "a-l-e-x", "a-league", "a-louis", "a-luigh", "a-ly-ba-ba-lou", "a-m-s", "a-m3001", "a-man", "a-neuron", "a-normal-life", "a-ok", "a-osorio", "a-payment-btc-a", "a-pile-of-steem", "a-priori", "a-random-person", "a-rod", "a-run", "a-s-h", "a-sakura83", "a-share", "a-sheeple-nomore", "a-sojourner", "a-spears", "a-tall-lion", "a-team", "a-train", "a-u", "a-val", "a-vm", "a-vytimy", "a-wadyanto", "a-xyli", "a-yo", "a-z", "a-zajonc", "a00", "a000346", "a001", "a0047a", "a007", "a007-steem", "a01", "a01.cshrem", "a0101201012", "a02.cshrem", "a0487987", "a0903l22", "a0de6qzchbut", "a0dh", "a10", "a10-c", "a100", "a1000eyes", "a10cwarhog", "a10inchcock", "a11", "a110", "a1148639279", "a114haeun", "a119315", "a11at", "a11stabilizer", "a11y", "a12345678", "a1270", "a12a", "a12inchcock", "a12kcm5518", "a12najafi", "a12oma1784", "a13inchcock", "a13x", "a13xz", "a13yus", "a1412", "a14inchcock", "a153048", "a154103040", "a1848art", "a186r", "a1933production", "a1962w", "a1a", "a1a1a11a", "a1an120", "a1b2c3d4", "a1beatznj", "a1choi", "a1dunn13", "a1exe1", "a1i-00ba0eb5", "a1i-01e13986", "a1i-03a7078f", "a1i-04a70788", "a1i-04ba0eb1", "a1i-05a70789", "a1i-06a7078a", "a1i-06ba0eb3", "a1i-06e13981", "a1i-07a7078b", "a1i-07ba0eb2", "a1i-07e13980", "a1i-0b6eb596", "a1i-0f6eb592", "a1i-106eb58d", "a1i-107e64e9", "a1i-10ba0ea5", "a1i-10e23a97", "a1i-111d3fc9", "a1i-11ba0ea4", "a1i-121d3fca", "a1i-137e64ea", "a1i-13e23a94", "a1i-16ba0ea3", "a1i-16e23a91", "a1i-172e8d9b", "a1i-176eb58a", "a1i-17ba0ea2", "a1i-17e23a90", "a1i-182f8c94", "a1i-188530ad", "a1i-19571a91", "a1i-19a70795", "a1i-19bb0eac", "a1i-1a8530af", "a1i-1ae18298", "a1i-1b2f8c97", "a1i-1b7e64e2", "a1i-1b8530ae", "a1i-1d7f65e4", "a1i-211c3ef9", "a1i-216ccfad", "a1i-221c3efa", "a1i-231c3efb", "a1i-286db6b5", "a1i-296db6b4", "a1i-29e182ab", "a1i-2a4fe79f", "a1i-2a6db6b7", "a1i-2b6db6b6", "a1i-2c511ca4", "a1i-2fe182ad", "a1i-34e182b6", "a1i-34e487b6", "a1i-35b112b9", "a1i-374fe782", "a1i-39982f8c", "a1i-412f8ccd", "a1i-42e281c0", "a1i-439522f6", "a1i-43c3a0c1", "a1i-458530f0", "a1i-45a33fcf", "a1i-483192d5", "a1i-4b1c3e93", "a1i-4b9a2ffe", "a1i-4c1c3e94", "a1i-4ccfacce", "a1i-4d1c3e95", "a1i-4dcfaccf", "a1i-4e3192d3", "a1i-53b112df", "a1i-596eb5c4", "a1i-5c6eb5c1", "a1i-5f6eb5c2", "a1i-608b22d5", "a1i-628b22d7", "a1i-668a23d3", "a1i-67e139e0", "a1i-699126dc", "a1i-69e487eb", "a1i-6a40e8df", "a1i-6d40e8d8", "a1i-6d920ee7", "a1i-6f01a2e3", "a1i-71b918ec", "a1i-7941e9cc", "a1i-7a8530cf", "a1i-7dbb0fc8", "a1i-7fbb0fca", "a1i-8042f635", "a1i-80ef8c02", "a1i-80f59602", "a1i-816db61c", "a1i-90a8081c", "a1i-91a8081d", "a1i-92a8081e", "a1i-93a8081f", "a1i-93e2c04b", "a1i-94a80818", "a1i-94e2c04c", "a1i-95a80819", "a1i-95e2c04d", "a1i-96e2c04e", "a1i-a7ec8f25", "a1i-a8bb0f1d", "a1i-a9bb0f1c", "a1i-ab1c3e73", "a1i-ac2e8d20", "a1i-ad2e8d21", "a1i-adbb0f18", "a1i-ae2e8d22", "a1i-aebb0f1b", "a1i-af2e8d23", "a1i-afbb0f1a", "a1i-b08c103a", "a1i-b18c103b", "a1i-b28c1038", "a1i-b78c103d", "a1i-bca70730", "a1i-bda70731", "a1i-bea70732", "a1i-bfa70733", "a1i-c2e23a45", "a1i-c3e23a44", "a1i-c631925b", "a1i-c7e23a40", "a1i-c973d045", "a1i-cc1c3e14", "a1i-cd1c3e15", "a1i-ce1c3e16", "a1i-d0930f5a", "a1i-d0b1125c", "a1i-d241e967", "a1i-d2843167", "a1i-d3843166", "a1i-d641e963", "a1i-dd843168", "a1i-de84316b", "a1i-df84316a", "a1i-e16cb77c", "a1i-e1a8086d", "a1i-e26cb77f", "a1i-e2b0136e", "a1i-e36cb77e", "a1i-e6b8197b", "a1i-ea96215f", "a1i-eb1d3f33", "a1i-ec1d3f34", "a1i-ed1d3f35", "a1i-ee1d3f36", "a1i-eea80862", "a1i-f4873241", "a1i-f57dc940", "a1i-f5852779", "a1i-f5873240", "a1i-f6873243", "a1i-f7873242", "a1i-fafa5876"]]
}
]
# pylint: disable=unused-variable,unused-argument,attribute-defined-outside-init
......@@ -964,3 +971,8 @@ def prod_url():
@pytest.fixture
def sanic_server(loop, app, test_server):
return loop.run_until_complete(test_server(app))
@pytest.fixture(params=LONG_REQUESTS)
def long_request(request):
yield request.param
......@@ -2,7 +2,6 @@ version: "3.3"
services:
jussi:
image: steemit/jussi
build: ..
ports:
- "8080:8080"
env_file:
......
......@@ -9,6 +9,21 @@ from jussi.middlewares.caching import cache_response
from jussi.middlewares.caching import get_response
req = {"id": 1, "jsonrpc": "2.0", "method": "get_block", "params": [1000]}
expected_steemd_response = {
"id": 1,
"result": {
"previous": "000003e7c4fd3221cf407efcf7c1730e2ca54b05",
"timestamp": "2016-03-24T16:55:30",
"witness": "initminer",
"transaction_merkle_root": "0000000000000000000000000000000000000000",
"extensions": [],
"witness_signature": "207f15578cac20ac0e8af1ebb8f463106b8849577e21cca9fc60da146d1d95df88072dedc6ffb7f7f44a9185bbf9bf8139a5b4285c9f423843720296a44d428856",
"transactions": [],
"block_id": "000003e8b922f4906a45af8e99d86b3511acd7a5",
"signing_key": "STM8GC13uCZbP44HzMLV6zPZGwVQ8Nt4Kji8PapsPiNq1BK153XTX",
"transaction_ids": []}}
expected_response = {
"id": 1,
"jsonrpc": "2.0",
......@@ -28,7 +43,7 @@ expected_response = {
@pytest.mark.live
async def test_cache_response_middleware(test_cli):
response = await test_cli.post('/', json=req)
assert await response.json() == expected_response
assert await response.json() == expected_steemd_response
response = await test_cli.post('/', json=req)
assert response.headers['x-jussi-cache-hit'] == 'steemd.database_api.get_block.params=[1000]'
......
......@@ -22,7 +22,7 @@ def test_response_results_type(
response.raise_for_status()
assert response.headers['Content-Type'] == 'application/json'
assert 'x-jussi-response-id' in response.headers
assert 'x-jussi-request-id' in response.headers
response_json = response.json()
assert response_json['id'] == request['id']
......@@ -40,8 +40,7 @@ def test_response_results_type(
assert expected_keys == result_keys
@pytest.mark.live
def test_repeated_response_equality(
def repeated_response_equality(
steemd_requests_and_responses, requests_session, jussi_url):
request, expected = steemd_requests_and_responses
expected_result = expected['result']
......@@ -57,3 +56,12 @@ def test_repeated_response_equality(
result_keys = set(jrpc_result.keys())
expected_keys = set(expected_result.keys())
assert expected_keys == result_keys
@pytest.mark.live
def test_long_request_live(long_request, requests_session, jussi_url,
steemd_jrpc_response_validator,):
response = requests_session.post(jussi_url, json=long_request)
response.raise_for_status()
response_json = response.json()
assert steemd_jrpc_response_validator(response_json) is None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment