-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(spanner): add pytest-xdist parallel execution with state isolation #17344
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,6 +230,7 @@ def unit(session, protobuf_implementation): | |
| CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" | ||
| ) | ||
| install_unittest_dependencies(session, "-c", constraints_path) | ||
| session.install("pytest-xdist") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be added to UNIT_TEST_STANDARD_DEPENDENCIES? |
||
|
|
||
| # TODO(https://github.com/googleapis/synthtool/issues/1976): | ||
| # Remove the 'cpp' implementation once support for Protobuf 3.x is dropped. | ||
|
|
@@ -240,6 +241,8 @@ def unit(session, protobuf_implementation): | |
| # Run py.test against the unit tests. | ||
| args = [ | ||
| "py.test", | ||
| "-n", | ||
| "auto", | ||
| "-s", | ||
| f"--junitxml=unit_{session.python}_sponge_log.xml", | ||
| "--cov=google", | ||
|
|
@@ -754,7 +757,6 @@ def prerelease_deps(session, protobuf_implementation, database_dialect): | |
| def mypy(session): | ||
| """Run the type checker.""" | ||
| session.skip("Mypy is not yet supported") | ||
|
|
||
| # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): | ||
| # use the latest version of mypy | ||
| session.install( | ||
|
|
@@ -832,12 +834,15 @@ def core_deps_from_source(session, protobuf_implementation): | |
| dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] | ||
|
|
||
| session.install(*dep_paths, "--no-deps", "--ignore-installed") | ||
| session.install("pytest-xdist") | ||
| print( | ||
| f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" | ||
| ) | ||
|
|
||
| session.run( | ||
| "py.test", | ||
| "-n", | ||
| "auto", | ||
| "tests/unit", | ||
| env={ | ||
| "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1800,11 +1800,18 @@ async def unit_of_work(txn, *args, **kw): | |
| called_with.append((txn, args, kw)) | ||
| txn.insert(TABLE_NAME, COLUMNS, VALUES) | ||
|
|
||
| import threading | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be moved to to top of the file? |
||
|
|
||
| main_thread = threading.current_thread() | ||
| _results = [1, 1.5] | ||
|
|
||
| # retry once w/ timeout_secs=1 | ||
| def _time(_results=[1, 1.5]): | ||
| if len(_results) > 1: | ||
| return _results.pop(0) | ||
| return _results[0] | ||
| def _time(): | ||
| if threading.current_thread() is main_thread: | ||
| if len(_results) > 1: | ||
| return _results.pop(0) | ||
| return _results[0] | ||
| return 1.0 | ||
|
|
||
| with mock.patch("time.time", _time): | ||
| with mock.patch( | ||
|
|
@@ -1877,9 +1884,16 @@ async def unit_of_work(txn, *args, **kw): | |
| called_with.append((txn, args, kw)) | ||
| txn.insert(TABLE_NAME, COLUMNS, VALUES) | ||
|
|
||
| import threading | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we import threading globally, this shouldnt be needed |
||
|
|
||
| main_thread = threading.current_thread() | ||
| _results = [1] * 100 | ||
|
|
||
| # retry several times to check backoff | ||
| def _time(_results=[1] * 100): | ||
| return _results.pop(0) | ||
| def _time(): | ||
| if threading.current_thread() is main_thread: | ||
| return _results.pop(0) | ||
| return 1.0 | ||
|
|
||
| with ( | ||
| mock.patch("time.time", _time), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1714,9 +1714,18 @@ def unit_of_work(txn, *args, **kw): | |
| called_with.append((txn, args, kw)) | ||
| txn.insert(TABLE_NAME, COLUMNS, VALUES) | ||
|
|
||
| import threading | ||
|
|
||
| main_thread = threading.current_thread() | ||
| _results = [1, 1.5] | ||
|
|
||
| # retry once w/ timeout_secs=1 | ||
| def _time(_results=[1, 1.5]): | ||
| return _results.pop(0) | ||
| def _time(): | ||
| if threading.current_thread() is main_thread: | ||
| if len(_results) > 1: | ||
| return _results.pop(0) | ||
| return _results[0] | ||
| return 1.0 | ||
|
|
||
| with mock.patch("time.time", _time): | ||
| with mock.patch("time.sleep") as sleep_mock: | ||
|
|
@@ -1783,9 +1792,18 @@ def unit_of_work(txn, *args, **kw): | |
| called_with.append((txn, args, kw)) | ||
| txn.insert(TABLE_NAME, COLUMNS, VALUES) | ||
|
|
||
| import threading | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comments about imports |
||
|
|
||
| main_thread = threading.current_thread() | ||
| _results = [1, 2, 4, 8] | ||
|
|
||
| # retry several times to check backoff | ||
| def _time(_results=[1, 2, 4, 8]): | ||
| return _results.pop(0) | ||
| def _time(): | ||
| if threading.current_thread() is main_thread: | ||
| if len(_results) > 1: | ||
| return _results.pop(0) | ||
| return _results[0] | ||
| return 1.0 | ||
|
|
||
| with ( | ||
| mock.patch("time.time", _time), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.