Skip to content

Commit

Permalink
Make Que fixture a reliable
Browse files Browse the repository at this point in the history
This doesn't seem to flake on CI (at least I haven't noticed it) but
it failed pretty commonly locally before this change
  • Loading branch information
imjoehaines committed Jan 5, 2021
1 parent 9b73185 commit 560de4a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions features/fixtures/que/app/app.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'pg'
require 'que'
require 'socket'
require 'bugsnag'
require 'active_record'

Expand All @@ -10,6 +11,23 @@
config.endpoint = ENV['BUGSNAG_ENDPOINT']
end

postgres_ready = false
attempts = 0
MAX_ATTEMPTS = 10

until postgres_ready || attempts >= MAX_ATTEMPTS
begin
Timeout::timeout(5) { TCPSocket.new('postgres', 5432).close }

postgres_ready = true
rescue Exception
attempts += 1
sleep 1
end
end

raise 'postgres was not ready in time!' unless postgres_ready

ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
database: 'postgres',
Expand Down

0 comments on commit 560de4a

Please sign in to comment.