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 all 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
47 changes: 45 additions & 2 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 @@ -75,7 +80,8 @@ services:
args:
- RUBY_VERSION
environment:
- endpoint
- BUGSNAG_API_KEY
- BUGSNAG_ENDPOINT
ports:
- "3001:3000"
restart: "no"
Expand All @@ -85,7 +91,8 @@ services:
args:
- RUBY_VERSION
environment:
- endpoint
- BUGSNAG_API_KEY
- BUGSNAG_ENDPOINT
ports:
- "3002:3000"
restart: "no"
Expand Down Expand Up @@ -272,3 +279,39 @@ services:
ports:
- "3007:3000"
restart: "no"

mailman:
build:
context: mailman
args:
- RUBY_VERSION
- APP_PATH
environment:
- BUGSNAG_API_KEY
- BUGSNAG_ENDPOINT
- TARGET_EMAIL
ports:
- "6245:6245"
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/
16 changes: 16 additions & 0 deletions features/fixtures/mailman/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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/ .

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

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--
2 changes: 2 additions & 0 deletions features/fixtures/mailman/app/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
cat $TARGET_EMAIL | bundle exec ruby app.rb
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
11 changes: 11 additions & 0 deletions features/fixtures/que/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ARG RUBY_VERSION
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
2 changes: 1 addition & 1 deletion features/fixtures/rack1/.dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Gemfile.lock
app/Gemfile.lock
2 changes: 1 addition & 1 deletion features/fixtures/rack1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ RUN bundle install

COPY app/ /usr/src/app

CMD ["ruby", "app.rb"]
CMD ["bundle", "exec", "ruby", "app.rb"]
8 changes: 0 additions & 8 deletions features/fixtures/rack1/app.rb

This file was deleted.

File renamed without changes.
33 changes: 33 additions & 0 deletions features/fixtures/rack1/app/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'bugsnag'
require 'rack'

puts "HERE"

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: 3000)
2 changes: 1 addition & 1 deletion features/fixtures/rack2/.dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Gemfile.lock
app/Gemfile.lock
2 changes: 1 addition & 1 deletion features/fixtures/rack2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ RUN bundle install

COPY app/ /usr/src/app

CMD ["ruby", "app.rb"]
CMD ["bundle", "exec", "ruby", "app.rb"]
8 changes: 0 additions & 8 deletions features/fixtures/rack2/app.rb

This file was deleted.

File renamed without changes.
32 changes: 32 additions & 0 deletions features/fixtures/rack2/app/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'bugsnag'
require 'rack'


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: 3000)
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
Loading