diff --git a/noxfile.py b/noxfile.py index 6bce85327..77823d28d 100644 --- a/noxfile.py +++ b/noxfile.py @@ -44,6 +44,7 @@ nox.options.sessions = [ "blacken", "conftest_retry", + "conftest_retry_bidi", "docfx", "docs", "lint", @@ -221,10 +222,9 @@ def system(session): @nox.session(python=CONFORMANCE_TEST_PYTHON_VERSIONS) def conftest_retry(session): """Run the retry conformance test suite.""" - conformance_test_folder_path = os.path.join("tests", "conformance") - conformance_test_folder_exists = os.path.exists(conformance_test_folder_path) + json_conformance_tests = "tests/conformance/test_conformance.py" # Environment check: only run tests if found. - if not conformance_test_folder_exists: + if not os.path.exists(json_conformance_tests): session.skip("Conformance tests were not found") constraints_path = str( @@ -236,10 +236,6 @@ def conftest_retry(session): session.install( "pytest", "pytest-xdist", - "pytest-asyncio", - "grpcio", - "grpcio-status", - "grpc-google-iam-v1", "-c", constraints_path, ) @@ -251,17 +247,52 @@ def conftest_retry(session): "pytest", "-vv", "-s", - # "--quiet", - conformance_test_folder_path, + json_conformance_tests, *session.posargs, ] else: - test_cmd = ["pytest", "-vv", "-s", "-n", "auto", conformance_test_folder_path] + test_cmd = ["pytest", "-vv", "-s", "-n", "auto", json_conformance_tests] - # Run py.test against the conformance tests. + # Run pytest against the conformance tests. session.run(*test_cmd, env={"DOCKER_API_VERSION": "1.39"}) +@nox.session(python=CONFORMANCE_TEST_PYTHON_VERSIONS) +def conftest_retry_bidi(session): + """Run the retry conformance test suite.""" + + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) + + # Install all test dependencies and pytest plugin to run tests in parallel. + # Then install this package in-place. + session.install( + "pytest", + "pytest-xdist", + "pytest-asyncio", + "grpcio", + "grpcio-status", + "grpc-google-iam-v1", + "-c", + constraints_path, + ) + session.install("-e", ".", "-c", constraints_path) + + bidi_tests = [ + "tests/conformance/test_bidi_reads.py", + "tests/conformance/test_bidi_writes.py", + ] + for test_file in bidi_tests: + session.run( + "pytest", + "-vv", + "-s", + test_file, + env={"DOCKER_API_VERSION": "1.39"}, + ) + + @nox.session(python=DEFAULT_PYTHON_VERSION) def cover(session): """Run the final coverage report. diff --git a/tests/conformance/test_bidi_reads.py b/tests/conformance/test_bidi_reads.py index efb9671a3..8f0c43c4a 100644 --- a/tests/conformance/test_bidi_reads.py +++ b/tests/conformance/test_bidi_reads.py @@ -5,16 +5,18 @@ import urllib import uuid -import grpc import pytest import requests from google.api_core import client_options, exceptions -from google.auth import credentials as auth_credentials from google.cloud import _storage_v2 as storage_v2 from google.cloud.storage.asyncio.async_grpc_client import AsyncGrpcClient -from google.cloud.storage.asyncio.async_multi_range_downloader import \ - AsyncMultiRangeDownloader +from google.cloud.storage.asyncio.async_multi_range_downloader import ( + AsyncMultiRangeDownloader, +) +from google.cloud.storage.asyncio.async_appendable_object_writer import ( + AsyncAppendableObjectWriter, +) from tests.conformance._utils import start_grpc_server # --- Configuration --- @@ -138,12 +140,11 @@ async def test_bidi_reads(testbench): start_grpc_server( grpc_endpoint, test_bench_endpoint ) # Ensure the testbench gRPC server is running before this test executes. - channel = grpc.aio.insecure_channel(GRPC_ENDPOINT) - creds = auth_credentials.AnonymousCredentials() - transport = storage_v2.services.storage.transports.StorageGrpcAsyncIOTransport( - channel=channel, credentials=creds + + grpc_client = AsyncGrpcClient._create_insecure_grpc_client( + client_options=client_options.ClientOptions(api_endpoint=GRPC_ENDPOINT), ) - gapic_client = storage_v2.StorageAsyncClient(transport=transport) + gapic_client = grpc_client.grpc_client http_client = requests.Session() bucket_name = f"grpc-test-bucket-{uuid.uuid4().hex[:8]}" @@ -166,22 +167,11 @@ async def test_bidi_reads(testbench): create_bucket_request = storage_v2.CreateBucketRequest( parent="projects/_", bucket_id=bucket_name, bucket=bucket_resource ) - await gapic_client.create_bucket(request=create_bucket_request) - - write_spec = storage_v2.WriteObjectSpec( - resource=storage_v2.Object( - bucket=f"projects/_/buckets/{bucket_name}", name=object_name - ) - ) - - async def write_req_gen(): - yield storage_v2.WriteObjectRequest( - write_object_spec=write_spec, - checksummed_data={"content": content}, - finish_write=True, - ) - - await gapic_client.write_object(requests=write_req_gen()) + _ = await gapic_client.create_bucket(request=create_bucket_request) + w = AsyncAppendableObjectWriter(grpc_client, bucket_name, object_name) + await w.open() + await w.append(content) + _ = await w.close(finalize_on_close=True) # Run all defined test scenarios. for scenario in test_scenarios: