diff --git a/migrate/20240619_lantern_doctor_queries.rb b/migrate/20240619_lantern_doctor_queries.rb index 278162924..18d6dd99f 100644 --- a/migrate/20240619_lantern_doctor_queries.rb +++ b/migrate/20240619_lantern_doctor_queries.rb @@ -4,6 +4,7 @@ up do # percent toward transaction wraparound sql = < 0;", db: db) + + statements = res.chomp.strip.split("\n").map do |row| + values = row.split(",") + "SELECT setval('#{values[0]}.#{values[1]}', #{values[2]});" + end + + representative_server.run_query(statements, db: db) + end + end + + def create_and_enable_subscription + representative_server.list_all_databases.each do |db| + commands = < "lantern resource is deleted"}) end end + + describe "#enable_logical_replication" do + it "enables logical replication" do + expect(lantern_resource).to receive(:listen_ddl_log) + expect(lantern_resource).to receive(:create_and_enable_subscription) + expect { nx.enable_logical_replication }.to hop("wait") + end + end + + describe "#swap_leaders_with_parent" do + it "swaps ips with parent leader" do + parent = instance_double(LanternResource) + representative_server = instance_double(LanternServer) + vm = instance_double(GcpVm) + expect(parent).to receive(:representative_server).and_return(representative_server) + expect(lantern_resource).to receive(:representative_server).and_return(representative_server).at_least(:once) + expect(lantern_resource).to receive(:disable_logical_subscription) + expect(lantern_resource).to receive(:sync_sequences_with_parent) + expect(representative_server).to receive(:vm).and_return(vm).at_least(:once) + expect(vm).to receive(:swap_ip) + expect(lantern_resource).to receive(:parent).and_return(parent).at_least(:once) + expect(parent).to receive(:set_to_readonly) + expect { nx.swap_leaders_with_parent }.to hop("wait_swap_ip") + end + end + + describe "#wait_swap_ip" do + it "naps if error" do + representative_server = instance_double(LanternServer) + expect(lantern_resource).to receive(:representative_server).and_return(representative_server).at_least(:once) + expect(representative_server).to receive(:run_query).and_raise "test" + expect { nx.wait_swap_ip }.to nap(5) + end + + it "hops if ready" do + representative_server = instance_double(LanternServer) + expect(lantern_resource).to receive(:representative_server).and_return(representative_server).at_least(:once) + expect(representative_server).to receive(:run_query) + expect { nx.wait_swap_ip }.to hop("update_hosts") + end + end + + describe "#update_hosts" do + it "updates the domains of the current and new master, updates display states, and removes fork association" do + parent = instance_double(LanternResource) + current_master = instance_double(LanternServer, domain: "current-master-domain.com") + new_master = instance_double(LanternServer, domain: "new-master-domain.com") + timeline = instance_double(LanternTimeline) + + expect(lantern_resource).to receive(:parent).and_return(parent).at_least(:once) + expect(parent).to receive(:representative_server).and_return(current_master).at_least(:once) + expect(lantern_resource).to receive(:representative_server).and_return(new_master).at_least(:once) + expect(new_master).to receive(:update).with(domain: "current-master-domain.com") + expect(current_master).to receive(:update).with(domain: "new-master-domain.com") + + expect(lantern_resource).to receive(:update).with(display_state: nil) + expect(parent).to receive(:update).with(display_state: nil) + + expect(lantern_resource).to receive(:update).with(parent_id: nil) + expect(lantern_resource).to receive(:timeline).and_return(timeline) + expect(timeline).to receive(:update).with(parent_id: nil) + + expect { nx.update_hosts }.to hop("wait") + end + end end