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

testCacheManager: use cppunit exception tests #1811

Closed

Conversation

kinkie
Copy link
Contributor

@kinkie kinkie commented May 10, 2024

Do not hand-roll tests for exception-throwing code

rousskov
rousskov previously approved these changes May 10, 2024
@rousskov rousskov added the S-could-use-an-approval An approval may speed this PR merger (but is not required) label May 10, 2024
@kinkie kinkie added the M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels label May 10, 2024
@rousskov rousskov dismissed their stale review May 10, 2024 20:57

If possible, please apply similar changes to TestRandomUuid::testInvalidIds() and check main() in test_http_range.cc

@rousskov rousskov added S-waiting-for-author author action is expected (and usually required) and removed M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels S-could-use-an-approval An approval may speed this PR merger (but is not required) labels May 10, 2024
@kinkie
Copy link
Contributor Author

kinkie commented May 11, 2024

If possible, please apply similar changes to TestRandomUuid::testInvalidIds() and check main() in test_http_range.cc

Noted and added to backlog

@kinkie kinkie added M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels and removed S-waiting-for-author author action is expected (and usually required) labels May 11, 2024
@yadij yadij added S-could-use-an-approval An approval may speed this PR merger (but is not required) backport-to-v6 maintainer has approved these changes for v6 backporting labels May 14, 2024
@rousskov rousskov removed the S-could-use-an-approval An approval may speed this PR merger (but is not required) label May 15, 2024
@kinkie
Copy link
Contributor Author

kinkie commented May 18, 2024

If possible, please apply similar changes to TestRandomUuid::testInvalidIds() and check main() in test_http_range.cc

Noted and added to backlog

testRandomUuid done in PR #1814 , test_http_range is not applicable (it's simply reporting on unexpected exceptions, rather than enforcing that an exception is thrown)

Copy link
Contributor

@rousskov rousskov left a comment

Choose a reason for hiding this comment

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

test_http_range is not applicable (it's simply reporting on unexpected exceptions ...)

I disagree that test_http_range is not applicable. Its main() is not just reporting (that it is dying). It is exiting with an error code on any thrown exception:

    {
        ...
    } catch (const std::exception &e) {
        printf("Error: dying from an unhandled exception: %s\n", e.what());
        return EXIT_FAILURE;
    } catch (...) {
        printf("Error: dying from an unhandled exception.\n");
        return EXIT_FAILURE;
    }

Would not EXIT_FAILURE fail "make check"?

... rather than enforcing that an exception is thrown

AFAICT, test_http_range is enforcing (via EXIT_FAILURE) that an exception is not thrown. Just like CPPUNIT_ASSERT_NO_THROW() code added in this PR. Am I missing something?

@kinkie
Copy link
Contributor Author

kinkie commented May 20, 2024

test_http_range is not applicable (it's simply reporting on unexpected exceptions ...)

I disagree that test_http_range is not applicable. Its main() is not just reporting (that it is dying). It is exiting with an error code on any thrown exception:

    {
        ...
    } catch (const std::exception &e) {
        printf("Error: dying from an unhandled exception: %s\n", e.what());
        return EXIT_FAILURE;
    } catch (...) {
        printf("Error: dying from an unhandled exception.\n");
        return EXIT_FAILURE;
    }

Would not EXIT_FAILURE fail "make check"?

... rather than enforcing that an exception is thrown

AFAICT, test_http_range is enforcing (via EXIT_FAILURE) that an exception is not thrown. Just like CPPUNIT_ASSERT_NO_THROW() code added in this PR. Am I missing something?

Of course EXIT_FAILURE makes "make check" fail. So does not catching an exception.
The difference with other test cases is that here we are not validating that some code
raises an exception we would expect it to do; here we are saying "if an exception is thrown, fail the test".
Duh, every test does that implicitly.

Now, I didn't write this code, but I can see it was added in commit a0b3b22 with this message: "Range: header testing may thor exceptions which were not caught by the test binary. Could lead to difficulty debugging exception errors."

Which matches my interpretation of the code: "if the exception code follows the standard, print the message, it might be helpful".

In other words, I think that the best thing we can do here is to just remove the exception block and reduce this test to the default case: unhandled exceptions terminate() and signal failure to the test harness

Copy link
Contributor

@rousskov rousskov left a comment

Choose a reason for hiding this comment

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

The last response appears to be based on testInvalidUrl() changes. They are a red herring in this discussion because test_http_range code is not similar to testInvalidUrl(). test_http_range is similar to testValidUrl(). Hence, the last response does not help me understand why test_http_range case was declared inapplicable when this PR handles the same "make sure the exception is not thrown (and report it if it is)" case inside PR's CacheManagerInternals::testValidUrl().

I think that the best thing we can do here is to just remove the exception block and reduce this test to the default case: unhandled exceptions terminate() and signal failure to the test harness

AFAICT, that proposed approach goes against the inapplicable claim, CacheManagerInternals::testValidUrl() changes in this PR, and commit a0b3b22 concerns. Please do not interpret this paragraph as implying that the proposed approach is necessarily wrong.

Let's continue this discussion in new #1816 that is dedicated to test_http_range changes.

squid-anubis pushed a commit that referenced this pull request May 22, 2024
Do not hand-roll tests for exception-throwing code
@squid-anubis squid-anubis added the M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels label May 22, 2024
@squid-anubis squid-anubis added M-merged https://github.com/measurement-factory/anubis#pull-request-labels and removed M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels labels May 23, 2024
squidadm pushed a commit to squidadm/squid that referenced this pull request May 23, 2024
Do not hand-roll tests for exception-throwing code
@squidadm squidadm removed the backport-to-v6 maintainer has approved these changes for v6 backporting label May 23, 2024
@squidadm
Copy link
Collaborator

queued for backport to v6

yadij pushed a commit that referenced this pull request May 23, 2024
Do not hand-roll tests for exception-throwing code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M-merged https://github.com/measurement-factory/anubis#pull-request-labels
Projects
None yet
5 participants