-
Notifications
You must be signed in to change notification settings - Fork 555
Remove forked from test_transport, separate gevent tests and generalize capturing_server to be module level #4577
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
Open
sl0thentr0py
wants to merge
1
commit into
master
Choose a base branch
from
neel/forked/transport
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+192
−72
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,118 @@ | ||
import logging | ||
import pickle | ||
from datetime import datetime, timezone | ||
|
||
import sentry_sdk | ||
from sentry_sdk._compat import PY37, PY38 | ||
|
||
import pytest | ||
from tests.conftest import CapturingServer | ||
|
||
pytest.importorskip("gevent") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def monkeypatched_gevent(): | ||
try: | ||
import gevent | ||
|
||
gevent.monkey.patch_all() | ||
except Exception as e: | ||
if "_RLock__owner" in str(e): | ||
pytest.skip("https://github.com/gevent/gevent/issues/1380") | ||
else: | ||
raise | ||
|
||
|
||
@pytest.fixture | ||
def capturing_server(request): | ||
server = CapturingServer() | ||
server.start() | ||
request.addfinalizer(server.stop) | ||
return server | ||
|
||
|
||
@pytest.fixture | ||
def make_client(request, capturing_server): | ||
def inner(**kwargs): | ||
return sentry_sdk.Client( | ||
"http://foobar@{}/132".format(capturing_server.url[len("http://") :]), | ||
**kwargs, | ||
) | ||
|
||
return inner | ||
|
||
|
||
@pytest.mark.forked | ||
@pytest.mark.parametrize("debug", (True, False)) | ||
@pytest.mark.parametrize("client_flush_method", ["close", "flush"]) | ||
@pytest.mark.parametrize("use_pickle", (True, False)) | ||
@pytest.mark.parametrize("compression_level", (0, 9, None)) | ||
@pytest.mark.parametrize( | ||
"compression_algo", | ||
(("gzip", "br", "<invalid>", None) if PY37 else ("gzip", "<invalid>", None)), | ||
) | ||
@pytest.mark.parametrize("http2", [True, False] if PY38 else [False]) | ||
def test_transport_works_gevent( | ||
capturing_server, | ||
request, | ||
capsys, | ||
caplog, | ||
debug, | ||
make_client, | ||
client_flush_method, | ||
use_pickle, | ||
compression_level, | ||
compression_algo, | ||
http2, | ||
): | ||
caplog.set_level(logging.DEBUG) | ||
|
||
experiments = {} | ||
if compression_level is not None: | ||
experiments["transport_compression_level"] = compression_level | ||
|
||
if compression_algo is not None: | ||
experiments["transport_compression_algo"] = compression_algo | ||
|
||
if http2: | ||
experiments["transport_http2"] = True | ||
|
||
client = make_client( | ||
debug=debug, | ||
_experiments=experiments, | ||
) | ||
|
||
if use_pickle: | ||
client = pickle.loads(pickle.dumps(client)) | ||
|
||
sentry_sdk.get_global_scope().set_client(client) | ||
request.addfinalizer(lambda: sentry_sdk.get_global_scope().set_client(None)) | ||
|
||
sentry_sdk.add_breadcrumb( | ||
level="info", message="i like bread", timestamp=datetime.now(timezone.utc) | ||
) | ||
sentry_sdk.capture_message("löl") | ||
|
||
getattr(client, client_flush_method)() | ||
|
||
out, err = capsys.readouterr() | ||
assert not err and not out | ||
assert capturing_server.captured | ||
should_compress = ( | ||
# default is to compress with brotli if available, gzip otherwise | ||
(compression_level is None) | ||
or ( | ||
# setting compression level to 0 means don't compress | ||
compression_level | ||
> 0 | ||
) | ||
) and ( | ||
# if we couldn't resolve to a known algo, we don't compress | ||
compression_algo | ||
!= "<invalid>" | ||
) | ||
|
||
assert capturing_server.captured[0].compressed == should_compress | ||
|
||
assert any("Sending envelope" in record.msg for record in caplog.records) == debug |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ultimately, I want to isolate all gevent tests here so they don't leak into the rest of the codebase