@@ -27,9 +27,31 @@ sub run_test_in_single_user_mode
2727 ],
2828 \$commands );
2929
30+ return $result ;
31+ }
32+
33+ # Wrapper function for run_test_in_single_user_mode. This would be used when
34+ # the input command succeeds.
35+ sub run_test_in_single_user_mode_success
36+ {
37+ my ($node , $commands , $testname ) = @_ ;
38+
39+ my $result = run_test_in_single_user_mode($node , $commands , $testname );
40+
3041 ok($result , $testname );
3142}
3243
44+ # Wrapper function for run_test_in_single_user_mode. This would be used when
45+ # the input command fails.
46+ sub run_test_in_single_user_mode_fail
47+ {
48+ my ($node , $commands , $testname ) = @_ ;
49+
50+ my $result = run_test_in_single_user_mode($node , $commands , $testname );
51+
52+ ok(!$result , $testname );
53+ }
54+
3355my $slotname = ' test_slot' ;
3456
3557# Initialize a node
@@ -38,34 +60,38 @@ sub run_test_in_single_user_mode
3860$node -> start;
3961
4062# Define initial table
41- $node -> safe_psql(' postgres' , " CREATE TABLE foo (id int)" );
63+ $node -> safe_psql(
64+ ' postgres' , qq(
65+ CREATE TABLE foo (id int);
66+ SELECT pg_create_logical_replication_slot('$slotname ', 'test_decoding');
67+ ) );
4268
4369# Stop the node to run and test in single-user mode
4470$node -> stop;
4571
46- run_test_in_single_user_mode (
72+ run_test_in_single_user_mode_fail (
4773 $node ,
48- " SELECT pg_create_logical_replication_slot('$slotname ', 'test_decoding')" ,
49- " replication slot can be created in single-user mode" );
74+ " SELECT pg_create_logical_replication_slot('another_slot ', 'test_decoding')" ,
75+ " replication slot cannot be created in single-user mode" );
5076
51- run_test_in_single_user_mode (
77+ run_test_in_single_user_mode_fail (
5278 $node , qq(
5379INSERT INTO foo VALUES (1);
5480SELECT count(1) FROM pg_logical_slot_get_changes('$slotname ', NULL, NULL);
5581) ,
56- " logical decoding be done in single-user mode" );
82+ " logical decoding cannot be done in single-user mode" );
5783
58- run_test_in_single_user_mode (
84+ run_test_in_single_user_mode_fail (
5985 $node ,
6086 " SELECT pg_replication_slot_advance('$slotname ', pg_current_wal_lsn())" ,
61- " replication slot can be advanced in single-user mode" );
87+ " replication slot cannot be advanced in single-user mode" );
6288
63- run_test_in_single_user_mode (
89+ run_test_in_single_user_mode_fail (
6490 $node ,
6591 " SELECT pg_copy_logical_replication_slot('$slotname ', 'dest_slot')" ,
66- " replication slot can be copied in single-user mode" );
92+ " replication slot cannot be copied in single-user mode" );
6793
68- run_test_in_single_user_mode (
94+ run_test_in_single_user_mode_success (
6995 $node ,
7096 " SELECT pg_drop_replication_slot('$slotname ')" ,
7197 " replication slot can be dropped in single-user mode" );
0 commit comments