-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-genshi-testing
- Loading branch information
Showing
6 changed files
with
250 additions
and
13 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
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,54 @@ | ||
# Copyright 2010 New Relic, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from threading import Thread | ||
from time import sleep | ||
|
||
from testing_support.sample_applications import ( | ||
raise_exception_application, | ||
raise_exception_finalize, | ||
raise_exception_response, | ||
simple_app_raw, | ||
) | ||
from testing_support.util import get_open_port | ||
|
||
|
||
def sample_application(environ, start_response): | ||
path_info = environ.get("PATH_INFO") | ||
|
||
if path_info.startswith("/raise-exception-application"): | ||
return raise_exception_application(environ, start_response) | ||
elif path_info.startswith("/raise-exception-response"): | ||
return raise_exception_response(environ, start_response) | ||
elif path_info.startswith("/raise-exception-finalize"): | ||
return raise_exception_finalize(environ, start_response) | ||
|
||
return simple_app_raw(environ, start_response) | ||
|
||
|
||
def setup_application(): | ||
port = get_open_port() | ||
|
||
def run_wsgi(): | ||
from waitress import serve | ||
|
||
serve(sample_application, host="127.0.0.1", port=port) | ||
|
||
wsgi_thread = Thread(target=run_wsgi) | ||
wsgi_thread.daemon = True | ||
wsgi_thread.start() | ||
|
||
sleep(1) | ||
|
||
return port |
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,40 @@ | ||
# Copyright 2010 New Relic, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pytest | ||
import webtest | ||
from testing_support.fixtures import ( # noqa: F401; pylint: disable=W0611 | ||
collector_agent_registration_fixture, | ||
collector_available_fixture, | ||
) | ||
|
||
_default_settings = { | ||
"transaction_tracer.explain_threshold": 0.0, | ||
"transaction_tracer.transaction_threshold": 0.0, | ||
"transaction_tracer.stack_trace_threshold": 0.0, | ||
"debug.log_data_collector_payloads": True, | ||
"debug.record_transaction_failure": True, | ||
} | ||
|
||
collector_agent_registration = collector_agent_registration_fixture( | ||
app_name="Python Agent Test (Waitress)", default_settings=_default_settings | ||
) | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="session") | ||
def target_application(): | ||
import _application | ||
|
||
port = _application.setup_application() | ||
return webtest.TestApp("http://localhost:%d" % port) |
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,101 @@ | ||
# Copyright 2010 New Relic, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
from testing_support.fixtures import ( | ||
override_application_settings, | ||
raise_background_exceptions, | ||
wait_for_background_threads, | ||
) | ||
from testing_support.validators.validate_transaction_errors import ( | ||
validate_transaction_errors, | ||
) | ||
from testing_support.validators.validate_transaction_metrics import ( | ||
validate_transaction_metrics, | ||
) | ||
|
||
from newrelic.common.package_version_utils import get_package_version | ||
|
||
WAITRESS_VERSION = get_package_version("waitress") | ||
|
||
|
||
@override_application_settings({"transaction_name.naming_scheme": "framework"}) | ||
def test_wsgi_application_index(target_application): | ||
@validate_transaction_metrics( | ||
"_application:sample_application", | ||
custom_metrics=[ | ||
("Python/Dispatcher/Waitress/%s" % WAITRESS_VERSION, 1), | ||
], | ||
) | ||
@raise_background_exceptions() | ||
@wait_for_background_threads() | ||
def _test(): | ||
response = target_application.get("/") | ||
assert response.status == "200 OK" | ||
|
||
_test() | ||
|
||
|
||
@override_application_settings({"transaction_name.naming_scheme": "framework"}) | ||
def test_raise_exception_application(target_application): | ||
@validate_transaction_errors(["builtins:RuntimeError"]) | ||
@validate_transaction_metrics( | ||
"_application:sample_application", | ||
custom_metrics=[ | ||
("Python/Dispatcher/Waitress/%s" % WAITRESS_VERSION, 1), | ||
], | ||
) | ||
@raise_background_exceptions() | ||
@wait_for_background_threads() | ||
def _test(): | ||
response = target_application.get("/raise-exception-application/", status=500) | ||
assert response.status == "500 Internal Server Error" | ||
|
||
_test() | ||
|
||
|
||
@override_application_settings({"transaction_name.naming_scheme": "framework"}) | ||
def test_raise_exception_response(target_application): | ||
@validate_transaction_errors(["builtins:RuntimeError"]) | ||
@validate_transaction_metrics( | ||
"_application:sample_application", | ||
custom_metrics=[ | ||
("Python/Dispatcher/Waitress/%s" % WAITRESS_VERSION, 1), | ||
], | ||
) | ||
@raise_background_exceptions() | ||
@wait_for_background_threads() | ||
def _test(): | ||
response = target_application.get("/raise-exception-response/", status=500) | ||
assert response.status == "500 Internal Server Error" | ||
|
||
_test() | ||
|
||
|
||
@override_application_settings({"transaction_name.naming_scheme": "framework"}) | ||
def test_raise_exception_finalize(target_application): | ||
@validate_transaction_errors(["builtins:RuntimeError"]) | ||
@validate_transaction_metrics( | ||
"_application:sample_application", | ||
custom_metrics=[ | ||
("Python/Dispatcher/Waitress/%s" % WAITRESS_VERSION, 1), | ||
], | ||
) | ||
@raise_background_exceptions() | ||
@wait_for_background_threads() | ||
def _test(): | ||
response = target_application.get("/raise-exception-finalize/", status=500) | ||
assert response.status == "500 Internal Server Error" | ||
|
||
_test() |
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
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