mirror of
https://github.com/percona/pg_stat_monitor.git
synced 2026-02-04 05:56:21 +00:00
Fix integer overflow (#435)
* Fix MAX_BUCKETS_MEM overflow * Fix MAX_QUERY_BUF overflow * Fix int overflow in IsBucketValid function * Add missing newline * Remove test for max value of pgsm_query_shared_buffer parameter * Tune tests * Cleanup * Use int64 type instead of long long
This commit is contained in:
63
t/031_query_stat.pl
Normal file
63
t/031_query_stat.pl
Normal file
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use File::Basename;
|
||||
use File::Compare;
|
||||
use File::Copy;
|
||||
use Test::More;
|
||||
use lib 't';
|
||||
use pgsm;
|
||||
|
||||
# Get file name and CREATE out file name and dirs WHERE requried
|
||||
PGSM::setup_files_dir(basename($0));
|
||||
|
||||
# CREATE new PostgreSQL node and do initdb
|
||||
my $node = PGSM->pgsm_init_pg();
|
||||
my $pgdata = $node->data_dir;
|
||||
|
||||
# UPDATE postgresql.conf to include/load pg_stat_monitor library
|
||||
open my $conf, '>>', "$pgdata/postgresql.conf";
|
||||
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
|
||||
print $conf "pg_stat_monitor.pgsm_bucket_time = 2147483647\n"; # Max value for this parameter
|
||||
print $conf "pg_stat_monitor.pgsm_max_buckets = 20000\n"; # Max value for this parameter
|
||||
close $conf;
|
||||
|
||||
# Start server
|
||||
my $rt_value = $node->start;
|
||||
ok($rt_value == 1, "Start Server");
|
||||
|
||||
# CREATE EXTENSION and change out file permissions
|
||||
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
|
||||
ok($cmdret == 0, "CREATE PGSM EXTENSION");
|
||||
PGSM::append_to_file($stdout);
|
||||
|
||||
# Run required commands/queries and dump output to out file.
|
||||
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
|
||||
ok($cmdret == 0, "Reset PGSM EXTENSION");
|
||||
PGSM::append_to_file($stdout);
|
||||
|
||||
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT 1 AS num;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
|
||||
ok($cmdret == 0, "Print results of a test query");
|
||||
PGSM::append_to_file($stdout);
|
||||
|
||||
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, comments FROM pg_stat_monitor ORDER BY query COLLATE "C";', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
|
||||
ok($cmdret == 0, "Check query stats");
|
||||
PGSM::append_to_file($stdout);
|
||||
|
||||
# DROP EXTENSION
|
||||
$stdout = $node->safe_psql('postgres', 'DROP EXTENSION pg_stat_monitor;', extra_params => ['-a']);
|
||||
ok($cmdret == 0, "DROP PGSM EXTENSION");
|
||||
PGSM::append_to_file($stdout);
|
||||
|
||||
# Stop the server
|
||||
$node->stop;
|
||||
|
||||
# compare the expected and out file
|
||||
my $compare = PGSM->compare_results();
|
||||
|
||||
# Test/check if expected and result/out file match. If Yes, test passes.
|
||||
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
|
||||
|
||||
# Done testing for this testcase file.
|
||||
done_testing();
|
||||
Reference in New Issue
Block a user