mirror of
https://github.com/percona/pg_stat_monitor.git
synced 2026-02-04 05:56:21 +00:00
PG-525: Update PGSM TAP Test Cases to accommodate PG15 changes.
Following changes are included in this commit: 1. Updated pgsm.pm to enable runtime loading of PG server version dependent perl modules that are needed for TAP testing. Similarly removed unneeded code from this file that is not needed right now. 2. Added generic settings and helper functions to pgsm.pm that could be used across different test cases. 3.Updated following TAP test case to use pgsm.pm based global settings and helper functions while making sure that we reduce the clutter and duplicate code in test cases, where possible. t/001_settings_default.pl t/002_settings_pgsm_track_planning.pl t/003_settings_pgms_extract_comments.pl t/004_settings_pgsm_track.pl t/005_settings_pgsm_enable_query_plan.pl t/006_settings_pgsm_overflow_target.pl t/007_settings_pgsm_query_shared_buffer.pl t/008_settings_pgsm_histogram_buckets.pl t/009_settings_pgsm_histogram_max.pl t/010_settings_pgsm_histogram_min.pl t/011_settings_pgsm_bucket_time.pl t/012_settings_pgsm_max_buckets.pl t/013_settings_pgsm_normalized_query.pl t/014_settings_pgsm_track_utility.pl t/015_settings_pgsm_query_max_len.pl t/016_settings_pgsm_max.pl t/017_execution_stats.pl t/019_insufficient_shared_space.pl t/020_buffer_overflow.pl t/021_misc_1.pl t/022_misc_2.pl t/023_missing_queries.pl t/024_check_timings.pl t/025_compare_pgss.pl t/026_shared_blocks.pl t/027_local_blocks.pl t/028_temp_block.pl 4. Removed following TAP test cases as these are no longer needed and are covered by existing other test cases. 0001_settings_pgsm_track_planning.pl 0002_settings_pgsm_enable_query_plan.pl 5. Added more out files for histogram sql test cases to cover the behavior for bucket_start_time and server versions. regression/expected/histogram_3.out regression/expected/histogram_4.out regression/expected/histogram_5.out regression/expected/histogram_6.out 6. Added following out file that is PG server version 15 specific. t/expected/007_settings_pgsm_query_shared_buffer.out.15
This commit is contained in:
committed by
Hamid Akhtar
parent
0fe9908d5f
commit
af2da8885a
171
t/pgsm.pm
171
t/pgsm.pm
@@ -1,72 +1,157 @@
|
||||
package pgsm;
|
||||
package PGSM;
|
||||
|
||||
use String::Util qw(trim);
|
||||
use File::Basename;
|
||||
use File::Compare;
|
||||
use PostgresNode;
|
||||
use Test::More;
|
||||
|
||||
our @ISA= qw( Exporter );
|
||||
|
||||
# these CAN be exported.
|
||||
# These CAN be exported.
|
||||
our @EXPORT = qw( pgsm_init_pg pgsm_start_pg pgsm_stop_pg pgsm_psql_cmd pgsm_setup_pg_stat_monitor pgsm_create_extension pgsm_reset_pg_stat_monitor pgsm_drop_extension );
|
||||
|
||||
# Instance of pg server that would be spanwed by TAP testing. A new server will be created for each TAP test.
|
||||
our $pg_node;
|
||||
|
||||
# Create new PostgreSQL node and do initdb
|
||||
# Expected .out filename of TAP testcase being executed. These are already part of repo under t/expected/*.
|
||||
our $expected_filename_with_path;
|
||||
|
||||
# Major version of PG Server that we are using.
|
||||
our $PG_MAJOR_VERSION;
|
||||
|
||||
# Result .out filename of TAP testcase being executed. Where needed, a new *.out will be created for each TAP test.
|
||||
our $out_filename_with_path;
|
||||
|
||||
# Runtime output file that is used only for debugging purposes for comparison to PGSS, blocks and timings.
|
||||
our $debug_out_filename_with_path;
|
||||
|
||||
BEGIN {
|
||||
# Get PG Server Major version from pg_config
|
||||
$PG_MAJOR_VERSION = `pg_config --version | awk {'print \$2'} | cut -f1 -d"." | sed -e 's/[^0-9].*\$//g'`;
|
||||
$PG_MAJOR_VERSION =~ s/^\s+|\s+$//g;
|
||||
|
||||
# Depending upon PG server version load the required module at runtime when pgsm.pm is loaded.
|
||||
my $node_module = $PG_MAJOR_VERSION > 14 ? "PostgreSQL::Test::Cluster" : "PostgresNode";
|
||||
my $node_module_file = $node_module;
|
||||
$node_module_file =~ s[::][/]g;
|
||||
$node_module_file .= '.pm';
|
||||
require $node_module_file;
|
||||
$node_module->import;
|
||||
}
|
||||
|
||||
sub pgsm_init_pg
|
||||
{
|
||||
$pg_node = PostgresNode->get_new_node('pgsm_regression');
|
||||
print "Postgres major version: $PG_MAJOR_VERSION \n";
|
||||
|
||||
# For Server version 15 & above, spawn the server using PostgreSQL::Test::Cluster
|
||||
if ($PG_MAJOR_VERSION > 14) {
|
||||
$pg_node = PostgreSQL::Test::Cluster->new('pgsm_regression');
|
||||
}
|
||||
# For Server version 14 & below, spawn the server using PostgresNode
|
||||
elsif ($PG_MAJOR_VERSION < 15) {
|
||||
$pg_node = PostgresNode->get_new_node('pgsm_regression');
|
||||
}
|
||||
|
||||
$pg_node->dump_info;
|
||||
$pg_node->init;
|
||||
return $pg_node;
|
||||
}
|
||||
|
||||
sub pgsm_start_pg
|
||||
sub append_to_file
|
||||
{
|
||||
my $rt_value = $pg_node->start;
|
||||
ok($rt_value == 1, "Starting PostgreSQL");
|
||||
return $rt_value;
|
||||
my ($str) = @_;
|
||||
|
||||
# For Server version 15 & above, use PostgreSQL::Test::Utils to write to files
|
||||
if ($PG_MAJOR_VERSION > 14) {
|
||||
PostgreSQL::Test::Utils::append_to_file($out_filename_with_path, $str . "\n");
|
||||
}
|
||||
# For Server version 14 & below, use PostgresNode to write to files
|
||||
elsif ($PG_MAJOR_VERSION < 15) {
|
||||
TestLib::append_to_file($out_filename_with_path, $str . "\n");
|
||||
}
|
||||
chmod(0640 , $out_filename_with_path)
|
||||
or die("unable to set permissions for $out_filename_with_path");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub pgsm_stop_pg
|
||||
sub append_to_debug_file
|
||||
{
|
||||
return $pg_node->stop;
|
||||
my ($str) = @_;
|
||||
|
||||
# For Server version 15 & above, use PostgreSQL::Test::Utils to write to files
|
||||
if ($PG_MAJOR_VERSION > 14) {
|
||||
PostgreSQL::Test::Utils::append_to_file($debug_out_filename_with_path, $str . "\n");
|
||||
}
|
||||
# For Server version 14 & below, use PostgresNode to write to files
|
||||
elsif ($PG_MAJOR_VERSION < 15) {
|
||||
TestLib::append_to_file($debug_out_filename_with_path, $str . "\n");
|
||||
}
|
||||
chmod(0640 , $debug_out_filename_with_path)
|
||||
or die("unable to set permissions for $debug_out_filename_with_path");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub pgsm_psql_cmd
|
||||
sub setup_files_dir
|
||||
{
|
||||
my ($cmdret, $stdout, $stderr) = $pg_node->psql(@_);
|
||||
my ($perlfilename) = @_;
|
||||
|
||||
# Expected folder where expected output will be present
|
||||
my $expected_folder = "t/expected";
|
||||
|
||||
# Results/out folder where generated results files will be placed
|
||||
my $results_folder = "t/results";
|
||||
|
||||
# Check if results folder exists or not, create if it doesn't
|
||||
unless (-d $results_folder)
|
||||
{
|
||||
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";
|
||||
}
|
||||
|
||||
# Check if expected folder exists or not, bail out if it doesn't
|
||||
unless (-d $expected_folder)
|
||||
{
|
||||
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";
|
||||
}
|
||||
|
||||
#Remove .pl from filename and store in a variable
|
||||
my @split_arr = split /\./, $perlfilename;
|
||||
|
||||
my $filename_without_extension = $split_arr[0];
|
||||
|
||||
# Create expected filename with path
|
||||
my $expected_filename = "${filename_without_extension}.out";
|
||||
|
||||
if ($PG_MAJOR_VERSION <= 12 and "$filename_without_extension" == "001_settings_default")
|
||||
{
|
||||
$expected_filename = "${expected_filename}.${PG_MAJOR_VERSION}";
|
||||
}
|
||||
|
||||
if ($PG_MAJOR_VERSION >= 15 and "$filename_without_extension" == "007_settings_pgsm_query_shared_buffer")
|
||||
{
|
||||
$expected_filename = "${expected_filename}.${PG_MAJOR_VERSION}";
|
||||
}
|
||||
|
||||
$expected_filename_with_path = "${expected_folder}/${expected_filename}";
|
||||
|
||||
# Create results filename with path
|
||||
my $out_filename = "${filename_without_extension}.out";
|
||||
$out_filename_with_path = "${results_folder}/${out_filename}";
|
||||
|
||||
# Delete already existing result out file, if it exists.
|
||||
if ( -f $out_filename_with_path)
|
||||
{
|
||||
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
|
||||
}
|
||||
|
||||
$debug_out_filename_with_path = "${results_folder}/${out_filename}.debug";
|
||||
}
|
||||
|
||||
sub pgsm_setup_pg_stat_monitor
|
||||
sub compare_results
|
||||
{
|
||||
my ($set) = @_;
|
||||
my $pgdata = $pg_node->data_dir;
|
||||
open my $conf, '>>', "$pgdata/postgresql.conf";
|
||||
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
|
||||
print $conf "$set\n";
|
||||
close $conf;
|
||||
# Compare expected and results files and return the result
|
||||
return compare($expected_filename_with_path, $out_filename_with_path);
|
||||
}
|
||||
|
||||
sub pgsm_create_extension
|
||||
{
|
||||
my ($cmdret, $stdout, $stderr) = $pg_node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
|
||||
ok($cmdret == 0, "CREATE EXTENSION pg_stat_monitor...");
|
||||
return ($cmdret, $stdout, $stderr);
|
||||
}
|
||||
|
||||
sub pgsm_reset_pg_stat_monitor
|
||||
{
|
||||
# Run required commands/queries and dump output to out file.
|
||||
($cmdret, $stdout, $stderr) = $pg_node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
|
||||
ok($cmdret == 0, "Reset pg_stat_monitor...");
|
||||
return ($cmdret, $stdout, $stderr);
|
||||
}
|
||||
|
||||
sub pgsm_drop_extension
|
||||
{
|
||||
my ($cmdret, $stdout) = $pg_node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
|
||||
ok($cmdret == 0, "DROP EXTENSION pg_stat_monitor...");
|
||||
return ($cmdret, $stdout, $stderr);
|
||||
}
|
||||
1;
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user