insights-core icon indicating copy to clipboard operation
insights-core copied to clipboard

Remove double exception print

Open Glutexo opened this issue 1 year ago • 6 comments

All Pull Requests:

Check all that apply:

  • [x] Have you followed the guidelines in our Contributing document, including the instructions about commit messages?
  • [x] No Sensitive Data in this change?
  • [x] Is this PR to correct an issue?
  • [ ] Is this PR an enhancement?

Complete Description of Additions/Changes:

In case of a connection error, an exception description was printed on the standard output twice: once by the outer test_connection method and once by the inner _(legacy_)test_urls method. The legacy version tries multiple URLs and prints the exception description on each failure. Thus, removed the outer print that only duplicates the last caught exception.

Card IDs:

Glutexo avatar Oct 11 '24 13:10 Glutexo

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 77.18%. Comparing base (f284dd0) to head (5e34f37).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4246      +/-   ##
==========================================
+ Coverage   77.11%   77.18%   +0.07%     
==========================================
  Files         761      761              
  Lines       41473    41472       -1     
  Branches     8763     8763              
==========================================
+ Hits        31981    32010      +29     
+ Misses       8437     8406      -31     
- Partials     1055     1056       +1     
Flag Coverage Δ
unittests 77.17% <100.00%> (+0.07%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Oct 11 '24 13:10 codecov-commenter

This pull request contains changes requested by Matyáš. First, I extracted the changes from https://github.com/RedHatInsights/insights-core/pull/4191 that didn’t belong to that PR. Then, I only kept the requested changes, replacing an intermediary PR https://github.com/RedHatInsights/insights-core/pull/4237.

Both pull requests introduce changes to the now untested test connection mechanic and both deal with exception handling. Because of that, general unit tests for sub-method calls are included in both of them. After one PR will have been merged I will resolve the conflict in the other one.

As for the caplog fixture, that is not supported on Python ≤2.7, I’m aware that the suggestion was to mark the tests as skipped. The change to logger asserts was however trivial. Moreover, I already used those in the sister pull request https://github.com/RedHatInsights/insights-core/pull/4211. Such asserts are less semantic, but working. They need to be replaced after fixing the pipeline, but so do the skip marks.

Opening the pull request for review. @m-horky

Glutexo avatar Oct 11 '24 13:10 Glutexo

If https://github.com/RedHatInsights/insights-core/pull/4211 gets merged first, this pull request would bring a regression. The other PR extends the set of exceptions caught by the outer test_connection method, but this one removes the redundant exception print from the same method.

That means that after merging https://github.com/RedHatInsights/insights-core/pull/4211, exceptions will be properly printed for read timeouts too (currently they are not), but then after merging this PR, that print will get removed. As a result, the read timeouts will be caught and would not dump a traceback, but wouldn’t have a nice print.

To fix that, exception handling in the inner _(legacy_)test_urls methods needs to be extended too. Doing so, read timeouts would reach the proper inner print and the outer one won’t be necessary – which was the original intention of this PR. I will create a new pull request to unblock this one.

Glutexo avatar Oct 14 '24 08:10 Glutexo

To make things simpler, let‘s say this is blocked by https://github.com/RedHatInsights/insights-core/pull/4246 and is a blocker of https://github.com/RedHatInsights/insights-core/pull/4211. Merging https://github.com/RedHatInsights/insights-core/pull/4246 first will make further reviewing and merging easier and would significantly reduce the size of the test patch.

Glutexo avatar Oct 21 '24 12:10 Glutexo

There is also https://github.com/RedHatInsights/insights-core/pull/4254 in the family. It neither blocks anything nor is blocked by anything. It only shares some tests.

Glutexo avatar Oct 22 '24 08:10 Glutexo

https://github.com/RedHatInsights/insights-core/pull/4248 got merged. There are now conflicts. That’s because both PRs contained same tests. Will resolve and re-request a review.

Glutexo avatar Oct 22 '24 13:10 Glutexo

Rebased on the current master with https://github.com/RedHatInsights/insights-core/pull/4248 merged. Resolved conflicts in the tests:

  • Different exceptions are expected in test_connection and in _(legacy_)_test_urls.
  • Covered cases when Read Timeout caught by _(legacy_)_test_urls, but not test_connection.

This pull request only changes what is print on standard output. It is a part of what’s communicated to the user though. Because of that there are error log tests too. Prints and logging are always happen at the same time. They are on adjacent lines.

Glutexo avatar Oct 24 '24 09:10 Glutexo