Skip to content
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

Catch Timeout on test connection #4211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Glutexo
Copy link
Collaborator

@Glutexo Glutexo commented Sep 10, 2024

All Pull Requests:

Check all that apply:

  • Have you followed the guidelines in our Contributing document, including the instructions about commit messages?
  • Is this PR to correct an issue?
  • Is this PR an enhancement?

Complete Description of Additions/Changes:

The --test-connection command only used to catch ConnectionError, including ConnectionTimeout, but not other timeouts such as ReadTimeoutError. Re-used the existing REQUEST_FAILED_EXCEPTIONS list to process all timeouts in the same way.

There is an integration test pull request RedHatInsights/insights-client#244 for this fix.

Card IDs:

@Glutexo Glutexo added the client These issues represent work to be done by the "client" team. label Sep 10, 2024
@Glutexo Glutexo self-assigned this Sep 10, 2024
@Glutexo
Copy link
Collaborator Author

Glutexo commented Sep 10, 2024

This is a copy of #4191, which got closed when I deleted the remote branch because of the changes in the history of master.

To unblock CCT-506, I only kept the original fix of read timeout not being properly caught. I‘ll create a separate pull request for Matyáš’s discovery of duplicate exception print.

Not all cases were covered by the original set of unit tests, so I backported those I wrote dealing with the additional fix. Now, the happy path and an uncaught exception path is tested in addition to the request failure one.

This pull only deals with the reported bug of not dealing with timeouted requests. As such, it only tests that the exception is properly handled, printing concise details. Integration tests verifying the standard output as a whole is going to be part of the follow-up pull request.

The executive code is same as in the original pull request, the tests changed slightly and there is more of them. Requesting thus a fresh review from @m-horky. Any feedback to them here will help me with the new PR.

Copy link
Contributor

@m-horky m-horky left a comment

Choose a reason for hiding this comment

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

Overall, this PR looks good, I like the tests. I left a few notes there to consider.

insights/tests/client/connection/test_test_connection.py Outdated Show resolved Hide resolved
insights/tests/client/connection/test_test_connection.py Outdated Show resolved Hide resolved
insights/tests/client/connection/test_test_connection.py Outdated Show resolved Hide resolved
insights/tests/client/connection/test_test_connection.py Outdated Show resolved Hide resolved
@Glutexo
Copy link
Collaborator Author

Glutexo commented Sep 11, 2024

Also, there was a failing test because of non-ASCII characters in the comments. I replaced the nice quotes () with crude ones (').

@xiangce
Copy link
Contributor

xiangce commented Sep 12, 2024

FYI, we can ignore the following failed test:

>               assert hasattr(DefaultSpecs, spec_name)
E               AssertionError: assert False
E                +  where False = hasattr(DefaultSpecs, 'cloud_init_cfg_run')

The cloud_init_cfg_run was just removed from core collection and as well from the uploader.json, however, the uploader.json on CDN will be updated after next release. Let's ignore it this time. And the uploader.json will be deprecated soon, as well as this test.

@Glutexo
Copy link
Collaborator Author

Glutexo commented Sep 13, 2024

Addressed the review comments except one. See my inline comment.

@Glutexo
Copy link
Collaborator Author

Glutexo commented Sep 16, 2024

Resolved the last review comment and rebased on the current master. Ready for a review.

Copy link
Contributor

@m-horky m-horky left a comment

Choose a reason for hiding this comment

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

LGTM for the code itself.

CI for Python 2.6 is failing on

E       fixture 'caplog' not found
>       available fixtures: cache, capfd, capsys, cov, doctest_namespace, insights_connection, monkeypatch, pytestconfig, record_xml_property, recwarn, run_rule, tmpdir, tmpdir_factory

you'll need to find a replacement (or e.g. backport it and use in 2.6 only) for that.

@Glutexo
Copy link
Collaborator Author

Glutexo commented Sep 23, 2024

pytest-catchlog providing the caplog fixture became part of Pytest since version 3.3. On previous ones it needs to be installed separately. Added the dependency to setup.py for Python < 2.7. Let’s see what the pipeline says.

@Glutexo
Copy link
Collaborator Author

Glutexo commented Sep 23, 2024

Adding the dependency to setup.py is not enough. The dependencies are grabbed from another repository. I created a pull request there, but I am afraid it’s never going to be reviewed and merged as it’s a personal repo not owned by RedHatInsights.

I created a card suggesting migration of the requirements. Since jenkins-s2i-example is only used to provide the requirements file and its wheels, I think we can ditch the repo and move the files to this repository. We can even only adopt ci_requirements.txt and curl the wheels directly from PyPI, which is what pip does for other Python versions anyways.

For now, I can either mark the tests as skipped for Python 2.6, or update them to check for function calls to the logger. The latter is suboptimal, but can do for the time being until CCT-768 is resolved. What do you think?

@Glutexo Glutexo force-pushed the read-timeout-error branch 2 times, most recently from 2ebbd88 to ae62e4c Compare September 23, 2024 12:58
@m-horky
Copy link
Contributor

m-horky commented Sep 23, 2024

Aha, interesting. At this point I think those tests could be skipped, let's not spend more time on this than needed.

@Glutexo
Copy link
Collaborator Author

Glutexo commented Sep 23, 2024

The test_connection method only use a single very simple error logging call. It was trivial to replace it with a logger mock. It doesn’t even use logging string interpolation, so the asserts don’t need to incorrectly test the exact arguments rather than the resulting message.

The other tests of the _test_urls_ and _legacy_test_urls methods use more complex logger calls, but they are no longer part of this pull request.

@Glutexo
Copy link
Collaborator Author

Glutexo commented Sep 24, 2024

Fixed the remaining Flake8 complaint. Now, everything should be ok. Please take a look at the alternative asserts without caplog.

Copy link
Contributor

@m-horky m-horky left a comment

Choose a reason for hiding this comment

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

LGTM.

@Glutexo
Copy link
Collaborator Author

Glutexo commented Sep 24, 2024

Updated on the current master.

@xiangce
Copy link
Contributor

xiangce commented Sep 25, 2024

@m-horky, @Glutexo - So, we are okay to merge this PR, right? I received your comment tagging me from github's notfi, but didn't find it here in the PR (you deleted it?), so having this query.

@m-horky
Copy link
Contributor

m-horky commented Sep 25, 2024

@xiangce Hi, after I tagged you I realized it didn't go through QE preverification yet. Sorry for the noise.

@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.05%. Comparing base (416ed6b) to head (6588b75).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4211      +/-   ##
==========================================
+ Coverage   77.01%   77.05%   +0.04%     
==========================================
  Files         761      761              
  Lines       41471    41471              
  Branches     8763     8763              
==========================================
+ Hits        31937    31955      +18     
+ Misses       8481     8462      -19     
- Partials     1053     1054       +1     
Flag Coverage Δ
unittests 77.03% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Glutexo
Copy link
Collaborator Author

Glutexo commented Oct 14, 2024

If this gets merged before #4246, that pull request would bring a regression. See my comment there for more details.

@Glutexo Glutexo mentioned this pull request Oct 14, 2024
4 tasks
@m-horky
Copy link
Contributor

m-horky commented Oct 17, 2024

QE PASSED, this patch has been verified by @zpetrace. Blocked by #4246 now.

@Glutexo
Copy link
Collaborator Author

Glutexo commented Oct 21, 2024

Cool! So to make things simpler, let‘s say this is blocked by #4246 which itself is blocked by #4248. Merging those first will make merging easier and would significantly reduce the size of the test patch.

The --test-connection command only used to catch ConnectionError, including ConnectionTimeout, but not other timeouts such as ReadTimeoutError. Re-used the existing REQUEST_FAILED_EXCEPTIONS list to process all timeouts in the same way.

* Card ID: CCT-506

Signed-off-by: Štěpán Tomsa <[email protected]>
@Glutexo
Copy link
Collaborator Author

Glutexo commented Oct 22, 2024

There is also #4254 in the family. It neither blocks anything nor is blocked by anything. It only shares some tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client These issues represent work to be done by the "client" team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants