Skip to content

Fix problem with tests failing sometimes #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2020

Conversation

t-persson
Copy link
Collaborator

Applicable Issues

None

Description of the Change

Added a connectivity waiter for the webserver to make sure it is ready for the test cases to use.

Alternate Designs

Unknown

Benefits

Tests won't fail intermittently

Possible Drawbacks

Possible that the tests will take a lot longer to run

Sign-off

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

Signed-off-by: Tobias Persson tobias.persson@axis.com

Added a connectivity waiter for the webserver to make
sure it is ready for the test cases to use.
@t-persson t-persson requested a review from a team as a code owner October 15, 2020 13:26
@t-persson t-persson requested review from fredjn and magnusbaeck and removed request for a team October 15, 2020 13:26
Copy link
Member

@fredjn fredjn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Comment on lines +50 to +67
def wait_for_webserver_connection():
"""Wait for the webserver to respond to HTTP requests."""
LOGGER.info("Testing for webserver connectivity.")
query_handler = GraphQLQueryHandler("http://127.0.0.1:12345/graphql")
timeout = time.time() + 30
while time.time() < timeout:
try:
query_handler.execute("{nothing}")
LOGGER.info("Up and running")
return
except HTTPError: # BadRequest means the webserver came up.
LOGGER.info("Up and running")
return
except Exception as exception: # pylint: disable=broad-except
LOGGER.error("%r", exception)
LOGGER.warning("Connection could not be established. Trying again in 1s..")
time.sleep(1)
raise TimeoutError("Timeout waiting for the webserver to start.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the retry package instead?

@retry.retry(exceptions=Exception, tries=30, delay=1, logger=LOGGER)
def wait_for_webserver_connection():
    query_handler = GraphQLQueryHandler("http://127.0.0.1:12345/graphql")
    try:
        query_handler.execute("{nothing}")
    except HTTPError as err:
        if err.response.status_code != 400:
            raise

It won't raise TimeoutError if the startup fails though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is the only place in the entire code-base where we do this kind of retry, I would say that the additional "overhead" of installing the retry package feels unnecessary.

If we were to add more retries, then definitely.

@t-persson t-persson merged commit 7be6b21 into eiffel-community:master Oct 16, 2020
@t-persson t-persson deleted the fix_tests branch October 16, 2020 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants