1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +03:00
Files
postgres/src/test/modules/commit_ts/t/001_base.pl
Andrew Dunstan b3b4d8e68a Move Perl test modules to a better namespace
The five modules in our TAP test framework all had names in the top
level namespace. This is unwise because, even though we're not
exporting them to CPAN, the names can leak, for example if they are
exported by the RPM build process. We therefore move the modules to the
PostgreSQL::Test namespace. In the process PostgresNode is renamed to
Cluster, and TestLib is renamed to Utils. PostgresVersion becomes simply
PostgreSQL::Version, to avoid possible confusion about what it's the
version of.

Discussion: https://postgr.es/m/aede93a4-7d92-ef26-398f-5094944c2504@dunslane.net

Reviewed by Erik Rijkers and Michael Paquier
2021-10-24 10:28:19 -04:00

37 lines
1.2 KiB
Perl

# Copyright (c) 2021, PostgreSQL Global Development Group
# Single-node test: value can be set, and is still present after recovery
use strict;
use warnings;
use PostgreSQL::Test::Utils;
use Test::More tests => 2;
use PostgreSQL::Test::Cluster;
my $node = PostgreSQL::Test::Cluster->new('foxtrot');
$node->init;
$node->append_conf('postgresql.conf', 'track_commit_timestamp = on');
$node->start;
# Create a table, compare "now()" to the commit TS of its xmin
$node->safe_psql('postgres',
'create table t as select now from (select now(), pg_sleep(1)) f');
my $true = $node->safe_psql('postgres',
'select t.now - ts.* < \'1s\' from t, pg_class c, pg_xact_commit_timestamp(c.xmin) ts where relname = \'t\''
);
is($true, 't', 'commit TS is set');
my $ts = $node->safe_psql('postgres',
'select ts.* from pg_class, pg_xact_commit_timestamp(xmin) ts where relname = \'t\''
);
# Verify that we read the same TS after crash recovery
$node->stop('immediate');
$node->start;
my $recovered_ts = $node->safe_psql('postgres',
'select ts.* from pg_class, pg_xact_commit_timestamp(xmin) ts where relname = \'t\''
);
is($recovered_ts, $ts, 'commit TS remains after crash recovery');