diff --git a/.github/workflows/maze-runner.yml b/.github/workflows/maze-runner.yml index 2adfe2ae..9e4c925c 100644 --- a/.github/workflows/maze-runner.yml +++ b/.github/workflows/maze-runner.yml @@ -56,7 +56,7 @@ jobs: include: - ruby-version: '2.0' que-version: '0.14' - - ruby-version: '3.2' + - ruby-version: '2.5' que-version: '0.14' - ruby-version: '2.5' que-version: '1' diff --git a/.github/workflows/run-maze-runner.yml b/.github/workflows/run-maze-runner.yml index 9a64c503..bb8f7426 100644 --- a/.github/workflows/run-maze-runner.yml +++ b/.github/workflows/run-maze-runner.yml @@ -42,6 +42,7 @@ jobs: with: ruby-version: 2.7 bundler-cache: true + cache-version: ${{ inputs.ruby-version }}-${{ inputs.rack-version }}-${{ inputs.que-version }}-${{ inputs.rails-version }}-${{ inputs.sidekiq-version }} - run: bundle exec maze-runner ${{ inputs.features }} --no-source env: diff --git a/features/fixtures/que/app/Gemfile b/features/fixtures/que/app/Gemfile index 9257d550..930f3958 100644 --- a/features/fixtures/que/app/Gemfile +++ b/features/fixtures/que/app/Gemfile @@ -6,7 +6,6 @@ que_version = ENV.fetch("QUE_VERSION") gem "que", "~> #{que_version}" gem "pg", RUBY_VERSION < "2.2.0" ? "0.21.0" : "> 0.21.0" -gem "activerecord", RUBY_VERSION < "2.2.0" ? "4.2.11" : "> 4.2.11" # Install a compatible Minitest version on Ruby <2.3 gem 'minitest', '5.11.3' if RUBY_VERSION < '2.3.0' diff --git a/features/fixtures/que/app/app.rb b/features/fixtures/que/app/app.rb index 5ff701ee..3f984f80 100644 --- a/features/fixtures/que/app/app.rb +++ b/features/fixtures/que/app/app.rb @@ -1,79 +1,3 @@ -require 'pg' -require 'que' -require 'socket' -require 'bugsnag' -require 'active_record' +require_relative "setup-que" -QUE_VERSION = ENV.fetch("QUE_VERSION") - -Bugsnag.configure do |config| - puts "Configuring `api_key` to #{ENV['BUGSNAG_API_KEY']}" - config.api_key = ENV['BUGSNAG_API_KEY'] - puts "Configuring `endpoint` to #{ENV['BUGSNAG_ENDPOINT']}" - 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', - username: 'postgres', - password: 'test_password', - host: 'postgres' -) - -Que.connection = ActiveRecord Que.migrate!(version: Que::Migrations::CURRENT_VERSION) - -# Workaround a bug in que/pg -# see https://github.com/que-rb/que/issues/247 -if QUE_VERSION == '0.14' - Que::Adapters::Base::CAST_PROCS[1184] = lambda do |value| - case value - when Time then value - when String then Time.parse(value) - else raise "Unexpected time class: #{value.class} (#{value.inspect})" - end - end -end - -class UnhandledJob < Que::Job - def run - raise RuntimeError.new("Unhandled error") - end - - def handle_error(error) - destroy - end -end - -class HandledJob < Que::Job - def run - raise RuntimeError.new("Handled error") - rescue => exception - Bugsnag.notify(exception) - end -end - -case ARGV[0] -when "unhandled" - UnhandledJob.enqueue -when "handled" - HandledJob.enqueue -end diff --git a/features/fixtures/que/app/enqueue-job.rb b/features/fixtures/que/app/enqueue-job.rb new file mode 100644 index 00000000..45eff66b --- /dev/null +++ b/features/fixtures/que/app/enqueue-job.rb @@ -0,0 +1,22 @@ +require_relative "setup-que" + +query = <<-SQL +SELECT EXISTS ( + SELECT FROM pg_tables WHERE tablename = 'que_jobs' +) AS que_jobs_exists +SQL + +Timeout::timeout(10) do + loop do + break if $connection.exec(query)[0]["que_jobs_exists"] == "t" + + sleep 0.1 + end +end + +case ARGV[0] +when "unhandled" + UnhandledJob.enqueue +when "handled" + HandledJob.enqueue +end diff --git a/features/fixtures/que/app/setup-que.rb b/features/fixtures/que/app/setup-que.rb new file mode 100644 index 00000000..1fc5724b --- /dev/null +++ b/features/fixtures/que/app/setup-que.rb @@ -0,0 +1,71 @@ +require 'pg' +require 'que' +require 'socket' +require 'bugsnag' + +QUE_VERSION = ENV.fetch("QUE_VERSION") + +Bugsnag.configure do |config| + puts "Configuring `api_key` to #{ENV['BUGSNAG_API_KEY']}" + config.api_key = ENV['BUGSNAG_API_KEY'] + puts "Configuring `endpoint` to #{ENV['BUGSNAG_ENDPOINT']}" + 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 + +$connection = PG::Connection.open( + host: 'postgres', + user: 'postgres', + password: 'test_password', + dbname: 'postgres' +) + +if QUE_VERSION == '0.14' + Que.connection = $connection + + # Workaround a bug in que/pg + # see https://github.com/que-rb/que/issues/247 + Que::Adapters::Base::CAST_PROCS[1184] = lambda do |value| + case value + when Time then value + when String then Time.parse(value) + else raise "Unexpected time class: #{value.class} (#{value.inspect})" + end + end +else + Que.connection_proc = ->(&block) { block.call($connection) } +end + +class UnhandledJob < Que::Job + def run + raise RuntimeError.new("Unhandled error") + end + + def handle_error(error) + destroy + end +end + +class HandledJob < Que::Job + def run + raise RuntimeError.new("Handled error") + rescue => exception + Bugsnag.notify(exception) + end +end diff --git a/features/fixtures/rails3/app/Gemfile b/features/fixtures/rails3/app/Gemfile index e99e60c8..00267d7f 100644 --- a/features/fixtures/rails3/app/Gemfile +++ b/features/fixtures/rails3/app/Gemfile @@ -18,3 +18,6 @@ gem "warden" # Install a compatible Loofah version on Ruby <2.5 gem 'loofah', '2.20.0' if RUBY_VERSION < '2.5' + +# Install a compatible Thor version on Ruby <2.6 +gem 'thor', '<1.3.0' if RUBY_VERSION < '2.6' diff --git a/features/que.feature b/features/que.feature index c143b8c6..efe0174a 100644 --- a/features/que.feature +++ b/features/que.feature @@ -2,7 +2,7 @@ Feature: Errors are delivered to Bugsnag from Que Scenario: Que will deliver unhandled errors Given I start the service "que" - When I execute the command "bundle exec ruby app.rb unhandled" in the service "que" + When I execute the command "bundle exec ruby enqueue-job.rb unhandled" in the service "que" And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is true @@ -15,7 +15,7 @@ Scenario: Que will deliver unhandled errors Scenario: Que will deliver handled errors Given I start the service "que" - When I execute the command "bundle exec ruby app.rb handled" in the service "que" + When I execute the command "bundle exec ruby enqueue-job.rb handled" in the service "que" And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is false