# storage-testbench **Repository Path**: mirrors_googleapis/storage-testbench ## Basic Information - **Project Name**: storage-testbench - **Description**: A testbench for Google Cloud Storage client libraries. - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-16 - **Last Updated**: 2026-11-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Storage Testbench **This is not an officially supported Google product** This repository is used by Storage Client libraries to test integration tests locally and reproduce Storage API transient errors. The testbench emulates the Storage API and is expected to be used by Storage library maintainers. ## Table of Contents - [Storage Testbench](#storage-testbench) - [Table of Contents](#table-of-contents) - [Issue Policy](#issue-policy) - [What is this testbench?](#what-is-this-testbench) - [When to use this testbench](#when-to-use-this-testbench) - [How to use this testbench](#how-to-use-this-testbench) - [Initial set up](#initial-set-up) - [Run the testbench](#run-the-testbench) - [Start the gRPC server](#start-the-gRPC-server) - [Check that the testbench is running](#check-that-the-testbench-is-running) - [Updating Proto Files](#updating-proto-files) - [Force Failures](#force-failures) - [return-broken-stream](#return-broken-stream) - [return-corrupted-data](#return-corrupted-data) - [stall-always](#stall-always) - [stall-at-256KiB](#stall-at-256kib) - [return-503-after-256K](#return-503-after-256k) - [return-503-after-256K/retry-N](#return-503-after-256kretry-n) - [redirect-send-token-T](#redirect-send-token-t) - [redirect-send-handle-and-token-T](#redirect-send-handle-and-token-t) - [redirect-expect-token-T](#redirect-expect-token-t) - [Retry Test API](#retry-test-api) - [Creating a new Retry Test](#creating-a-new-retry-test) - [Get a Retry Test resource](#get-a-retry-test-resource) - [Delete a Retry Test resource](#delete-a-retry-test-resource) - [Causing a failure using x-retry-test-id header](#causing-a-failure-using-x-retry-test-id-header) - [Forced Failures Supported](#forced-failures-supported) - [Storage Control API Stall Support](#storage-control-api-stall-support) - [Developing for the testbench](#developing-for-the-testbench) - [Writing and running tests](#writing-and-running-tests) - [Releasing the testbench](#releasing-the-testbench) ## Issue Policy Repository provides no dedicated support for issues filed. Issues will be addressed when time permits. ## What is this testbench? This testbench fakes the Google Cloud Storage (GCS) API. You can configure the GCS client libraries to make calls to this fake rather than to the actual API. * The testbench fakes the JSON API, both over REST and gRPC. It has limited support for the XML API. * Generally, the error codes are similar to the ones generated by GCS, but the error messages are not. * The testbench performs far fewer error checks, and no permission checks (ACL/IAM). ## When to use this testbench In general, this testbench is best suited for integration tests that are hard (or just annoying) to reliably run against production. The primary example of this are errors that make the client library go through its retry path. This testbench can be useful to test HMAC keys, which are really hard to test against production due to quota restrictions. It is useful as well to test features that are not yet deployed to production: you can implement them in the testbench and then write the library code before production is "ready". ## How to use this testbench ### Initial set up 1. [Set up python if you haven't already](https://cloud.google.com/python/docs/setup) 2. [Clone this repository](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository-from-github/cloning-a-repository#cloning-a-repository) From the terminal: ```bash git clone https://github.com/googleapis/storage-testbench.git ``` 3. Switch to the cloned directory: ```bash cd storage-testbench ``` 4. [Create a virtual environment](https://cloud.google.com/python/docs/setup#installing_and_using_virtualenv) * keep this virtual environment active whenever you run the testbench 5. Install dependencies: ```bash pip install -e . ``` ### Run the testbench To start the testbench, run this command from a terminal: On Non-Windows ```bash python3 testbench_run.py localhost 9000 10 ``` On Windows ```bash py testbench_run.py localhost 9000 10 ``` > ⚠️ Ensure that the virtual environment you created to install the dependencies is active. ### Start the gRPC server If you want to test the gRPC API, you must make a request which will start the testbench's gRPC server. Also, the gRPC server must run on a different port than the HTTP server. To serve gRPC requests on port 8888, run: ```bash curl -s --retry 5 --retry-max-time 40 "http://localhost:9000/start_grpc?port=8888" ``` > ⚠️ The HTTP server must be kept running to start the gRPC server and to make calls to the testbench, > even after you start the gRPC server. Run this command in a different terminal window. By default, `/start_grpc` binds the gRPC server to the host specified by the `STORAGE_TESTBENCH_HOST` environment variable, falling back to `localhost` when unset. `testbench_run.py` sets `STORAGE_TESTBENCH_HOST` to the `` argument it was started with, and the `Dockerfile` sets `STORAGE_TESTBENCH_HOST=0.0.0.0`. If you invoke `gunicorn` directly outside `testbench_run.py` or Docker and need remote/cross-container access to gRPC, set `STORAGE_TESTBENCH_HOST=0.0.0.0` explicitly. `/start_grpc` also accepts these optional parameters: - `max-workers`: size of the gRPC server thread pool (each open stream holds one worker). - `bidi-read-idle-timeout`: seconds a `BidiReadObject` stream may stay idle (no request received and no response sent) before the testbench cancels it. Defaults to 10. Active streams are not cancelled. - `strict-bucket-modes`: set to `true` to emulate the differences between RAPID buckets (`storageClass: RAPID`) and standard buckets in `BidiReadObject`. Defaults to `false`. - RAPID buckets reject a `read_mask` that does not include `object_data_ranges`. - Standard buckets require `x-goog-request-params` with `bucket=` set to the bucket in the request, never return a `read_handle`, and ignore any `read_handle` sent by clients. ### Check that the testbench is running Ensure the testbench is running by sending it a request from a different terminal, such as: ```bash curl -X GET localhost:9000 ``` The response you get should be: `OK` Now you can use the testbench (while it's running) with the client libraries. ## Updating Proto Files From time to time you may need to update the files generated by protobuf and gRPC. To do so, clone the [protos](https://github.com/googleapis/googleapis) and run the grpc_tools generator: ```shell cd $HOME/storage-testbench pip install --no-deps grpcio-tools ./update-protos.sh $PWD/.googleapis ``` Then commit the files generated in `google/**`: ```shell git commit -m"chore: update protos" google ``` ## Force Failures You can force the following failures by using the `x-goog-emulator-instructions` header. The `x-goog-testbench-instructions` header is deprecated, but supported for backwards compatibility and provides the same functionality as `x-goog-emulator-instructions`, please change your code to use `x-goog-emulator-instructions` instead. ### return-broken-stream Set request headers with `x-goog-emulator-instructions: return-broken-stream`. Testbench will fail after sending 1024*1024 bytes. ### return-corrupted-data Set request headers with `x-goog-emulator-instructions: return-corrupted-data`. Testbench will return corrupted data. In gRPC, use the Retry Test API with `return-corrupted-data` for `BidiReadObject` (`storage.objects.get`; `ReadObject` is not affected). `BidiReadObject` corrupts the next non-empty data chunk while keeping the CRC32C of the original data, so clients see a checksum mismatch. ### stall-always Set request headers with `x-goog-emulator-instructions: stall-always`. Testbench will stall at the beginning. ### stall-at-256KiB Set request headers with `x-goog-emulator-instructions: stall-at-256KiB`. Testbench will stall at 256KiB bytes. ### return-503-after-256K Set request headers with `x-goog-emulator-instructions: return-503-after-256K`. Testbench will return a `HTTP 503` after sending 256KiB bytes. ### return-503-after-256K/retry-N Set request headers with `x-goog-emulator-instructions: return-503-after-256K/retry-1` up to `x-goog-emulator-instructions: return-503-after-256K/retry-N`. For N==1 and N==2 behave like `return-305-after-256K`, for `N>=3` ignore the failure instruction and return successfully. This is used to test failures during retry, the client cooperates by sending the retry counter in the failure instructions. ### redirect-send-token-T In gRPC, set initial metadata with `x-goog-emulator-instructions: redirect-send-token-tokenval`. Testbench will fail redirectable RPCs with `routing_token` set to the value `T` (`tokenval` in the example). ### redirect-send-handle-and-token-T In gRPC, set initial metadata with `x-goog-emulator-instructions: redirect-send-handle-and-token-tokenval`. Testbench will fail redirectable RPCs with `routing_token` set to the value `T` (`tokenval` in the example) and a `write_handle` or `read_handle` depending on the method called( `storage.objects.insert` or `storage.objects.get` ). For `BidiReadObject`, the status message is "The object is not available from this location.", and the `read_handle` is valid: clients can reopen the object with it. ### redirect-expect-token-T In gRPC, set initial metadata with `x-goog-emulator-instructions: redirect-expect-token-tokenval`. Testbench will consume the instruction if the RPC also specifies `x-goog-request-params: routing_token=T` (`routing_token=tokenval` in the example). For `storage.objects.get` (`BidiReadObject`), setting `read_object_spec.routing_token` to `T` also consumes the instruction. Redirect tokens (`T`) may contain lowercase letters, digits, and `-`. Note that `x-goog-request-params` supports multiple key-value pairs, encoded like URL query parameters. ## Retry Test API The "Retry Test API" offers a mechanism to describe more complex retry scenarios while sending a single, constant header through all the HTTP requests from a test program. Retry Test provides accounting of failures used to validate the expected failures were experienced by the testbench and not accidentally missed. Previous versions of the GCS testbench used a custom header in the RPC to control the behavior of each RPC, for some test scenarios this required sending different header with the first retry attempt vs. subsequent attempts. Producing different headers in each attempt is not easy to implement with some client libraries. Sending a constant header with all RPCs can be implemented across all client libraries, and to some degree decouples the test setup from the test execution. ### Creating a new Retry Test The following cURL request will create a Retry Test resource which emits a 503 when a buckets list operation is received by the testbench HTTP server with the returned retry test ID. Note: A Retry Test resource can only apply to one transport, either `HTTP` or `GRPC`. It defaults to `HTTP` if not specified. ```bash curl -X POST "http://localhost:9000/retry_test" -H 'Content-Type: application/json' \ -d '{"instructions":{"storage.buckets.list": ["return-503"]}, "transport": "HTTP"}' ``` ### Get a Retry Test resource Get Retry Test resource by id "1d05c20627844214a9ff7cbcf696317d". ```bash curl -X GET "http://localhost:9000/retry_test/1d05c20627844214a9ff7cbcf696317d" ``` ### Delete a Retry Test resource Delete Retry Test resource by id "1d05c20627844214a9ff7cbcf696317d". ```bash curl -X DELETE "http://localhost:9000/retry_test/1d05c20627844214a9ff7cbcf696317d" ``` ### Causing a failure using x-retry-test-id header The following cURL request will attempt to list buckets and the testbench will emit a `503` error once in the HTTP server based on the Retry Test created above. Subsequent list buckets operations will succeed. In this example, list buckets operations in the gRPC server will not be impacted since the Retry Test created above only applies to HTTP. Specify `"transport": "GRPC"` for a Retry Test Resource to apply to gRPC operations. ```bash curl -H "x-retry-test-id: 1d05c20627844214a9ff7cbcf696317d" "http://localhost:9100/storage/v1/b?project=test" ``` ### Forced Failures Supported | Failure Id | Description | ----------------------- | --- | return-X | [HTTP] Testbench will fail with HTTP code provided for X, e.g. return-503 returns a 503
[GRPC] Testbench will fail with the equivalent gRPC error to the HTTP code provided for X (X currently supported in the gRPC context include `400`, `401`, `429`, `500`, `501`, `503`) | return-X-after-YK | [HTTP] Testbench will return X after YKiB of uploaded data
[GRPC] Testbench will return the equivalent gRPC error to the HTTP code provided for X after YKiB of uploaded data (X currently supported in the gRPC context include `400`, `401`, `429`, `500`, `501`, `503`) | return-broken-stream-final-chunk-after-YB | [HTTP] Testbench will break connection on final chunk of a resumable upload after Y bytes | return-broken-stream | [HTTP] Testbench will fail after a few downloaded bytes
[GRPC] Testbench will fail with `UNAVAILABLE` after a few downloaded bytes | return-broken-stream-after-YK | [HTTP] Testbench will fail after YKiB of downloaded data
[GRPC] Testbench will fail with `UNAVAILABLE` after YKiB of downloaded data | return-corrupted-data | [HTTP] Unsupported
[GRPC] For `BidiReadObject` (`storage.objects.get`), testbench will corrupt the next non-empty data chunk while keeping the CRC32C of the original data | return-reset-connection | [HTTP] Testbench will fail with a reset connection
[GRPC] Testbench will fail the RPC with `UNAVAILABLE` | stall-for-Ts-after-YK | [HTTP] Testbench will stall for T seconds after reading YKiB of downloaded/uploaded data, e.g. stall-for-10s-after-12K stalls after reading/writing 12KiB of data
[GRPC] Testbench will stall for T seconds after reading YKiB of downloaded data or after writing YKiB of uploaded data (Supported for `storage.objects.get` and for `storage.objects.insert` via `WriteObject` and `BidiWriteObject`). For uploads, YKiB is measured from the start of the object, so the stall also applies to resumed uploads; it triggers once, before the chunk that crosses the threshold is persisted. | redirect-send-token-T | [HTTP] Unsupported [GRPC] Testbench will fail the RPC with `ABORTED` and include appropriate redirection error details. | redirect-send-handle-and-token-T | [HTTP] Unsupported [GRPC] Testbench will fail the RPC with `ABORTED` and include appropriate redirection error details. | return-X-if-dp-enforced | [HTTP] Unsupported [GRPC] Testbench will fail with the equivalent gRPC error to the HTTP code provided for X, but only if DirectPath is enforced. ## Storage Control API Stall Support The testbench supports stall functionality for the Storage Control API (gRPC only) to test client retry behavior. All folder operations and storage layout operations can be delayed using the `x-goog-emulator-instructions` metadata header. **Supported operations:** - **Folder operations:** `CreateFolder`, `DeleteFolder`, `GetFolder`, `ListFolders`, `RenameFolder` - **Storage layout operations:** `GetStorageLayout` > **Note:** The Storage Control API uses the **same gRPC server** as the Storage API. Both services are available on the same port (e.g., port 8888 if started with `curl "http://localhost:9000/start_grpc?port=8888"`). **Supported stall instruction:** - `stall-for-Ns`: Stalls for N seconds (e.g., `stall-for-3s` stalls for 3 seconds) **Example usage in Python:** ```python import grpc from google.storage.control.v2 import storage_control_pb2, storage_control_pb2_grpc # Connect to the same gRPC server port (8888) started earlier channel = grpc.insecure_channel('localhost:8888') stub = storage_control_pb2_grpc.StorageControlStub(channel) # Create folder with 2-second stall metadata = [('x-goog-emulator-instructions', 'stall-for-2s')] request = storage_control_pb2.CreateFolderRequest( parent="projects/_/buckets/test-bucket", folder_id="test-folder" ) response = stub.CreateFolder(request, metadata=metadata) ``` ## Developing for the testbench ### Writing and running tests Tests are located in the `tests/` directory. To run the tests locally, use ```bash python -m unittest [test_module.py] # runs all the tests in test_module.py python -m unittest [test_module.TestClass.test_method] # runs a single test python -m unittest discover -s tests/ # runs all the tests ``` ## Releasing the testbench The repository currently uses [Github Tags](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository#creating-a-release) Steps: 1. Go to https://github.com/googleapis/storage-testbench/releases/new 1. Create a new tag v0.x.x 1. Title "v0.x.x" 1. Click Generate release notes 1. Make sure "Set as the latest release" is checked 1. Click "Publish Release" to release