Skip to content

Commit

Permalink
use external connection string for checking availablitiy
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Jul 22, 2024
1 parent 586990c commit 5a57719
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
4 changes: 2 additions & 2 deletions misc/misc_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def self.run_script_daemonized(resource_name, filename, task_name)
serv = LanternResource[name: resource_name].representative_server
serv.vm.sshable.cmd("common/bin/daemonizer 'sudo #{filename}' #{task_name}")

task_logs resource_name, "#{task_name}"
task_logs resource_name, task_name.to_s
end

def self.create_all_indexes_concurrently_script(resource_name, filename)
Expand All @@ -109,7 +109,7 @@ def self.create_all_indexes_concurrently_script(resource_name, filename)
if !indexes.empty?
queries = []
indexes.each {
queries.push(_1.gsub(/create\s+index/i, 'CREATE INDEX CONCURRENTLY')[1..-2])
queries.push(_1.gsub(/create\s+index/i, "CREATE INDEX CONCURRENTLY")[1..-2])
}

queries.map do |query|
Expand Down
10 changes: 5 additions & 5 deletions prog/lantern/lantern_server_nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,11 @@ def destroy_domain
end

def available?
vm.sshable.invalidate_cache_entry

status = false
begin
lantern_server.run_query("SELECT 1")
return true
session = Sequel.connect(lantern_server.connection_string)
session["SELECT 1"]
status = true
rescue
end

Expand All @@ -624,7 +624,7 @@ def available?
rescue
end

false
status
end

label def prewarm_indexes
Expand Down
36 changes: 13 additions & 23 deletions spec/prog/lantern/lantern_server_nexus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -748,40 +748,30 @@
end
end

describe "#update_memory_limits" do
it "updates memory limits" do
expect(nx).to receive(:when_update_memory_limits_set?).and_yield
expect(lantern_server).to receive(:run_query)
expect(lantern_server.vm.sshable).to receive(:invalidate_cache_entry)
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo lantern/bin/update_memory_limits")
expect { nx.wait_db_available }.to hop("wait")
end
end

describe "#available" do
it "marks as available" do
expect(lantern_server).to receive(:run_query)
expect(lantern_server.vm.sshable).to receive(:invalidate_cache_entry)
expect(lantern_server).to receive(:connection_string)
session = instance_double(Hash)
expect(session).to receive(:[]).with("SELECT 1")
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo lantern/bin/logs --tail 5").and_return("logs")
expect(Sequel).to receive(:connect).and_return(session)
expect(nx.available?).to be(true)
end

it "does not mark as unavailable if redo in progress" do
expect(lantern_server).to receive(:run_query).and_raise "err"
expect(lantern_server.vm.sshable).to receive(:invalidate_cache_entry)
expect(lantern_server).to receive(:connection_string)
session = instance_double(Hash)
expect(session).to receive(:[]).with("SELECT 1").and_raise "err"
expect(Sequel).to receive(:connect).and_return(session)
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo lantern/bin/logs --tail 5").and_return("redo in progress")
expect(nx.available?).to be(true)
end

it "marks unavailable if cmd fails" do
expect(lantern_server).to receive(:run_query).and_raise "err"
expect(lantern_server.vm.sshable).to receive(:invalidate_cache_entry)
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo lantern/bin/logs --tail 5").and_raise
expect(nx.available?).to be(false)
end

it "marks unavailable if cmd returns other logs" do
expect(lantern_server).to receive(:run_query).and_raise "err"
expect(lantern_server.vm.sshable).to receive(:invalidate_cache_entry)
expect(lantern_server).to receive(:connection_string)
session = instance_double(Hash)
expect(session).to receive(:[]).with("SELECT 1").and_raise "err"
expect(Sequel).to receive(:connect).and_return(session)
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo lantern/bin/logs --tail 5").and_return("logs")
expect(nx.available?).to be(false)
end
Expand Down

0 comments on commit 5a57719

Please sign in to comment.