Skip to content

Commit

Permalink
Revert and cleanup the verify_connection task (#995)
Browse files Browse the repository at this point in the history
* Revert and cleanup the verify_connection task to fix random race conditions. Fxies #902

* oops. I was doing testing and forgot to remove this variable assignment
  • Loading branch information
jwoertink authored Dec 29, 2023
1 parent 49f6ccb commit 795b005
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions spec/avram/tasks/db_verify_connection_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
require "../../spec_helper"

describe Db::VerifyConnection do
it "runs a test connection" do
task = Db::VerifyConnection.new
task.output = IO::Memory.new
task.run_task
task.output.to_s.should contain "Connection verified"
end

it "throws a helpful error" do
creds = Avram::Credentials.parse("postgres://eat@joes/crab_shack")
TestDatabase.temp_config(credentials: creds) do
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Avram.initialize_logging

Db::Create.new(quiet: true).run_task
Db::Migrate.new(quiet: true).run_task
Db::VerifyConnection.new(quiet: true).run_task

Avram::SpecHelper.use_transactional_specs(TestDatabase)

Expand Down
9 changes: 6 additions & 3 deletions src/avram/tasks/db/verify_connection.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ class Db::VerifyConnection < BaseTask
end

def run_task
Avram.settings.database_to_migrate.verify_connection
puts "✔ Connection verified" unless quiet?
rescue Avram::ConnectionError
# Using this block method instead of the previous `Database.verify_connection`
# due to some random race conditions that cause this task to fail for some people
DB.open(Avram.settings.database_to_migrate.settings.credentials.url) do |_db|
output.puts "✔ Connection verified" unless quiet?
end
rescue Avram::ConnectionError | DB::ConnectionRefused
raise <<-ERROR
Unable to connect to Postgres for database '#{Avram.settings.database_to_migrate}'.
Expand Down

0 comments on commit 795b005

Please sign in to comment.