-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d4e88e
commit 22d6143
Showing
11 changed files
with
200 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
@not-python-3.5 | ||
Feature: Celery | ||
|
||
Scenario: Handled exceptions are delivered | ||
Given I start the service "celery" | ||
When I execute the command "python bugsnag_celery_test_app/queue_task.py handled" in the service "celery" | ||
And I wait to receive an error | ||
Then the error is valid for the error reporting API version "4.0" for the "Python Bugsnag Notifier" notifier | ||
And the exception "errorClass" equals "Exception" | ||
And the exception "message" equals "oooh nooo" | ||
And the event "unhandled" is false | ||
And the event "severity" equals "warning" | ||
And the event "severityReason.type" equals "handledException" | ||
And the event "device.runtimeVersions.celery" matches "5\.\d+\.\d+" | ||
|
||
Scenario: Unhandled exceptions are delivered | ||
Given I start the service "celery" | ||
When I execute the command "python bugsnag_celery_test_app/queue_task.py unhandled" in the service "celery" | ||
And I wait to receive an error | ||
Then the error is valid for the error reporting API version "4.0" for the "Python Bugsnag Notifier" notifier | ||
And the exception "errorClass" equals "KeyError" | ||
And the exception "message" equals "'b'" | ||
And the event "unhandled" is true | ||
And the event "severity" equals "error" | ||
And the event "severityReason.type" equals "unhandledExceptionMiddleware" | ||
And the event "severityReason.attributes.framework" equals "Celery" | ||
And the event "device.runtimeVersions.celery" matches "5\.\d+\.\d+" | ||
And the event "context" equals "bugsnag_celery_test_app.tasks.unhandled" | ||
And the event "metaData.extra_data.task_id" is not null | ||
# these aren't strings but the maze runner step works on arrays and hashes | ||
And the event "metaData.extra_data.args" string is empty | ||
And the event "metaData.extra_data.kwargs" string is empty | ||
|
||
Scenario: Task arguments are added to metadata | ||
Given I start the service "celery" | ||
When I execute the command "python bugsnag_celery_test_app/queue_task.py add 1 2 3 '4' a=100 b=200" in the service "celery" | ||
And I wait to receive an error | ||
Then the error is valid for the error reporting API version "4.0" for the "Python Bugsnag Notifier" notifier | ||
And the exception "errorClass" equals "AssertionError" | ||
And the exception "message" equals "" | ||
And the event "unhandled" is true | ||
And the event "severity" equals "error" | ||
And the event "severityReason.type" equals "unhandledExceptionMiddleware" | ||
And the event "severityReason.attributes.framework" equals "Celery" | ||
And the event "device.runtimeVersions.celery" matches "5\.\d+\.\d+" | ||
And the event "context" equals "bugsnag_celery_test_app.tasks.add" | ||
And the event "metaData.extra_data.task_id" is not null | ||
And the error payload field "events.0.metaData.extra_data.args" is an array with 4 elements | ||
And the event "metaData.extra_data.args.0" equals "1" | ||
And the event "metaData.extra_data.args.1" equals "2" | ||
And the event "metaData.extra_data.args.2" equals "3" | ||
And the event "metaData.extra_data.args.3" equals "4" | ||
And the event "metaData.extra_data.kwargs.a" equals "100" | ||
And the event "metaData.extra_data.kwargs.b" equals "200" | ||
|
||
Scenario: Errors in shared tasks are reported | ||
Given I start the service "celery" | ||
When I execute the command "python bugsnag_celery_test_app/queue_task.py divide 10 0" in the service "celery" | ||
And I wait to receive an error | ||
Then the error is valid for the error reporting API version "4.0" for the "Python Bugsnag Notifier" notifier | ||
And the exception "errorClass" equals "ZeroDivisionError" | ||
And the exception "message" equals "division by zero" | ||
And the event "unhandled" is true | ||
And the event "severity" equals "error" | ||
And the event "severityReason.type" equals "unhandledExceptionMiddleware" | ||
And the event "severityReason.attributes.framework" equals "Celery" | ||
And the event "device.runtimeVersions.celery" matches "5\.\d+\.\d+" | ||
And the event "context" equals "bugsnag_celery_test_app.tasks.divide" | ||
And the event "metaData.extra_data.task_id" is not null | ||
And the error payload field "events.0.metaData.extra_data.args" is an array with 2 elements | ||
And the event "metaData.extra_data.args.0" equals "10" | ||
And the event "metaData.extra_data.args.1" equals "0" | ||
And the event "metaData.extra_data.kwargs" string is empty | ||
|
||
Scenario: Successful tasks do not report errors | ||
Given I start the service "celery" | ||
When I execute the command "python bugsnag_celery_test_app/queue_task.py add 1 2 3 4 5 6 7 a=8 b=9" in the service "celery" | ||
Then I should receive no errors | ||
|
||
Scenario: Successful shared tasks do not report errors | ||
Given I start the service "celery" | ||
When I execute the command "python bugsnag_celery_test_app/queue_task.py divide 10 2" in the service "celery" | ||
Then I should receive no errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ARG PYTHON_TEST_VERSION | ||
FROM python:$PYTHON_TEST_VERSION | ||
|
||
COPY app/ /usr/src/app | ||
COPY temp-bugsnag-python/ /usr/src/bugsnag | ||
|
||
WORKDIR /usr/src/app | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
CMD celery --app bugsnag_celery_test_app.main worker -l INFO |
Empty file.
24 changes: 24 additions & 0 deletions
24
features/fixtures/celery/app/bugsnag_celery_test_app/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
import bugsnag | ||
from celery import Celery | ||
from bugsnag.celery import connect_failure_handler | ||
|
||
|
||
bugsnag.configure( | ||
api_key=os.environ["BUGSNAG_API_KEY"], | ||
endpoint=os.environ["BUGSNAG_ERROR_ENDPOINT"], | ||
session_endpoint=os.environ["BUGSNAG_SESSION_ENDPOINT"], | ||
) | ||
|
||
app = Celery( | ||
'bugsnag_celery_test_app', | ||
broker='redis://redis:6379', | ||
backend='rpc://', | ||
include=['bugsnag_celery_test_app.tasks'], | ||
) | ||
|
||
connect_failure_handler() | ||
|
||
|
||
if __name__ == '__main__': | ||
app.start() |
23 changes: 23 additions & 0 deletions
23
features/fixtures/celery/app/bugsnag_celery_test_app/queue_task.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import sys | ||
import json | ||
import bugsnag_celery_test_app.tasks as tasks | ||
|
||
|
||
if __name__ == '__main__': | ||
task = sys.argv[1] | ||
arguments = [] | ||
keyword_arguments = {} | ||
|
||
if len(sys.argv) > 2: | ||
raw_arguments = sys.argv[2:] | ||
|
||
for argument in raw_arguments: | ||
if '=' in argument: | ||
key, value = argument.split('=') | ||
keyword_arguments[key] = value | ||
else: | ||
arguments.append(argument) | ||
|
||
print("~*~ Queueing task '%s' with args: [%s] and kwargs: %s" % (task, ", ".join(arguments), json.dumps(keyword_arguments))) | ||
|
||
getattr(tasks, task).delay(*arguments, **keyword_arguments) |
34 changes: 34 additions & 0 deletions
34
features/fixtures/celery/app/bugsnag_celery_test_app/tasks.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import bugsnag | ||
from celery import shared_task | ||
from bugsnag_celery_test_app.main import app | ||
|
||
|
||
@app.task | ||
def handled(): | ||
bugsnag.notify(Exception('oooh nooo')) | ||
|
||
return 'hello world' | ||
|
||
|
||
@app.task | ||
def unhandled(): | ||
a = {} | ||
|
||
return a['b'] | ||
|
||
|
||
@app.task | ||
def add(*args, a, b): | ||
total = int(a) + int(b) | ||
|
||
for arg in args: | ||
total += int(arg) | ||
|
||
assert total < 100 | ||
|
||
return total | ||
|
||
|
||
@shared_task | ||
def divide(a, b): | ||
return int(a) / int(b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
. | ||
../bugsnag | ||
celery[redis] | ||
importlib-metadata<5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from setuptools import setup | ||
|
||
setup(name="bugsnag_celery_test_app", packages=["bugsnag_celery_test_app"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.