Skip to content

Commit

Permalink
Merge pull request #771 from bugsnag/maze-runner-docker-exec
Browse files Browse the repository at this point in the history
Use docker compose exec to run queue commands in maze runner tests
  • Loading branch information
imjoehaines authored Jan 16, 2023
2 parents f8d6f4b + 57a91a9 commit 98f999c
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Gemfile-maze-runner
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source "https://rubygems.org"

gem 'bugsnag-maze-runner', git: 'https://github.com/bugsnag/maze-runner', tag: 'v7.6.0'
gem 'bugsnag-maze-runner', git: 'https://github.com/bugsnag/maze-runner', tag: 'v7.10.1'
2 changes: 2 additions & 0 deletions features/fixtures/que/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ ENV QUE_VERSION $QUE_VERSION
RUN bundle install

COPY app/ /usr/src/app

CMD bundle exec que ./app.rb
13 changes: 13 additions & 0 deletions features/fixtures/rails_integrations/app/lib/tasks/fixture.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace :fixture do
task queue_unhandled_job: [:environment] do
UnhandledJob.perform_later(1, yes: true)
end

task queue_working_job: [:environment] do
WorkingJob.perform_later
end

task queue_resque_job: [:environment] do
Resque.enqueue(ResqueWorker, 123, "abc", [7, 8, 9], x: true, y: false)
end
end
4 changes: 3 additions & 1 deletion features/fixtures/sidekiq/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ ENV SIDEKIQ_VERSION $SIDEKIQ_VERSION

RUN bundle install

COPY app/ /app/
COPY app/ /app/

CMD bundle exec sidekiq -r ./app.rb
8 changes: 4 additions & 4 deletions features/que.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Feature: Errors are delivered to Bugsnag from Que

Scenario: Que will deliver unhandled errors
Given I run the service "que" with the command "bundle exec ruby app.rb unhandled"
And I run the service "que" with the command "timeout 5 bundle exec que ./app.rb"
Given I start the service "que"
When I execute the command "bundle exec ruby app.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
Expand All @@ -14,8 +14,8 @@ Scenario: Que will deliver unhandled errors
And the exception "errorClass" equals "RuntimeError"

Scenario: Que will deliver handled errors
Given I run the service "que" with the command "bundle exec ruby app.rb handled"
And I run the service "que" with the command "timeout 5 bundle exec que ./app.rb"
Given I start the service "que"
When I execute the command "bundle exec ruby app.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
Expand Down
86 changes: 50 additions & 36 deletions features/rails_features/integrations.feature
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
Feature: App type is set correctly for integrations in a Rails app

Background:
Given I start the rails service
And I run the "db:prepare" rake task in the rails app
And I run the "db:migrate" rake task in the rails app

@rails_integrations
Scenario: Delayed job
Given I start the rails service with the database
And I run the "jobs:work" rake task in the rails app in the background
When I run "User.new.delay.raise_the_roof" with the rails runner
And I run the "jobs:workoff" rake task in the rails app
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
Expand All @@ -27,6 +23,7 @@ Scenario: Delayed job

@rails_integrations
Scenario: Mailman
Given I start the rails service
When I run "./run_mailman" in the rails app
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
Expand All @@ -41,8 +38,9 @@ Scenario: Mailman

@rails_integrations
Scenario: Que
Given I start the rails service with the database
And I run "bundle exec que ./config/environment.rb" in the rails app in the background
When I run "QueJob.enqueue" with the rails runner
And I run "timeout 5 bundle exec que ./config/environment.rb" in the rails app
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
Expand All @@ -56,6 +54,7 @@ Scenario: Que

@rails_integrations
Scenario: Rake
Given I start the rails service
When I run the "rake_task:raise" rake task in the rails app
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
Expand All @@ -71,8 +70,9 @@ Scenario: Rake

@rails_integrations
Scenario: Resque (no on_exit hooks)
When I run "Resque.enqueue(ResqueWorker, 123, %(abc), x: true, y: false)" with the rails runner
And I run "timeout --signal QUIT 5 bundle exec rake resque:work" in the rails app
Given I start the rails service
And I run the "resque:work" rake task in the rails app in the background
When I run the "fixture:queue_resque_job" rake task in the rails app
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
Expand All @@ -87,17 +87,21 @@ Scenario: Resque (no on_exit hooks)
And the event "metaData.payload.class" equals "ResqueWorker"
And the event "metaData.payload.args.0" equals 123
And the event "metaData.payload.args.1" equals "abc"
And the event "metaData.payload.args.2.x" is true
And the event "metaData.payload.args.2.y" is false
And the event "metaData.payload.args.2.0" equals 7
And the event "metaData.payload.args.2.1" equals 8
And the event "metaData.payload.args.2.2" equals 9
And the event "metaData.payload.args.3.x" is true
And the event "metaData.payload.args.3.y" is false
And the event "metaData.rake_task.name" equals "resque:work"
And the event "metaData.rake_task.description" equals "Start a Resque worker"
And the event "metaData.rake_task.arguments" is null

@rails_integrations
Scenario: Resque (with on_exit hooks)
Given I set environment variable "RUN_AT_EXIT_HOOKS" to "1"
When I run "Resque.enqueue(ResqueWorker, %(xyz), [7, 8, 9], a: 4, b: 5)" with the rails runner
And I run "timeout --signal QUIT 5 bundle exec rake resque:work" in the rails app
And I start the rails service
And I run the "resque:work" rake task in the rails app in the background
When I run the "fixture:queue_resque_job" rake task in the rails app
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
Expand All @@ -110,20 +114,22 @@ Scenario: Resque (with on_exit hooks)
And the event "metaData.config.delivery_method" equals "thread_queue"
And the event "metaData.context" equals "ResqueWorker@crash"
And the event "metaData.payload.class" equals "ResqueWorker"
And the event "metaData.payload.args.0" equals "xyz"
And the event "metaData.payload.args.1.0" equals 7
And the event "metaData.payload.args.1.1" equals 8
And the event "metaData.payload.args.1.2" equals 9
And the event "metaData.payload.args.2.a" equals 4
And the event "metaData.payload.args.2.b" equals 5
And the event "metaData.payload.args.0" equals 123
And the event "metaData.payload.args.1" equals "abc"
And the event "metaData.payload.args.2.0" equals 7
And the event "metaData.payload.args.2.1" equals 8
And the event "metaData.payload.args.2.2" equals 9
And the event "metaData.payload.args.3.x" is true
And the event "metaData.payload.args.3.y" is false
And the event "metaData.rake_task.name" equals "resque:work"
And the event "metaData.rake_task.description" equals "Start a Resque worker"
And the event "metaData.rake_task.arguments" is null

@rails_integrations
Scenario: Sidekiq
Given I start the rails service
And I run "bundle exec sidekiq" in the rails app in the background
When I run "SidekiqWorker.perform_async" with the rails runner
And I run "timeout 5 bundle exec sidekiq" in the rails app
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
Expand All @@ -140,8 +146,9 @@ Scenario: Sidekiq
@rails_integrations
Scenario: Using Sidekiq as the Active Job queue adapter for a job that raises
Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "sidekiq"
When I run "UnhandledJob.perform_later(1, yes: true)" with the rails runner
And I run "timeout 5 bundle exec sidekiq" in the rails app
And I start the rails service
And I run "bundle exec sidekiq" in the rails app in the background
When I run the "fixture:queue_unhandled_job" rake task in the rails app
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
Expand All @@ -162,8 +169,9 @@ Scenario: Using Sidekiq as the Active Job queue adapter for a job that raises
@rails_integrations
Scenario: Using Resque as the Active Job queue adapter for a job that raises
Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "resque"
When I run "UnhandledJob.perform_later(1, yes: true)" with the rails runner
And I run "timeout --signal QUIT 5 bundle exec rake resque:work" in the rails app
And I start the rails service
And I run the "resque:work" rake task in the rails app in the background
When I run the "fixture:queue_unhandled_job" rake task in the rails app
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
Expand All @@ -183,8 +191,9 @@ Scenario: Using Resque as the Active Job queue adapter for a job that raises
@rails_integrations
Scenario: Using Que as the Active Job queue adapter for a job that raises
Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "que"
When I run "UnhandledJob.perform_later(1, yes: true)" with the rails runner
And I run "timeout 5 bundle exec que -q default ./config/environment.rb" in the rails app
And I start the rails service with the database
And I run "bundle exec que -q default ./config/environment.rb" in the rails app in the background
When I run the "fixture:queue_unhandled_job" rake task in the rails app
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
Expand All @@ -204,8 +213,9 @@ Scenario: Using Que as the Active Job queue adapter for a job that raises
@rails_integrations
Scenario: Using Delayed Job as the Active Job queue adapter for a job that raises
Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "delayed_job"
And I run "UnhandledJob.perform_later(1, yes: true)" with the rails runner
And I run the "jobs:workoff" rake task in the rails app
And I start the rails service with the database
And I run the "jobs:work" rake task in the rails app in the background
When I run the "fixture:queue_unhandled_job" rake task in the rails app
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
Expand All @@ -225,27 +235,31 @@ Scenario: Using Delayed Job as the Active Job queue adapter for a job that raise
@rails_integrations
Scenario: Using Sidekiq as the Active Job queue adapter for a job that works
Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "sidekiq"
And I run "WorkingJob.perform_later" with the rails runner
And I run "timeout 5 bundle exec sidekiq" in the rails app
And I start the rails service
And I run "bundle exec sidekiq" in the rails app in the background
When I run the "fixture:queue_working_job" rake task in the rails app
Then I should receive no requests

@rails_integrations
Scenario: Using Resque as the Active Job queue adapter for a job that works
Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "resque"
And I run "WorkingJob.perform_later" with the rails runner
And I run "timeout --signal QUIT 5 bundle exec rake resque:work" in the rails app
And I start the rails service
And I run "bundle exec rake resque:work" in the rails app in the background
When I run the "fixture:queue_working_job" rake task in the rails app
Then I should receive no requests

@rails_integrations
Scenario: Using Que as the Active Job queue adapter for a job that works
Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "que"
And I run "WorkingJob.perform_later" with the rails runner
And I run "timeout 5 bundle exec que -q default ./config/environment.rb" in the rails app
And I start the rails service with the database
And I run "bundle exec que -q default ./config/environment.rb" in the rails app in the background
When I run the "fixture:queue_working_job" rake task in the rails app
Then I should receive no requests

@rails_integrations
Scenario: Using Delayed Job as the Active Job queue adapter for a job that works
Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "delayed_job"
And I run "WorkingJob.perform_later" with the rails runner
And I run the "jobs:workoff" rake task in the rails app
And I start the rails service with the database
And I run the "jobs:work" rake task in the rails app in the background
When I run the "fixture:queue_working_job" rake task in the rails app
Then I should receive no requests
9 changes: 6 additions & 3 deletions features/sidekiq.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Feature: Bugsnag raises errors in Sidekiq workers

Scenario: An unhandled RuntimeError sends a report
Given I run the service "sidekiq" with the command "timeout 5 bundle exec rake sidekiq_tests:unhandled_error"
Given I start the service "sidekiq"
And I execute the command "bundle exec ruby initializers/UnhandledError.rb" in the service "sidekiq"
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
Expand All @@ -19,7 +20,8 @@ Scenario: An unhandled RuntimeError sends a report
And the event "metaData.config.delivery_method" equals "thread_queue"

Scenario: A handled RuntimeError can be notified
Given I run the service "sidekiq" with the command "timeout 5 bundle exec rake sidekiq_tests:handled_error"
Given I start the service "sidekiq"
And I execute the command "bundle exec ruby initializers/HandledError.rb" in the service "sidekiq"
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
Expand All @@ -35,7 +37,8 @@ Scenario: A handled RuntimeError can be notified

Scenario: Synchronous delivery can be used
Given I set environment variable "BUGSNAG_DELIVERY_METHOD" to "synchronous"
And I run the service "sidekiq" with the command "timeout 5 bundle exec rake sidekiq_tests:handled_error"
And I start the service "sidekiq"
And I execute the command "bundle exec ruby initializers/HandledError.rb" in the service "sidekiq"
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
Expand Down
24 changes: 22 additions & 2 deletions features/steps/ruby_notifier_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,27 @@
}
end

Given("I start the rails service with the database") do
steps %Q{
Given I start the rails service
And I run the "db:prepare" rake task in the rails app
And I run the "db:migrate" rake task in the rails app
}
end

When("I navigate to the route {string} on the rails app") do |route|
RAILS_FIXTURE.navigate_to(route)
end

When("I run {string} in the rails app") do |command|
steps %Q{
When I run the service "rails#{ENV['RAILS_VERSION']}" with the command "#{command}"
When I execute the command "#{command}" in the service "rails#{ENV['RAILS_VERSION']}"
}
end

When("I run {string} in the rails app in the background") do |command|
steps %Q{
When I execute the command "#{command}" in the service "rails#{ENV['RAILS_VERSION']}" in the background
}
end

Expand All @@ -43,9 +57,15 @@
}
end

When("I run the {string} rake task in the rails app in the background") do |task|
steps %Q{
When I run "bundle exec rake #{task}" in the rails app in the background
}
end

When("I run {string} with the rails runner") do |code|
steps %Q{
When I run "bundle exec rails runner '#{code}'" in the rails app
When I execute the command "bundle exec rails runner #{code}" in the service "rails#{ENV['RAILS_VERSION']}"
}
end

Expand Down

0 comments on commit 98f999c

Please sign in to comment.