0

Jussi docker 有 28 个步骤来构建 docker。我使用 steemit 开发人员指南运行 docker,但未在单元测试步骤 26 中通过。 Step 26/28 : RUN pipenv run pytest

我的环境如下操作系统:Ubuntu 18.04 Python:3.6.5 Docker:18.09.1

发生以下错误。

 ---> Running in 248a0ce440aa
============================= test session starts ==============================
platform linux -- Python 3.6.5, pytest-3.10.0, py-1.7.0, pluggy-0.8.1
rootdir: /app, inifile: pytest.ini
plugins: timeout-1.3.3, sanic-0.1.15, pylint-0.14.0, profiling-1.4.0, mock-1.10.0, docker-0.6.1, cov-2.6.0, console-scripts-0.1.7, asyncio-0.9.0
collected 3036 items

tests/test_account_transfer_route.py ......................              [  0%]
tests/test_appbase_compat_translation.py ............................... [  1%]
........................................................................ [  4%]
........................................................................ [  6%]
........................................................................ [  8%]
........................................................................ [ 11%]
........................................................................ [ 13%]
........................................................................ [ 15%]
.........................................                                [ 17%]
tests/test_cache_backends.py ..................                          [ 17%]
tests/test_cache_group.py .............................................. [ 19%]
........................................................................ [ 21%]
........................................................................ [ 24%]
........................................................................ [ 26%]
........................                                                 [ 27%]
tests/test_cache_key.py .........................................        [ 28%]
tests/test_cache_middleware.py sF                                        [ 28%]
tests/test_cache_utils.py .                                              [ 28%]
tests/test_empty.py .........                                            [ 29%]
tests/test_error_handling.py FFFFFFFF                                    [ 29%]
tests/test_healthcheck_routes.py sss                                     [ 29%]
tests/test_jsonrpc_request_and_responses.py FFFFFFFFFFFFFFFFFFFFFFFFFFFF [ 30%]
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF                 [ 32%]
tests/test_jussi_handlers.py FFFFFF                                      [ 32%]
tests/test_jussi_http_request.py ...........................             [ 33%]
tests/test_jussi_jsonrpc_request.py .................................... [ 34%]
........................................................................ [ 36%]
........................................................................ [ 39%]
........................................................................ [ 41%]
........................................................................ [ 43%]
........................................................................ [ 46%]
.........................................................                [ 48%]
tests/test_jussi_request_response_middleware.py FFFF....                 [ 48%]
tests/test_responses.py ssssssssssssssssssssssssssssssssssssssssssssssss [ 50%]
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 52%]
ssssssssssssssssssssssssssssssssssssssssss                               [ 53%]
tests/test_restricted_routes.py ssssssssssssssssssssssssssssssssssssssss [ 55%]
                                                                         [ 55%]
tests/test_ttls.py ......................                                [ 55%]
tests/test_upstream.py ................................................. [ 57%]
........................................................................ [ 59%]
..                                                                       [ 59%]
tests/test_upstreams.py .................                                [ 60%]
tests/test_urn.py ...................................................... [ 62%]
........................................................................ [ 64%]
........................................................................ [ 66%]
........................................................................ [ 69%]
........................................................................ [ 71%]
...........................                                              [ 72%]
tests/test_utils_namespaces.py ......................................... [ 73%]
.........................................................                [ 75%]
tests/test_validators.py ............................................... [ 77%]
........................................................................ [ 79%]
........................................................................ [ 82%]
........................................................................ [ 84%]
........................................................................ [ 86%]
........................................................................ [ 89%]
........................................................................ [ 91%]
........................................................................ [ 94%]
........................................................................ [ 96%]
........................................................................ [ 98%]
......................................                                   [100%]

=================================== FAILURES ===================================
____________________ test_mocked_cache_response_middleware _____________________

mocked_app_test_cli = (<CoroutineMock name='_get_new_connection()' id='140155905724144'>, <pytest_sanic.utils.TestClient object at 0x7f789735c4e0>)

    async def test_mocked_cache_response_middleware(mocked_app_test_cli):
        mocked_ws_conn, test_cli = mocked_app_test_cli
        mocked_ws_conn.recv.return_value = json.dumps(expected_response)
        response = await test_cli.post('/', json=req, headers={'x-jussi-request-id': '1'})
        assert 'x-jussi-cache-hit' not in response.headers
>       assert await response.json() == expected_response
E       AssertionError: assert {'error': {'c...onrpc': '2.0'} == {'id': 1, 'jso...9615022, ...}}
E         Omitting 1 identical items, use -vv to show
E         Differing items:
E         {'id': None} != {'id': 1}
E         Left contains more items:
E         {'error': {'code': -32603,
E                    'data': {'error_id': '16a3d5dc-efd6-49e7-bd22-30f5223a555f',
E                             'jussi_request_id': '1'},...
E         
E         ...Full output truncated (33 lines hidden), use '-vv' to show

tests/test_cache_middleware.py:96: AssertionError
---------------------------- Captured stdout setup -----------------------------
[2019-01-29 12:17:00 +0000] [6] [INFO] Goin' Fast @ http://127.0.0.1:43365
------------------------------ Captured log setup ------------------------------
app.py                    1120 INFO     Goin' Fast @ http://127.0.0.1:43365
----------------------------- Captured stdout call -----------------------------
[2019-01-29 12:17:00 +0000] - (sanic.access)[INFO][127.0.0.1:50746]: POST http://127.0.0.1:43365/  200 160
------------------------------ Captured log call -------------------------------
errors.py                  217 ERROR    {"exception":"InvalidUsage('Bad Request',)","message":"Internal Error","error_id":"16a3d5dc-efd6-49e7-bd22-30f5223a555f","jrpc_request_id":null,"jussi_request_id":"1","event":"Internal Error","logger":"jussi.errors","level":"error"}
server.py                  362 INFO
___________ test_middleware_error_handler[rpc_req0-error0-expected0] ___________

rpc_req = {'id': 1, 'jsonrpc': '2.0', 'method': 'yo.test_method', 'params': [1, 2, 3]}
error = Exception()
expected = {'error': {'code': -32603, 'data': {'error_id': '123', 'jussi_request_id': '123'}, 'message': 'Internal Error'}, 'id': 1, 'jsonrpc': '2.0'}

    @pytest.mark.test_app
    @pytest.mark.parametrize(
        'rpc_req,error,expected',
        [(jrpc_req, Exception(),
          minimal_error0),
         ({'jsonrpc': '2.0', 'method': 'yo.test_method'},
          Exception(),
          minimal_error_with_no_jsonrpc_id),
         (jrpc_req,
          JsonRpcError(http_request=fake_http_request),
          minimal_error2),
         (jrpc_req,
          JsonRpcError(
              http_request=fake_http_request, data=test_data),
          jrpc_error_with_data),
         (jrpc_req,
          JsonRpcError(
              http_request=fake_http_request, data=test_data,
              exception=Exception('test'),
              error_id='123'),
          jrpc_error_with_data),
         (jrpc_req,
          ParseError(http_request=fake_http_request),
          parse_error),
         (jrpc_req,
          InvalidRequest(http_request=fake_http_request),
          invalid_request_error),
         (jrpc_req,
          ServerError(http_request=fake_http_request),
          server_error)])
    def test_middleware_error_handler(rpc_req, error, expected):
        app = sanic.Sanic('testApp', request_class=HTTPRequest)

        # pylint: disable=unused-argument,unused-variable

        @app.post('/')
        def handler(request):
            return sanic.response.text('Hello')

        @app.middleware('request')
        @handle_middleware_exceptions
        async def error_middleware(request):
            raise error

        req, response = app.test_client.post('/', json=rpc_req, headers={'x-jussi-request-id': '123'})
>       assert response.headers['Content-Type'] == 'application/json'
E       AssertionError: assert 'text/plain; charset=utf-8' == 'application/json'
E         - text/plain; charset=utf-8
E         + application/json

tests/test_error_handling.py:179: AssertionError
----------------------------- Captured stdout call -----------------------------
[2019-01-29 12:17:00 +0000] [6] [INFO] Goin' Fast @ http://127.0.0.1:42101
[2019-01-29 12:17:00 +0000] [6] [INFO] http://127.0.0.1:42101/
[2019-01-29 12:17:00 +0000] [6] [ERROR] Exception occurred while handling uri: 'http://127.0.0.1:42101/'
Traceback (most recent call last):
  File "httptools/parser/parser.pyx", line 307, in httptools.parser.parser.cb_on_body
  File "/app/.venv/lib/python3.6/site-packages/sanic/server.py", line 310, in on_body
    self.request.body_push(body)
AttributeError: 'HTTPRequest' object has no attribute 'body_push'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/.venv/lib/python3.6/site-packages/sanic/server.py", line 251, in data_received
    self.parser.feed_data(data)
  File "httptools/parser/parser.pyx", line 193, in httptools.parser.parser.HttpParser.feed_data
httptools.parser.errors.HttpParserCallbackError: the on_body callback failed
[2019-01-29 12:17:00 +0000] - (sanic.access)[INFO][127.0.0.1:49448]: POST http://127.0.0.1:42101/  400 18
[2019-01-29 12:17:00 +0000] [6] [INFO] Starting worker [6]
[2019-01-29 12:17:00 +0000] [6] [INFO] Stopping worker [6]
[2019-01-29 12:17:00 +0000] [6] [INFO] Server Stopped

我的 DEV_config.json 如下。

{
  "limits": {
    "blacklist_accounts": [
      "non-steemit"
    ]
  },
  "upstreams": [
    {
      "name": "steemd",
      "translate_to_appbase": true,
      "urls": [
        [
          "steemd",
         "https://api.steemit.com"
        ]
      ],
      "ttls": [
        [
          "steemd",
          3
        ],
        [
          "steemd.login_api",
          -1
        ],
        [
          "steemd.network_broadcast_api",
          -1
        ],
        [
          "steemd.follow_api",
          10
        ],
        [
          "steemd.market_history_api",
          1
        ],
        [
          "steemd.database_api",
          3
        ],
        [
          "steemd.database_api.get_block",
          -2
        ],
        [
          "steemd.database_api.get_block_header",
          -2
        ],
        [
          "steemd.database_api.get_content",
          1
        ],
        [
          "steemd.database_api.get_state",
          1
        ],
        [
          "steemd.database_api.get_state.params=['/trending']",
          30
        ],
        [
          "steemd.database_api.get_state.params=['trending']",
          30
        ],
        [
          "steemd.database_api.get_state.params=['/hot']",
          30
        ],
        [
          "steemd.database_api.get_state.params=['/welcome']",
          30
        ],
        [
          "steemd.database_api.get_state.params=['/promoted']",
          30
        ],
        [
          "steemd.database_api.get_state.params=['/created']",
          10
        ],
        [
          "steemd.database_api.get_dynamic_global_properties",
          1
        ]
      ],
      "timeouts": [
        [
          "steemd",
          5
        ],
        [
          "steemd.network_broadcast_api",
          0
        ]
      ]
    },
    {
      "name": "appbase",
      "urls": [
        [
          "appbase",
          "https://api.steemit.com"
        ]
      ],
      "ttls": [
        [
          "appbase",
          -2
        ],
        [
          "appbase.block_api",
          -2
        ],
        [
          "appbase.database_api",
          1
        ]
      ],
      "timeouts": [
        [
          "appbase",
          3
        ],
        [
          "appbase.chain_api.push_block",
          0
        ],
        [
          "appbase.chain_api.push_transaction",
          0
        ],
        [
          "appbase.network_broadcast_api",
          0
        ],
        [
          "appbase.condenser_api.broadcast_block",
          0
        ],
        [
          "appbase.condenser_api.broadcast_transaction",
          0
        ],
        [
          "appbase.condenser_api.broadcast_transaction_synchronous",
          0
        ],
        [
          "appbase.condenser_api.get_ops_in_block.params=[2889020,false]",
          20
        ]
      ]
    }
  ]
}

它应该在 docker 构建中通过了 28 个步骤,但在单元测试中的 26 个步骤中没有成功

4

0 回答 0