Skip to content

Proof of concept: Ideas for cleaner TAP tests #249

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

Draft
wants to merge 5 commits into
base: TDE_REL_17_STABLE
Choose a base branch
from

Conversation

AndersAstrand
Copy link
Collaborator

@AndersAstrand AndersAstrand commented Apr 23, 2025

I applied some ideas on how to clean up our TAP tests to 001_basic.pl for your consideration. Any feedback is appreciated.

I tried to split it up into commits that explains why I did what I did.

Also, the rules used for pgperltidy are disgusting. This code could have been so much nicer with sane perltidy rules, who was the dumbass who suggested we should run that 😆 .

Some things tested in 001_basic.pl can easily be tested by pg_regress,
so let's remove them from the TAP test.

- Checking the extension version
- Verify that tde_heap tables can't be created without principal key set
- Select from table right after insert
- Dropping a tde_heap table
- Dropping the extension
Assume that everything that isn't the test subject works and don't
assert that it does. These things can easily be tested by pg_regress.

Also prefer q{} over '' for SQL strings as that will keep escaping to a
minimum and make it easier to read.
Instead of our home brewed assertion system we use regular Test::More
assertions as these will document what is being tested and give a
comprehensive error message if a test fail.

Also use the "standard" test scrip pre-amble from src/test/perl/README
Just because these are tests we don't have to make the SQL hard to read.
@codecov-commenter
Copy link

codecov-commenter commented Apr 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.13%. Comparing base (86a43fc) to head (7f475e9).
Report is 19 commits behind head on TDE_REL_17_STABLE.

❌ Your project status has failed because the head coverage (77.13%) is below the target coverage (90.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           TDE_REL_17_STABLE     #249      +/-   ##
=====================================================
+ Coverage              75.45%   77.13%   +1.68%     
=====================================================
  Files                     22       22              
  Lines                   2465     2489      +24     
  Branches                 388      394       +6     
=====================================================
+ Hits                    1860     1920      +60     
+ Misses                   532      490      -42     
- Partials                  73       79       +6     
Components Coverage Δ
access 78.13% <ø> (+5.68%) ⬆️
catalog 83.64% <ø> (-0.64%) ⬇️
common 92.50% <ø> (ø)
encryption 71.90% <ø> (ø)
keyring 72.07% <ø> (+2.20%) ⬆️
src 53.79% <ø> (+0.99%) ⬆️
smgr 98.01% <ø> (+1.08%) ⬆️
transam ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This is by no means the final wrapper we should use, but should hide a
peeve for Andreas so he can see the rest of this branch :D .
Copy link
Collaborator

@jeltz jeltz left a comment

Choose a reason for hiding this comment

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

I like the general idea but a bit worried about comaprison of blobs of text returned by psql with errors messages etc.

SELECT * FROM test_enc ORDER BY id ASC
}
),
"1|foobar\n2|barfoo",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Like I wrote directly to Anders I worry that this kind of comparison will result in a pretty hard to read output and that we need to split the output but in general I think this is moving us in the right direction. Need to test this locally a bit tomorrow and see if we are fine with it as-is or if we need to write the better helper already.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer the "output comparison" style tests, but maybe that's because I'm used to how mysql works - there the test framework is a combination of the SQL tests and the tap tests, basically the SQL tests have way more features.

Here the only reason why we have to use tap at all is because the sql tests are missing some features, mainly proper server restarts.

Copy link
Collaborator Author

@AndersAstrand AndersAstrand Apr 23, 2025

Choose a reason for hiding this comment

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

I think that style of test just leads to higher maintenance cost without giving any value. I would probably prefer if we mainly did TAP tests, so I understand I'm the odd man out.

I just don't see the appeal of having to update the expectations for every single test if you change the output of a function, even if that function is only run as part of setting up scaffolding for every test except the one that actually tests that function.

I think there only need to be one test that asserts that CREATE EXSTENSION pg_tde works for example, and the rest can just assume that it works and focus on asserting whatever their test subject is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here are two examples of the high maintenance cost of the regression tests I've fixed recently:

Test didn't actually test anything, it only setup scaffolding: ce63840
Test asserted the complete opposite of what it claimed to test: 1390dd0

These issues are more or less unavoidable in regression tests, but with proper TAP tests we can at least avoid them there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, that is annoying, mysql mtr has special commands for that, disable_query_log, enable_query_log and disable_result_log, enable_result_log - statements written between those, or their results, won't get written to the output file.

SELECT * FROM test_enc ORDER BY id ASC
}
),
"1|foobar\n2|barfoo",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer the "output comparison" style tests, but maybe that's because I'm used to how mysql works - there the test framework is a combination of the SQL tests and the tap tests, basically the SQL tests have way more features.

Here the only reason why we have to use tap at all is because the sql tests are missing some features, mainly proper server restarts.

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.

4 participants