Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit f768af7

Browse files
chore: run bidi_tests independently (#1781)
chore: run bidi conformance tests independently. --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 17828ea commit f768af7

File tree

2 files changed

+57
-36
lines changed

2 files changed

+57
-36
lines changed

noxfile.py

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
nox.options.sessions = [
4545
"blacken",
4646
"conftest_retry",
47+
"conftest_retry_bidi",
4748
"docfx",
4849
"docs",
4950
"lint",
@@ -221,10 +222,9 @@ def system(session):
221222
@nox.session(python=CONFORMANCE_TEST_PYTHON_VERSIONS)
222223
def conftest_retry(session):
223224
"""Run the retry conformance test suite."""
224-
conformance_test_folder_path = os.path.join("tests", "conformance")
225-
conformance_test_folder_exists = os.path.exists(conformance_test_folder_path)
225+
json_conformance_tests = "tests/conformance/test_conformance.py"
226226
# Environment check: only run tests if found.
227-
if not conformance_test_folder_exists:
227+
if not os.path.exists(json_conformance_tests):
228228
session.skip("Conformance tests were not found")
229229

230230
constraints_path = str(
@@ -236,10 +236,6 @@ def conftest_retry(session):
236236
session.install(
237237
"pytest",
238238
"pytest-xdist",
239-
"pytest-asyncio",
240-
"grpcio",
241-
"grpcio-status",
242-
"grpc-google-iam-v1",
243239
"-c",
244240
constraints_path,
245241
)
@@ -251,17 +247,52 @@ def conftest_retry(session):
251247
"pytest",
252248
"-vv",
253249
"-s",
254-
# "--quiet",
255-
conformance_test_folder_path,
250+
json_conformance_tests,
256251
*session.posargs,
257252
]
258253
else:
259-
test_cmd = ["pytest", "-vv", "-s", "-n", "auto", conformance_test_folder_path]
254+
test_cmd = ["pytest", "-vv", "-s", "-n", "auto", json_conformance_tests]
260255

261-
# Run py.test against the conformance tests.
256+
# Run pytest against the conformance tests.
262257
session.run(*test_cmd, env={"DOCKER_API_VERSION": "1.39"})
263258

264259

260+
@nox.session(python=CONFORMANCE_TEST_PYTHON_VERSIONS)
261+
def conftest_retry_bidi(session):
262+
"""Run the retry conformance test suite."""
263+
264+
constraints_path = str(
265+
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
266+
)
267+
268+
# Install all test dependencies and pytest plugin to run tests in parallel.
269+
# Then install this package in-place.
270+
session.install(
271+
"pytest",
272+
"pytest-xdist",
273+
"pytest-asyncio",
274+
"grpcio",
275+
"grpcio-status",
276+
"grpc-google-iam-v1",
277+
"-c",
278+
constraints_path,
279+
)
280+
session.install("-e", ".", "-c", constraints_path)
281+
282+
bidi_tests = [
283+
"tests/conformance/test_bidi_reads.py",
284+
"tests/conformance/test_bidi_writes.py",
285+
]
286+
for test_file in bidi_tests:
287+
session.run(
288+
"pytest",
289+
"-vv",
290+
"-s",
291+
test_file,
292+
env={"DOCKER_API_VERSION": "1.39"},
293+
)
294+
295+
265296
@nox.session(python=DEFAULT_PYTHON_VERSION)
266297
def cover(session):
267298
"""Run the final coverage report.

tests/conformance/test_bidi_reads.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
import urllib
66
import uuid
77

8-
import grpc
98
import pytest
109
import requests
1110
from google.api_core import client_options, exceptions
12-
from google.auth import credentials as auth_credentials
1311

1412
from google.cloud import _storage_v2 as storage_v2
1513
from google.cloud.storage.asyncio.async_grpc_client import AsyncGrpcClient
16-
from google.cloud.storage.asyncio.async_multi_range_downloader import \
17-
AsyncMultiRangeDownloader
14+
from google.cloud.storage.asyncio.async_multi_range_downloader import (
15+
AsyncMultiRangeDownloader,
16+
)
17+
from google.cloud.storage.asyncio.async_appendable_object_writer import (
18+
AsyncAppendableObjectWriter,
19+
)
1820
from tests.conformance._utils import start_grpc_server
1921

2022
# --- Configuration ---
@@ -138,12 +140,11 @@ async def test_bidi_reads(testbench):
138140
start_grpc_server(
139141
grpc_endpoint, test_bench_endpoint
140142
) # Ensure the testbench gRPC server is running before this test executes.
141-
channel = grpc.aio.insecure_channel(GRPC_ENDPOINT)
142-
creds = auth_credentials.AnonymousCredentials()
143-
transport = storage_v2.services.storage.transports.StorageGrpcAsyncIOTransport(
144-
channel=channel, credentials=creds
143+
144+
grpc_client = AsyncGrpcClient._create_insecure_grpc_client(
145+
client_options=client_options.ClientOptions(api_endpoint=GRPC_ENDPOINT),
145146
)
146-
gapic_client = storage_v2.StorageAsyncClient(transport=transport)
147+
gapic_client = grpc_client.grpc_client
147148
http_client = requests.Session()
148149

149150
bucket_name = f"grpc-test-bucket-{uuid.uuid4().hex[:8]}"
@@ -166,22 +167,11 @@ async def test_bidi_reads(testbench):
166167
create_bucket_request = storage_v2.CreateBucketRequest(
167168
parent="projects/_", bucket_id=bucket_name, bucket=bucket_resource
168169
)
169-
await gapic_client.create_bucket(request=create_bucket_request)
170-
171-
write_spec = storage_v2.WriteObjectSpec(
172-
resource=storage_v2.Object(
173-
bucket=f"projects/_/buckets/{bucket_name}", name=object_name
174-
)
175-
)
176-
177-
async def write_req_gen():
178-
yield storage_v2.WriteObjectRequest(
179-
write_object_spec=write_spec,
180-
checksummed_data={"content": content},
181-
finish_write=True,
182-
)
183-
184-
await gapic_client.write_object(requests=write_req_gen())
170+
_ = await gapic_client.create_bucket(request=create_bucket_request)
171+
w = AsyncAppendableObjectWriter(grpc_client, bucket_name, object_name)
172+
await w.open()
173+
await w.append(content)
174+
_ = await w.close(finalize_on_close=True)
185175

186176
# Run all defined test scenarios.
187177
for scenario in test_scenarios:

0 commit comments

Comments
 (0)