|
11 | 11 | use PostgreSQL::Test::Utils;
|
12 | 12 | use Test::More;
|
13 | 13 |
|
14 |
| -my $node = PostgreSQL::Test::Cluster->new('primary'); |
15 |
| -$node->init(); |
16 |
| -$node->start; |
17 |
| - |
18 |
| -$node->append_conf('postgresql.conf', |
| 14 | +############### init primary/replica/standby ############## |
| 15 | +my $node_primary = PostgreSQL::Test::Cluster->new('primary'); |
| 16 | +$node_primary->polar_init_primary; |
| 17 | +$node_primary->append_conf('postgresql.conf', |
19 | 18 | "shared_preload_libraries = 'polar_login_history'");
|
20 |
| -$node->restart; |
21 | 19 |
|
22 |
| -$node->append_conf('postgresql.conf', "polar_login_history.enable = on"); |
23 |
| -$node->restart; |
| 20 | +my $node_replica = PostgreSQL::Test::Cluster->new('replica'); |
| 21 | +$node_replica->polar_init_replica($node_primary); |
| 22 | + |
| 23 | +my $node_standby = PostgreSQL::Test::Cluster->new('standby'); |
| 24 | +$node_standby->polar_init_standby($node_primary); |
| 25 | + |
| 26 | +$node_primary->start; |
| 27 | + |
| 28 | +$node_primary->polar_create_slot($node_replica->name); |
| 29 | +$node_primary->polar_create_slot($node_standby->name); |
| 30 | + |
| 31 | +$node_replica->start; |
| 32 | +$node_standby->start; |
| 33 | + |
| 34 | +$node_standby->polar_drop_all_slots; |
| 35 | + |
| 36 | + |
| 37 | +############### enable login history ############## |
| 38 | +$node_primary->append_conf('postgresql.conf', |
| 39 | + "polar_login_history.enable = on"); |
| 40 | +$node_primary->restart; |
| 41 | +is( $node_primary->safe_psql('postgres', 'show polar_login_history.enable;'), |
| 42 | + 'on', |
| 43 | + 'login history function is enabled'); |
| 44 | + |
| 45 | +$node_replica->append_conf('postgresql.conf', |
| 46 | + "polar_login_history.enable = on"); |
| 47 | +$node_replica->restart; |
| 48 | +is( $node_replica->safe_psql('postgres', 'show polar_login_history.enable;'), |
| 49 | + 'on', |
| 50 | + 'login history function is enabled'); |
| 51 | + |
| 52 | +$node_standby->append_conf('postgresql.conf', |
| 53 | + "polar_login_history.enable = on"); |
| 54 | +$node_standby->restart; |
| 55 | +is( $node_standby->safe_psql('postgres', 'show polar_login_history.enable;'), |
| 56 | + 'on', |
| 57 | + 'login history function is enabled'); |
| 58 | + |
| 59 | + |
| 60 | +############### log in to the database with the new user ############## |
| 61 | +$node_primary->safe_psql('postgres', 'create user zhangsan;'); |
| 62 | +$node_replica->restart; |
| 63 | + |
| 64 | +is( $node_primary->psql( |
| 65 | + 'postgres', undef, extra_params => [ '-U', 'zhangsan' ]), |
| 66 | + 0, |
| 67 | + 'login success'); |
| 68 | +isnt( |
| 69 | + $node_primary->psql( |
| 70 | + 'postgres1', undef, extra_params => [ '-U', 'zhangsan' ]), |
| 71 | + 0, |
| 72 | + 'login success'); |
| 73 | + |
| 74 | +is( $node_replica->psql( |
| 75 | + 'postgres', undef, extra_params => [ '-U', 'zhangsan' ]), |
| 76 | + 0, |
| 77 | + 'login success'); |
| 78 | +isnt( |
| 79 | + $node_replica->psql( |
| 80 | + 'postgres1', undef, extra_params => [ '-U', 'zhangsan' ]), |
| 81 | + 0, |
| 82 | + 'login success'); |
24 | 83 |
|
25 |
| -is($node->safe_psql('postgres', 'show polar_login_history.enable;'), |
26 |
| - 'on', 'login history function is enabled'); |
| 84 | +is( $node_standby->psql( |
| 85 | + 'postgres', undef, extra_params => [ '-U', 'zhangsan' ]), |
| 86 | + 0, |
| 87 | + 'login success'); |
| 88 | +isnt( |
| 89 | + $node_standby->psql( |
| 90 | + 'postgres1', undef, extra_params => [ '-U', 'zhangsan' ]), |
| 91 | + 0, |
| 92 | + 'login success'); |
27 | 93 |
|
28 |
| -$node->safe_psql('postgres', 'create user zhangsan;'); |
29 |
| -is($node->psql('postgres', undef, extra_params => [ '-U', 'zhangsan' ]), |
30 |
| - 0, 'login success'); |
31 |
| -$node->safe_psql('postgres', 'drop user zhangsan;'); |
| 94 | +$node_primary->safe_psql('postgres', 'drop user zhangsan;'); |
32 | 95 |
|
33 |
| -$node->stop; |
34 | 96 |
|
| 97 | +############### stop ############## |
| 98 | +$node_primary->stop; |
| 99 | +$node_replica->stop; |
| 100 | +$node_standby->stop; |
35 | 101 | done_testing();
|
0 commit comments