cosmicpython / code

Example application code for the python architecture book
Other
2.07k stars 922 forks source link

Error in the tests #51

Closed nomhoi closed 2 years ago

nomhoi commented 2 years ago
$ make test
docker-compose up -d
Creating network "code_default" with the default driver
Creating code_redis_1    ... done
Creating code_mailhog_1  ... done
Creating code_postgres_1 ... done
Creating code_redis_pubsub_1 ... done
Creating code_api_1          ... done
docker-compose run --rm --no-deps --entrypoint=pytest api /tests/unit /tests/integration /tests/e2e
Creating code_api_run ... done
================================================= test session starts ==================================================
platform linux -- Python 3.9.12, pytest-7.1.1, pluggy-1.0.0
rootdir: /tests, configfile: pytest.ini
plugins: icdiff-0.5
collected 31 items                                                                                                     

../tests/unit/test_batches.py ......                                                                             [ 19%]
../tests/unit/test_handlers.py ........                                                                          [ 45%]
../tests/unit/test_product.py ......                                                                             [ 64%]
../tests/integration/test_email.py .                                                                             [ 67%]
../tests/integration/test_repository.py .                                                                        [ 70%]
../tests/integration/test_uow.py ....                                                                            [ 83%]
../tests/integration/test_views.py ..                                                                            [ 90%]
../tests/e2e/test_api.py F.                                                                                      [ 96%]
../tests/e2e/test_external_events.py F                                                                           [100%]

======================================================= FAILURES =======================================================
__________________________________ test_happy_path_returns_202_and_batch_is_allocated __________________________________
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:703: in urlopen
    httplib_response = self._make_request(
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:449: in _make_request
    six.raise_from(e, None)
<string>:3: in raise_from
    ???
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:444: in _make_request
    httplib_response = conn.getresponse()
/usr/local/lib/python3.9/http/client.py:1377: in getresponse
    response.begin()
/usr/local/lib/python3.9/http/client.py:320: in begin
    version, status, reason = self._read_status()
/usr/local/lib/python3.9/http/client.py:289: in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
E   http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:
/usr/local/lib/python3.9/site-packages/requests/adapters.py:440: in send
    resp = conn.urlopen(
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:785: in urlopen
    retries = retries.increment(
/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py:550: in increment
    raise six.reraise(type(error), error, _stacktrace)
/usr/local/lib/python3.9/site-packages/urllib3/packages/six.py:769: in reraise
    raise value.with_traceback(tb)
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:703: in urlopen
    httplib_response = self._make_request(
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:449: in _make_request
    six.raise_from(e, None)
<string>:3: in raise_from
    ???
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:444: in _make_request
    httplib_response = conn.getresponse()
/usr/local/lib/python3.9/http/client.py:1377: in getresponse
    response.begin()
/usr/local/lib/python3.9/http/client.py:320: in begin
    version, status, reason = self._read_status()
/usr/local/lib/python3.9/http/client.py:289: in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
E   urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:
/tests/e2e/test_api.py:15: in test_happy_path_returns_202_and_batch_is_allocated
    api_client.post_to_add_batch(earlybatch, sku, 100, "2011-01-01")
/tests/e2e/api_client.py:7: in post_to_add_batch
    r = requests.post(
/usr/local/lib/python3.9/site-packages/requests/api.py:117: in post
    return request('post', url, data=data, json=json, **kwargs)
/usr/local/lib/python3.9/site-packages/requests/api.py:61: in request
    return session.request(method=method, url=url, **kwargs)
/usr/local/lib/python3.9/site-packages/requests/sessions.py:529: in request
    resp = self.send(prep, **send_kwargs)
/usr/local/lib/python3.9/site-packages/requests/sessions.py:645: in send
    r = adapter.send(request, **kwargs)
/usr/local/lib/python3.9/site-packages/requests/adapters.py:501: in send
    raise ConnectionError(err, request=request)
E   requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
__________________________________ test_change_batch_quantity_leading_to_reallocation __________________________________
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:703: in urlopen
    httplib_response = self._make_request(
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:449: in _make_request
    six.raise_from(e, None)
<string>:3: in raise_from
    ???
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:444: in _make_request
    httplib_response = conn.getresponse()
/usr/local/lib/python3.9/http/client.py:1377: in getresponse
    response.begin()
/usr/local/lib/python3.9/http/client.py:320: in begin
    version, status, reason = self._read_status()
/usr/local/lib/python3.9/http/client.py:289: in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
E   http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:
/usr/local/lib/python3.9/site-packages/requests/adapters.py:440: in send
    resp = conn.urlopen(
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:785: in urlopen
    retries = retries.increment(
/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py:550: in increment
    raise six.reraise(type(error), error, _stacktrace)
/usr/local/lib/python3.9/site-packages/urllib3/packages/six.py:769: in reraise
    raise value.with_traceback(tb)
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:703: in urlopen
    httplib_response = self._make_request(
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:449: in _make_request
    six.raise_from(e, None)
<string>:3: in raise_from
    ???
/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:444: in _make_request
    httplib_response = conn.getresponse()
/usr/local/lib/python3.9/http/client.py:1377: in getresponse
    response.begin()
/usr/local/lib/python3.9/http/client.py:320: in begin
    version, status, reason = self._read_status()
/usr/local/lib/python3.9/http/client.py:289: in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
E   urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:
/tests/e2e/test_external_events.py:17: in test_change_batch_quantity_leading_to_reallocation
    r = api_client.post_to_allocate(orderid, sku, 10)
/tests/e2e/api_client.py:15: in post_to_allocate
    r = requests.post(
/usr/local/lib/python3.9/site-packages/requests/api.py:117: in post
    return request('post', url, data=data, json=json, **kwargs)
/usr/local/lib/python3.9/site-packages/requests/api.py:61: in request
    return session.request(method=method, url=url, **kwargs)
/usr/local/lib/python3.9/site-packages/requests/sessions.py:529: in request
    resp = self.send(prep, **send_kwargs)
/usr/local/lib/python3.9/site-packages/requests/sessions.py:645: in send
    r = adapter.send(request, **kwargs)
/usr/local/lib/python3.9/site-packages/requests/adapters.py:501: in send
    raise ConnectionError(err, request=request)
E   requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
------------------------------------------------ Captured stdout setup -------------------------------------------------
skipping restart, assumes running in container
=============================================== short test summary info ================================================
FAILED ../tests/e2e/test_api.py::test_happy_path_returns_202_and_batch_is_allocated - requests.exceptions.ConnectionE...
FAILED ../tests/e2e/test_external_events.py::test_change_batch_quantity_leading_to_reallocation - requests.exceptions...
============================================= 2 failed, 29 passed in 8.65s =============================================
ERROR: 1
make: *** [Makefile:17: test] Error 1
hjwp commented 2 years ago

that could happen if the tests run too soon after the containers come up, before the webapp container is ready, maybe? is it consistent, or does it go away if you re-run a second time?

nomhoi commented 2 years ago

Thank you! I have run tests again, all tests have been passed.

jdholstein commented 1 year ago

This problem seems to still be happening for me. It is a non-deterministic bug unfortunately