|
209 | 209 | end
|
210 | 210 |
|
211 | 211 | describe ".drop_subscription" do
|
212 |
| - before do |
213 |
| - PgEasyReplicate.bootstrap({ group_name: "cluster1" }) |
214 |
| - end |
| 212 | + before { PgEasyReplicate.bootstrap({ group_name: "cluster1" }) } |
215 | 213 |
|
216 | 214 | after do
|
217 | 215 | PgEasyReplicate.cleanup({ everything: true, group_name: "cluster1" })
|
|
234 | 232 | it "raises an error when user does not have sufficient privileges" do
|
235 | 233 | # Use a limited user for this test case
|
236 | 234 | restricted_user = "no_sup"
|
237 |
| - restricted_user_target_connection_url = target_connection_url(restricted_user) |
| 235 | + restricted_user_target_connection_url = |
| 236 | + target_connection_url(restricted_user) |
238 | 237 |
|
239 | 238 | described_class.create_subscription(
|
240 | 239 | group_name: "cluster1",
|
|
250 | 249 | end.to raise_error(RuntimeError) { |e|
|
251 | 250 | expect(e.message).to include("Unable to drop subscription")
|
252 | 251 | }
|
253 |
| - expect(pg_subscriptions(connection_url: target_connection_url)).not_to eq([]) |
| 252 | + expect(pg_subscriptions(connection_url: target_connection_url)).not_to eq( |
| 253 | + [], |
| 254 | + ) |
254 | 255 | end
|
255 | 256 | end
|
256 | 257 |
|
|
704 | 705 | { last_analyze: nil, last_vacuum: nil, relname: "spatial_ref_sys" },
|
705 | 706 | )
|
706 | 707 | end
|
| 708 | + |
| 709 | + it "does not mark switchover complete if subscription drop fails" do |
| 710 | + conn1 = |
| 711 | + PgEasyReplicate::Query.connect( |
| 712 | + connection_url: connection_url, |
| 713 | + schema: test_schema, |
| 714 | + ) |
| 715 | + conn1[:items].insert(name: "Foo1") |
| 716 | + expect(conn1[:items].first[:name]).to eq("Foo1") |
| 717 | + |
| 718 | + conn2 = |
| 719 | + PgEasyReplicate::Query.connect( |
| 720 | + connection_url: target_connection_url, |
| 721 | + schema: test_schema, |
| 722 | + ) |
| 723 | + expect(conn2[:items].first).to be_nil |
| 724 | + |
| 725 | + ENV["SECONDARY_SOURCE_DB_URL"] = docker_compose_source_connection_url |
| 726 | + described_class.start_sync( |
| 727 | + group_name: "cluster1", |
| 728 | + schema_name: test_schema, |
| 729 | + recreate_indices_post_copy: true, |
| 730 | + ) |
| 731 | + |
| 732 | + conn1[:items].insert(name: "Foo2") |
| 733 | + |
| 734 | + allow(described_class).to receive(:drop_subscription).and_raise( |
| 735 | + "Subscription drop failed", |
| 736 | + ) |
| 737 | + |
| 738 | + expect do |
| 739 | + described_class.switchover( |
| 740 | + group_name: "cluster1", |
| 741 | + source_conn_string: connection_url, |
| 742 | + target_conn_string: target_connection_url, |
| 743 | + skip_vacuum_analyze: true, |
| 744 | + ) |
| 745 | + end.to raise_error("Switchover failed: Subscription drop failed") |
| 746 | + |
| 747 | + described_class.restore_connections_on_source_db("cluster1") |
| 748 | + |
| 749 | + expect(PgEasyReplicate::Group.find("cluster1")).to include( |
| 750 | + switchover_completed_at: nil, |
| 751 | + ) |
| 752 | + end |
707 | 753 | end
|
708 | 754 |
|
709 | 755 | # Note: Hard to test for special roles that act as superuser which aren't superuser, like rds_superuser
|
|
769 | 815 | )
|
770 | 816 | end.to raise_error(/Starting sync failed: PG::InsufficientPrivilege/)
|
771 | 817 |
|
772 |
| - # expect(PgEasyReplicate::Group.find("cluster1")).to include( |
773 |
| - # switchover_completed_at: nil, |
774 |
| - # created_at: kind_of(Time), |
775 |
| - # name: "cluster1", |
776 |
| - # schema_name: "pger_test", |
777 |
| - # id: kind_of(Integer), |
778 |
| - # started_at: kind_of(Time), |
779 |
| - # updated_at: kind_of(Time), |
780 |
| - # failed_at: nil, |
781 |
| - # table_names: nil, |
782 |
| - # ) |
| 818 | + expect(PgEasyReplicate::Group.find("cluster1")).to include( |
| 819 | + switchover_completed_at: nil, |
| 820 | + ) |
783 | 821 |
|
784 | 822 | # conn1[:items].insert(name: "Foo2")
|
785 | 823 |
|
|
0 commit comments