googleapis / storage-testbench

A testbench for Google Cloud Storage client libraries.
Apache License 2.0
9 stars 20 forks source link

Add support for disabling reloader #669

Open kou opened 2 months ago

kou commented 2 months ago

Is your feature request related to a problem? Please describe.

I'm an Apache Arrow developer. We're using this product for testing our GCS filesystem implementation.

We run this product by python3 -m testbench. This launches multiple processes for reloader. To shutdown these processes, we need to (1) shutdown the main process gracefully (the main process shutdowns other processes) or (2) terminate all related processes by ourselves.

Our test uses Boost.Process https://www.boost.org/libs/process to launch this product. We're using (2) because Boost.Process can't do (1) on Windows. I don't know why but (1) with Boost.Process shutdowns the launcher process (the main test process in our case) too.

We're migrating Boost.Process v2 API https://github.com/apache/arrow/pull/43766 because Boost.Process v1 API is deprecated since Boost 1.86.0. Unfortunately, we can't use (2) with Boost.Process v2 API because it doesn't support process group: https://github.com/boostorg/process/issues/259

If this product doesn't use multiple processes, we don't need to use (2). We can just need to terminate the main process. It can simplify our test.

Describe the solution you'd like

How about adding a new --no-use-reloader option that disables reloader something like the following? If we disable reloader, python3 -m testbench launches only one process.

diff --git a/testbench/rest_server.py b/testbench/rest_server.py
index 9490f24..579b349 100644
--- a/testbench/rest_server.py
+++ b/testbench/rest_server.py
@@ -1174,12 +1174,14 @@ def _main():
         description="A testbench for the GCS client libraries"
     )
     parser.add_argument("--port", default=0, type=int)
+    parser.add_argument("--use-reloader", default=True,
+                        action=argparse.BooleanOptionalAction)
     args = parser.parse_args()
     serving.run_simple(
         "localhost",
         port=args.port,
         application=_run(),
-        use_reloader=True,
+        use_reloader=args.use_reloader,
         threaded=True,
     )

If we keep the default value of it as True, we can still use reloader by default.

Describe alternatives you've considered

Something that only uses one process.

Additional context

None.