Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f28f776

Browse files
committed
First version of the test.
1 parent b476ed4 commit f28f776

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Simple checks
2+
#use Data::Dumper;
3+
use strict;
4+
use warnings;
5+
6+
use PostgresNode;
7+
use TestLib;
8+
use Test::More;
9+
10+
# Wait until replay to complete
11+
sub replay_wait( $$ ) {
12+
my $node_master = shift;
13+
my $node_standby = shift;
14+
my $until_lsn =
15+
$node_master->safe_psql('postgres', "SELECT pg_current_wal_lsn()");
16+
17+
$node_standby->poll_query_until('postgres',
18+
"SELECT (pg_last_wal_replay_lsn() - '$until_lsn'::pg_lsn) >= 0")
19+
or die "standby never caught up";
20+
}
21+
22+
my ( $ret, $stdout, $stderr );
23+
24+
# Initialize master node
25+
my $node_master = get_new_node('master');
26+
$node_master->init(allows_streaming => 1);
27+
$node_master->start;
28+
29+
# Make first snapshot
30+
$node_master->safe_psql('postgres',
31+
"select pg_make_snapshot();");
32+
33+
# And some content
34+
$node_master->safe_psql('postgres',
35+
"CREATE TABLE tab_int AS SELECT generate_series(1, 10) AS a");
36+
37+
# Take backup
38+
my $backup_name = 'my_backup';
39+
$node_master->backup($backup_name);
40+
41+
# Create streaming standby from backup
42+
my $node_standby = get_new_node('standby');
43+
44+
$node_standby->init_from_backup($node_master, $backup_name,
45+
has_streaming => 1);
46+
47+
$node_standby->start;
48+
49+
# Make second snapshot
50+
$node_master->safe_psql('postgres',
51+
"select pg_make_snapshot();");
52+
53+
replay_wait( $node_master, $node_standby );
54+
55+
# Check for pg_control_snapshot() results
56+
my ( $master_out, $standby_out );
57+
$master_out = $node_master->safe_psql( 'postgres', "select * from pg_control_snapshot()" );
58+
$standby_out = $node_standby->safe_psql( 'postgres', "select * from pg_control_snapshot()" );
59+
60+
ok( $master_out eq '1|2|0', 'pg_control_snapshot() on master' );
61+
ok( $standby_out eq '1|1|0', 'pg_control_snapshot() on standby' );
62+
63+
# Make third snapshot
64+
$node_master->safe_psql('postgres',
65+
"select pg_make_snapshot();");
66+
67+
replay_wait( $node_master, $node_standby );
68+
69+
# Check for pg_control_snapshot() results another one
70+
$master_out = $node_master->safe_psql( 'postgres', "select * from pg_control_snapshot()" );
71+
$standby_out = $node_standby->safe_psql( 'postgres', "select * from pg_control_snapshot()" );
72+
73+
ok( $master_out eq '1|3|0', 'pg_control_snapshot() on master 2' );
74+
ok( $standby_out eq '1|2|0', 'pg_control_snapshot() on standby 2' );
75+
76+
# Standby checks
77+
( $ret, $stdout, $stderr ) = $node_standby->psql( 'postgres', "select pg_recover_to_snapshot( 3 );" );
78+
like( $stderr, '/ERROR: Operation is not possible at replica/', 'pg_recover_to_snapshot() is prohibited on replica' );
79+
80+
( $ret, $stdout, $stderr ) = $node_standby->psql( 'postgres', "select pg_make_snapshot();" );
81+
like( $stderr, '/ERROR: Operation is not possible at replica/', 'pg_make_snapshot() is prohibited on replica' );
82+
83+
( $ret, $stdout, $stderr ) = $node_standby->psql( 'postgres', "select pg_switch_to_snapshot( 2 );" );
84+
like( $stderr, '/ERROR: Operation is not possible at replica/', 'pg_switch_to_snapshot() is prohibited on replica' );
85+
86+
( $ret, $stdout, $stderr ) = $node_standby->psql( 'postgres', "select pg_set_backend_snapshot( 3 );" );
87+
like( $stderr, '/ERROR: Invalid snapshot/', 'Invalid snapshot number passed to pg_set_backend_snapshot() on standby' );
88+
89+
( $ret, $stdout, $stderr ) = $node_standby->psql( 'postgres', "select pg_set_backend_snapshot( 2 );" );
90+
is( $ret, 0, 'Standby pg_set_backend_snapshot()' );
91+
92+
( $ret, $stdout, $stderr ) = $node_standby->psql( 'postgres', "select pg_set_backend_snapshot( 2 ); select pg_get_backend_snapshot();" );
93+
94+
$stdout =~ s/\s//;
95+
96+
is( $stdout, 2, 'Standby pg_get_backend_snapshot()' );
97+
98+
# Master checks
99+
100+
( $ret, $stdout, $stderr ) = $node_standby->psql( 'postgres', "select pg_set_backend_snapshot( 3 );" );
101+
like( $stderr, '/ERROR: Invalid snapshot/', 'Invalid snapshot number passed to pg_set_backend_snapshot() on master' );
102+
103+
( $ret, $stdout, $stderr ) = $node_master->psql( 'postgres', "select pg_set_backend_snapshot( 2 );" );
104+
is( $ret, 0, 'Master pg_set_backend_snapshot()' );
105+
106+
( $ret, $stdout, $stderr ) = $node_master->psql( 'postgres', "select pg_set_backend_snapshot( 2 ); select pg_get_backend_snapshot();" );
107+
108+
$stdout =~ s/\s//;
109+
110+
is( $stdout, 2, 'Master pg_get_backend_snapshot()' );
111+
112+
113+
#print Dumper( $ret );
114+
#print Dumper( $stdout );
115+
#print Dumper( $stderr );
116+
117+
118+
done_testing();

0 commit comments

Comments
 (0)