Skip to content

Commit 00b79fa

Browse files
committed
Port Celery tests to Maze Runner
1 parent 2d4e88e commit 00b79fa

File tree

11 files changed

+269
-231
lines changed

11 files changed

+269
-231
lines changed

features/celery.feature

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
Feature: Celery
2+
3+
Scenario Outline: Handled exceptions are delivered in Celery <celery-version>
4+
Given I start the service "celery-<celery-version>"
5+
When I execute the command "python bugsnag_celery_test_app/queue_task.py handled" in the service "celery-<celery-version>"
6+
And I wait to receive an error
7+
Then the error is valid for the error reporting API version "4.0" for the "Python Bugsnag Notifier" notifier
8+
And the exception "errorClass" equals "Exception"
9+
And the exception "message" equals "oooh nooo"
10+
And the event "unhandled" is false
11+
And the event "severity" equals "warning"
12+
And the event "severityReason.type" equals "handledException"
13+
And the event "device.runtimeVersions.celery" matches "<celery-version>\.\d+\.\d+"
14+
15+
@not-python-3.11 @not-python-3.12
16+
Examples:
17+
| celery-version |
18+
| 4 |
19+
20+
@not-python-3.5
21+
Examples:
22+
| celery-version |
23+
| 5 |
24+
25+
Scenario Outline: Unhandled exceptions are delivered in Celery <celery-version>
26+
Given I start the service "celery-<celery-version>"
27+
When I execute the command "python bugsnag_celery_test_app/queue_task.py unhandled" in the service "celery-<celery-version>"
28+
And I wait to receive an error
29+
Then the error is valid for the error reporting API version "4.0" for the "Python Bugsnag Notifier" notifier
30+
And the exception "errorClass" equals "KeyError"
31+
And the exception "message" equals "'b'"
32+
And the event "unhandled" is true
33+
And the event "severity" equals "error"
34+
And the event "severityReason.type" equals "unhandledExceptionMiddleware"
35+
And the event "severityReason.attributes.framework" equals "Celery"
36+
And the event "device.runtimeVersions.celery" matches "<celery-version>\.\d+\.\d+"
37+
And the event "context" equals "bugsnag_celery_test_app.tasks.unhandled"
38+
And the event "metaData.extra_data.task_id" is not null
39+
# these aren't strings but the maze runner step works on arrays and hashes
40+
And the event "metaData.extra_data.args" string is empty
41+
And the event "metaData.extra_data.kwargs" string is empty
42+
43+
@not-python-3.11 @not-python-3.12
44+
Examples:
45+
| celery-version |
46+
| 4 |
47+
48+
@not-python-3.5
49+
Examples:
50+
| celery-version |
51+
| 5 |
52+
53+
Scenario Outline: Task arguments are added to metadata in Celery <celery-version>
54+
Given I start the service "celery-<celery-version>"
55+
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-<celery-version>"
56+
And I wait to receive an error
57+
Then the error is valid for the error reporting API version "4.0" for the "Python Bugsnag Notifier" notifier
58+
And the exception "errorClass" equals "AssertionError"
59+
And the exception "message" equals ""
60+
And the event "unhandled" is true
61+
And the event "severity" equals "error"
62+
And the event "severityReason.type" equals "unhandledExceptionMiddleware"
63+
And the event "severityReason.attributes.framework" equals "Celery"
64+
And the event "device.runtimeVersions.celery" matches "<celery-version>\.\d+\.\d+"
65+
And the event "context" equals "bugsnag_celery_test_app.tasks.add"
66+
And the event "metaData.extra_data.task_id" is not null
67+
And the error payload field "events.0.metaData.extra_data.args" is an array with 4 elements
68+
And the event "metaData.extra_data.args.0" equals "1"
69+
And the event "metaData.extra_data.args.1" equals "2"
70+
And the event "metaData.extra_data.args.2" equals "3"
71+
And the event "metaData.extra_data.args.3" equals "4"
72+
And the event "metaData.extra_data.kwargs.a" equals "100"
73+
And the event "metaData.extra_data.kwargs.b" equals "200"
74+
75+
@not-python-3.11 @not-python-3.12
76+
Examples:
77+
| celery-version |
78+
| 4 |
79+
80+
@not-python-3.5
81+
Examples:
82+
| celery-version |
83+
| 5 |
84+
85+
Scenario Outline: Errors in shared tasks are reported in Celery <celery-version>
86+
Given I start the service "celery-<celery-version>"
87+
When I execute the command "python bugsnag_celery_test_app/queue_task.py divide 10 0" in the service "celery-<celery-version>"
88+
And I wait to receive an error
89+
Then the error is valid for the error reporting API version "4.0" for the "Python Bugsnag Notifier" notifier
90+
And the exception "errorClass" equals "ZeroDivisionError"
91+
And the exception "message" equals "division by zero"
92+
And the event "unhandled" is true
93+
And the event "severity" equals "error"
94+
And the event "severityReason.type" equals "unhandledExceptionMiddleware"
95+
And the event "severityReason.attributes.framework" equals "Celery"
96+
And the event "device.runtimeVersions.celery" matches "<celery-version>\.\d+\.\d+"
97+
And the event "context" equals "bugsnag_celery_test_app.tasks.divide"
98+
And the event "metaData.extra_data.task_id" is not null
99+
And the error payload field "events.0.metaData.extra_data.args" is an array with 2 elements
100+
And the event "metaData.extra_data.args.0" equals "10"
101+
And the event "metaData.extra_data.args.1" equals "0"
102+
And the event "metaData.extra_data.kwargs" string is empty
103+
104+
@not-python-3.11 @not-python-3.12
105+
Examples:
106+
| celery-version |
107+
| 4 |
108+
109+
@not-python-3.5
110+
Examples:
111+
| celery-version |
112+
| 5 |
113+
114+
Scenario Outline: Successful tasks do not report errors in Celery <celery-version>
115+
Given I start the service "celery-<celery-version>"
116+
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-<celery-version>"
117+
Then I should receive no errors
118+
119+
@not-python-3.11 @not-python-3.12
120+
Examples:
121+
| celery-version |
122+
| 4 |
123+
124+
@not-python-3.5
125+
Examples:
126+
| celery-version |
127+
| 5 |
128+
129+
Scenario Outline: Successful shared tasks do not report errors in Celery <celery-version>
130+
Given I start the service "celery-<celery-version>"
131+
When I execute the command "python bugsnag_celery_test_app/queue_task.py divide 10 2" in the service "celery-<celery-version>"
132+
Then I should receive no errors
133+
134+
@not-python-3.11 @not-python-3.12
135+
Examples:
136+
| celery-version |
137+
| 4 |
138+
139+
@not-python-3.5
140+
Examples:
141+
| celery-version |
142+
| 5 |

features/fixtures/celery/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ARG PYTHON_TEST_VERSION
2+
FROM python:$PYTHON_TEST_VERSION
3+
4+
COPY app/ /usr/src/app
5+
COPY temp-bugsnag-python/ /usr/src/bugsnag
6+
7+
WORKDIR /usr/src/app
8+
9+
ARG CELERY_TEST_VERSION
10+
RUN CELERY_TEST_VERSION=$CELERY_TEST_VERSION pip install --no-cache-dir -r requirements.txt
11+
12+
CMD celery --app bugsnag_celery_test_app.main worker -l INFO

features/fixtures/celery/app/bugsnag_celery_test_app/__init__.py

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
import bugsnag
3+
from celery import Celery
4+
from bugsnag.celery import connect_failure_handler
5+
6+
7+
bugsnag.configure(
8+
api_key=os.environ["BUGSNAG_API_KEY"],
9+
endpoint=os.environ["BUGSNAG_ERROR_ENDPOINT"],
10+
session_endpoint=os.environ["BUGSNAG_SESSION_ENDPOINT"],
11+
)
12+
13+
app = Celery(
14+
'bugsnag_celery_test_app',
15+
broker='redis://redis:6379',
16+
backend='rpc://',
17+
include=['bugsnag_celery_test_app.tasks'],
18+
)
19+
20+
connect_failure_handler()
21+
22+
23+
if __name__ == '__main__':
24+
app.start()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
import json
3+
import bugsnag_celery_test_app.tasks as tasks
4+
5+
6+
if __name__ == '__main__':
7+
task = sys.argv[1]
8+
arguments = []
9+
keyword_arguments = {}
10+
11+
if len(sys.argv) > 2:
12+
raw_arguments = sys.argv[2:]
13+
14+
for argument in raw_arguments:
15+
if '=' in argument:
16+
key, value = argument.split('=')
17+
keyword_arguments[key] = value
18+
else:
19+
arguments.append(argument)
20+
21+
print("~*~ Queueing task '%s' with args: [%s] and kwargs: %s" % (task, ", ".join(arguments), json.dumps(keyword_arguments)))
22+
23+
getattr(tasks, task).delay(*arguments, **keyword_arguments)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import bugsnag
2+
from celery import shared_task
3+
from bugsnag_celery_test_app.main import app
4+
5+
6+
@app.task
7+
def handled():
8+
bugsnag.notify(Exception('oooh nooo'))
9+
10+
return 'hello world'
11+
12+
13+
@app.task
14+
def unhandled():
15+
a = {}
16+
17+
return a['b']
18+
19+
20+
@app.task
21+
def add(*args, a, b):
22+
total = int(a) + int(b)
23+
24+
for arg in args:
25+
total += int(arg)
26+
27+
assert total < 100
28+
29+
return total
30+
31+
32+
@shared_task
33+
def divide(a, b):
34+
return int(a) / int(b)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.
2+
../bugsnag
3+
celery[redis]${CELERY_TEST_VERSION}
4+
importlib-metadata<5.0

features/fixtures/celery/app/setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from setuptools import setup
2+
3+
setup(name="bugsnag_celery_test_app", packages=["bugsnag_celery_test_app"])

features/fixtures/docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
version: "3.8"
22

33
services:
4+
redis:
5+
image: redis
6+
47
plain:
58
build:
69
context: plain
@@ -27,3 +30,26 @@ services:
2730
volumes:
2831
- "/var/run/docker.sock:/var/run/docker.sock"
2932
- "./aws-lambda/app:/usr/src/app"
33+
34+
celery-4: &celery
35+
build:
36+
context: celery
37+
args:
38+
- PYTHON_TEST_VERSION
39+
- CELERY_TEST_VERSION=>=4,<5
40+
environment:
41+
- BUGSNAG_API_KEY
42+
- BUGSNAG_ERROR_ENDPOINT
43+
- BUGSNAG_SESSION_ENDPOINT
44+
extra_hosts:
45+
- "host.docker.internal:host-gateway"
46+
depends_on:
47+
- redis
48+
49+
celery-5:
50+
<<: *celery
51+
build:
52+
context: celery
53+
args:
54+
- PYTHON_TEST_VERSION
55+
- CELERY_TEST_VERSION=>=5,<6

0 commit comments

Comments
 (0)