Skip to content

Adding helper functions that reduce code duplications in TAP tests #263

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

Open
wants to merge 3 commits into
base: TDE_REL_17_STABLE
Choose a base branch
from

Conversation

shahidullah79
Copy link
Collaborator

@shahidullah79 shahidullah79 commented Apr 25, 2025

I have added few helper functions that will reduce code duplication in TAP tests. like

  • create pg_tde extension and then adding provider and key.
  • Enable pg_tde in conf file
  • enable/disable WAL encryption and restart server.
  • Setting default access method to tde_heap
  • Check status of encrypted object using pg_tde_is_encrypted() function

Go through these functions if you think these will be useful then will merge it.

@codecov-commenter
Copy link

codecov-commenter commented Apr 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.30%. Comparing base (57ac8c8) to head (a693649).
Report is 6 commits behind head on TDE_REL_17_STABLE.

❌ Your project status has failed because the head coverage (78.30%) 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     #263      +/-   ##
=====================================================
+ Coverage              78.13%   78.30%   +0.17%     
=====================================================
  Files                     22       22              
  Lines                   2488     2485       -3     
  Branches                 393      392       -1     
=====================================================
+ Hits                    1944     1946       +2     
+ Misses                   466      462       -4     
+ Partials                  78       77       -1     
Components Coverage Δ
access 79.35% <ø> (+0.67%) ⬆️
catalog 86.14% <ø> (+0.07%) ⬆️
common 92.50% <ø> (ø)
encryption 71.90% <ø> (ø)
keyring 72.07% <ø> (ø)
src 53.79% <ø> (ø)
smgr 98.01% <ø> (ø)
transam ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AndersAstrand
Copy link
Collaborator

AndersAstrand commented Apr 25, 2025

I am generally opposed to these types of helpers in tests. For test code, it's very important that it's easy to read and understand, and less important that it's easy to write. DRY principles doesn't really apply to tests.

I don't think this is a direction that would make our TAP tests better.

That said, adding helpers for setting up common scaffolding could possibly be useful. But executing the test subject and asserting on it shouldn't be hidden behind indirection imho.

}

# Set up pg_tde extension and add a database key provider and set the database key
sub setup_pg_tde_db_environment
Copy link
Member

Choose a reason for hiding this comment

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

Here and the previous function: maybe _key or _keyring instead of _environment? E.g. setup_pg_tde_global_key and setup_pg_tde_db_key

# Set up pg_tde extension and add a database key provider and set the database key
sub setup_pg_tde_db_environment
{
my ($node, $key_name, $provider_name, $provider_path) = @_;
Copy link
Member

Choose a reason for hiding this comment

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

In most cases in tests nobody cares about the key and provider name, and path. So maybe have defaults like:

my $testname = basename($0);
$testname =~ s/\.[^.]+$//;

my $key_name = $key_name . '_db_key';  
my $provider_name = $testname . '_provider';
my $provider_path = '/tmp/' . $testname . '.per';

And then in most cases you call much more convenient setup_pg_tde_db_key($node)

Comment on lines +119 to +130
sub enable_pg_tde_in_conf
{
my ($node) = @_;
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_tde'");
}

# Set default table access method to tde_heap
sub set_default_table_am_tde_heap
{
my ($node) = @_;
$node->append_conf('postgresql.conf', "default_table_access_method = 'tde_heap'");
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about those two functions. I don't think anyone would memorize this func names, hence they would be copied from the existing tests anyway. But then it's not a bit difference which line is to copy (I mean $node->append_conf('postgresql.conf', "default_table_access_method = 'tde_heap'"); or set_default_table_am_tde_heap($node)). But append_conf( is more clear of what it does. However, I don't have super strong opinion about that.

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