-
Notifications
You must be signed in to change notification settings - Fork 34
test: Cover gevent autotracing #544
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
Merged
Merged
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,71 @@ | ||
| # (c) Copyright IBM Corp. 2021 | ||
| # (c) Copyright Instana Inc. 2020 | ||
|
|
||
| import importlib | ||
| import os | ||
| import unittest | ||
| import socket | ||
|
|
||
| import gevent | ||
| from gevent import monkey | ||
| from instana import apply_gevent_monkey_patch | ||
|
|
||
|
|
||
| class TestGEventAutoTrace(unittest.TestCase): | ||
| def setUp(self): | ||
| # Ensure that the test suite is operational even when Django is installed | ||
| # but not running or configured | ||
| os.environ['DJANGO_SETTINGS_MODULE'] = '' | ||
|
|
||
| self.default_patched_modules = ('socket', 'time', 'select', 'os', | ||
| 'threading', 'ssl', 'subprocess', 'signal', 'queue',) | ||
|
|
||
| def tearDown(self): | ||
| if os.environ.get('INSTANA_GEVENT_MONKEY_OPTIONS'): | ||
| os.environ.pop('INSTANA_GEVENT_MONKEY_OPTIONS') | ||
|
|
||
| # Clean up after gevent monkey patches, by restore from the saved dict | ||
| for modname in monkey.saved.keys(): | ||
| try: | ||
| mod = __import__(modname) | ||
| importlib.reload(mod) | ||
| for key in monkey.saved[modname].keys(): | ||
| setattr(mod, key, monkey.saved[modname][key]) | ||
| except ImportError: | ||
| pass | ||
| monkey.saved = {} | ||
|
|
||
|
|
||
| def test_default_patch_all(self): | ||
| apply_gevent_monkey_patch() | ||
| for module_name in self.default_patched_modules: | ||
| self.assertTrue(monkey.is_module_patched(module_name), | ||
| f"{module_name} is not patched") | ||
|
|
||
| def test_instana_monkey_options_only_time(self): | ||
| os.environ['INSTANA_GEVENT_MONKEY_OPTIONS'] = ( | ||
| 'time,no-socket,no-select,no-os,no-select,no-threading,no-os,' | ||
| 'no-ssl,no-subprocess,''no-signal,no-queue') | ||
| apply_gevent_monkey_patch() | ||
|
|
||
| self.assertTrue(monkey.is_module_patched('time'), "time module is not patched") | ||
| not_patched_modules = (m for m in self.default_patched_modules if m not in ('time', 'threading')) | ||
|
|
||
| for module_name in not_patched_modules: | ||
| self.assertFalse(monkey.is_module_patched(module_name), | ||
| f"{module_name} is patched, when it shouldn't be") | ||
|
|
||
|
|
||
| def test_instana_monkey_options_only_socket(self): | ||
| os.environ['INSTANA_GEVENT_MONKEY_OPTIONS'] = ( | ||
| '--socket, --no-time, --no-select, --no-os, --no-queue, --no-threading,' | ||
GSVarsha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| '--no-os, --no-ssl, no-subprocess, --no-signal, --no-select,') | ||
| apply_gevent_monkey_patch() | ||
|
|
||
| self.assertTrue(monkey.is_module_patched('socket'), "socket module is not patched") | ||
| not_patched_modules = (m for m in self.default_patched_modules if m not in ('socket', 'threading')) | ||
|
|
||
| for module_name in not_patched_modules: | ||
| self.assertFalse(monkey.is_module_patched(module_name), | ||
| f"{module_name} is patched, when it shouldn't be") | ||
|
|
||
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.