Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: App-type fixtures #532

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions features/delayed_job.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Scenario: An unhandled RuntimeError sends a report with arguments
And the event "context" equals "TestModel.fail_with_args"
And the event "severityReason.type" equals "unhandledExceptionMiddleware"
And the event "severityReason.attributes.framework" equals "DelayedJob"
And the event "app.type" equals "delayed_job"
And the exception "errorClass" equals "RuntimeError"
And the event "metaData.job.class" equals "Delayed::Backend::ActiveRecord::Job"
And the event "metaData.job.id" is not null
Expand All @@ -41,6 +42,7 @@ Scenario: A handled exception sends a report
And the event "severity" equals "warning"
And the event "context" equals "TestModel.notify_with_args"
And the event "severityReason.type" equals "handledException"
And the event "app.type" equals "delayed_job"
And the exception "errorClass" equals "RuntimeError"
And the event "metaData.job.class" equals "Delayed::Backend::ActiveRecord::Job"
And the event "metaData.job.id" is not null
Expand Down
53 changes: 53 additions & 0 deletions features/fixtures/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ services:
redis:
image: redis

postgres:
image: postgres
environment:
- POSTGRES_PASSWORD=test_password

mongo:
image: mongo

Expand Down Expand Up @@ -272,3 +277,51 @@ services:
ports:
- "3007:3000"
restart: "no"

mailman:
build:
context: mailman
args:
- RUBY_VERSION
- APP_PATH
- TEST_EMAIL
environment:
- BUGSNAG_API_KEY
- BUGSNAG_ENDPOINT
ports:
- "6245:6245"
restart: "no"

rack:
imjoehaines marked this conversation as resolved.
Show resolved Hide resolved
build:
context: rack
args:
- RUBY_VERSION
environment:
- BUGSNAG_API_KEY
- BUGSNAG_ENDPOINT
ports:
- "3008:8080"
restart: 'no'

rake:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not add a rake task in a rails app?

build:
context: rake
args:
- RUBY_VERSION
environment:
- BUGSNAG_API_KEY
- BUGSNAG_ENDPOINT
restart: 'no'

que:
build:
context: que
args:
- RUBY_VERSION
depends_on:
- postgres
environment:
- BUGSNAG_API_KEY
- BUGSNAG_ENDPOINT
restart: 'no'
2 changes: 2 additions & 0 deletions features/fixtures/mailman/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Gemfile.lock
imjoehaines marked this conversation as resolved.
Show resolved Hide resolved
payloads/
18 changes: 18 additions & 0 deletions features/fixtures/mailman/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION

WORKDIR /bugsnag
COPY temp-bugsnag-lib ./

ARG APP_PATH

WORKDIR $APP_PATH

COPY app/Gemfile .
RUN bundle install

COPY app/ .

ARG TEST_EMAIL
RUN cp $TEST_EMAIL "./target.eml"
CMD "./run.sh"
10 changes: 10 additions & 0 deletions features/fixtures/mailman/app/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source 'https://rubygems.org'

gem 'bugsnag', path: '/bugsnag'
gem 'mailman'
gem 'hitimes', '~> 1.2.6'
gem 'i18n', '~> 0.9.5'
gem 'rb-inotify', '0.9.8'
gem 'maildir', '~> 2.1.0'
gem 'activesupport', '~> 3.2'
gem 'rack', '~> 1.6.11'
26 changes: 26 additions & 0 deletions features/fixtures/mailman/app/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'mailman'
require 'bugsnag'
require 'pp'
Cawllec marked this conversation as resolved.
Show resolved Hide resolved

Bugsnag.configure do |conf|
puts "Configuring `api_key` to #{ENV['BUGSNAG_API_KEY']}"
conf.api_key = ENV['BUGSNAG_API_KEY']
puts "Configuring `endpoint` to #{ENV['BUGSNAG_ENDPOINT']}"
conf.endpoint = ENV['BUGSNAG_ENDPOINT']
end

Mailman.config.ignore_stdin = false

Mailman::Application.run do
subject "Unhandled" do
raise RuntimeError.new("Unhandled exception")
end

subject "Handled" do
begin
raise RuntimeError.new("Handled exception")
rescue => exception
Bugsnag.notify(exception)
end
end
end
19 changes: 19 additions & 0 deletions features/fixtures/mailman/app/emails/Handled.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MIME-Version: 1.0
imjoehaines marked this conversation as resolved.
Show resolved Hide resolved
Date: Mon, 4 Feb 2019 17:54:01 +0000
Message-ID: <CABpr-1gRk_ueV0LBvFVdeWPG5Tt4feVvB14iMB_FTfKgKrwt-w@mail.gmail.com>
Subject: Handled
From: Test <Test@maze-runner.mail>
To: "Test@maze-runner.mail" <Test@maze-runner.mail>
Content-Type: multipart/alternative; boundary="0000000000008ead860581152db1"

--0000000000008ead860581152db1
Content-Type: text/plain; charset="UTF-8"

test

--0000000000008ead860581152db1
Content-Type: text/html; charset="UTF-8"

<div dir="ltr">test</div>

--0000000000008ead860581152db1--
19 changes: 19 additions & 0 deletions features/fixtures/mailman/app/emails/Unhandled.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MIME-Version: 1.0
imjoehaines marked this conversation as resolved.
Show resolved Hide resolved
Date: Mon, 4 Feb 2019 17:54:01 +0000
Message-ID: <CABpr-1gRk_ueV0LBvFVdeWPG5Tt4feVvB14iMB_FTfKgKrwt-w@mail.gmail.com>
Subject: Unhandled
From: Test <Test@maze-runner.mail>
To: "Test@maze-runner.mail" <Test@maze-runner.mail>
Content-Type: multipart/alternative; boundary="0000000000008ead860581152db1"

--0000000000008ead860581152db1
Content-Type: text/plain; charset="UTF-8"

test

--0000000000008ead860581152db1
Content-Type: text/html; charset="UTF-8"

<div dir="ltr">test</div>

--0000000000008ead860581152db1--
1 change: 1 addition & 0 deletions features/fixtures/mailman/app/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cat target.eml | bundle exec ruby app.rb
imjoehaines marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions features/fixtures/que/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app/Gemfile.lock
imjoehaines marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 14 additions & 0 deletions features/fixtures/que/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION

ARG RUBY_VERSION
imjoehaines marked this conversation as resolved.
Show resolved Hide resolved
FROM ruby:$RUBY_VERSION

WORKDIR /bugsnag
COPY temp-bugsnag-lib ./

WORKDIR /usr/src/app
COPY app/Gemfile /usr/src/app/
RUN bundle install

COPY app/ /usr/src/app
9 changes: 9 additions & 0 deletions features/fixtures/que/app/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source "https://rubygems.org"

gem "bugsnag", path: "/bugsnag"

gem "que", "~> 0.14.3"

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"
47 changes: 47 additions & 0 deletions features/fixtures/que/app/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'pg'
require 'que'
require 'bugsnag'
require 'active_record'

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

ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
database: 'postgres',
username: 'postgres',
password: 'test_password',
host: 'postgres'
)

Que.connection = ActiveRecord
Que.migrate!(version: 3)

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
1 change: 1 addition & 0 deletions features/fixtures/rack/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app/Gemfile.lock
imjoehaines marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions features/fixtures/rack/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION

ARG RUBY_VERSION
imjoehaines marked this conversation as resolved.
Show resolved Hide resolved
FROM ruby:$RUBY_VERSION

WORKDIR /bugsnag
COPY temp-bugsnag-lib ./

WORKDIR /usr/src/app
COPY app/Gemfile /usr/src/app/
RUN bundle install

COPY app/ /usr/src/app

CMD ["bundle", "exec", "ruby", "server.rb"]
5 changes: 5 additions & 0 deletions features/fixtures/rack/app/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gem 'bugsnag', path: '/bugsnag'

gem 'rack', RUBY_VERSION <= '2.2.0' ? '1.6.2': '>1.6.2'
35 changes: 35 additions & 0 deletions features/fixtures/rack/app/server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'rack'
require 'rack/request'
require 'rack/response'

require 'bugsnag'


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

class BugsnagTests
def call(env)
req = Rack::Request.new(env)

case req.env['REQUEST_PATH']
when '/unhandled'
raise RuntimeError.new('Unhandled error')
when '/handled'
begin
raise RuntimeError.new('Handled error')
rescue => exception
Bugsnag.notify(exception)
end
end

res = Rack::Response.new
res.finish
end
end

Rack::Server.start(app: Bugsnag::Rack.new(BugsnagTests.new), Host: '0.0.0.0', Port: 8080)
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
class AppTypeController < ActionController::Base
protect_from_forgery

def index
def default_handled
raise RuntimeError.new ("Handled error")
rescue Exception => e
Bugsnag.notify(e)
render json: {}
end

def default_unhandled
raise RuntimeError.new ("Unhandled error")
end

def initializer
Bugsnag.notify("handled string")
render json: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
class AppTypeController < ActionController::Base
protect_from_forgery

def index
def default_handled
raise RuntimeError.new ("Handled error")
rescue Exception => e
Bugsnag.notify(e)
render json: {}
end

def default_unhandled
raise RuntimeError.new ("Unhandled error")
end

def initializer
Bugsnag.notify("handled string")
render json: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
class AppTypeController < ActionController::Base
protect_from_forgery

def default_handled
raise RuntimeError.new ("Handled error")
rescue Exception => e
Bugsnag.notify(e)
render json: {}
end

def default_unhandled
raise RuntimeError.new ("Unhandled error")
end

def initializer
Bugsnag.notify("handled string")
render json: {}
Expand Down
2 changes: 2 additions & 0 deletions features/fixtures/rails5/app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
get 'api_key/environment', to: 'api_key#environment'
get 'api_key/changing', to: 'api_key#changing'

get 'app_type/default_handled', to: 'app_type#default_handled'
get 'app_type/default_unhandled', to: 'app_type#default_unhandled'
get 'app_type/initializer', to: 'app_type#initializer'
get 'app_type/after', to: 'app_type#after'

Expand Down
1 change: 1 addition & 0 deletions features/fixtures/rake/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app/Gemfile.lock
Loading