Skip to content

Commit

Permalink
Rehome python bazel distribtest (grpc#29275)
Browse files Browse the repository at this point in the history
* WIP

* Test multiple languages

* Yapf

* isort

* Shellcheck

* comment not provided

* Fix import ordering issue.

* Turn up Bazel logging
  • Loading branch information
gnossen authored Apr 1, 2022
1 parent 2fd632a commit f688f5f
Show file tree
Hide file tree
Showing 27 changed files with 45 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ third_party/re2
third_party/upb
third_party/xds

bazel/test/python_test_repo
test/distrib/bazel/cpp
test/distrib/bazel/python
test/distrib/bazel/python_second_test_repo

# Directories generated by setuptools build containing BUILD files.
src/python/grpcio_tests/src/
Expand Down
1 change: 0 additions & 1 deletion bazel/test/python_test_repo/tools/bazel

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

local_repository(
name = "com_github_grpc_grpc",
path = "../../..",
path = "../../../..",
)

# Ensure rules don't rely on __main__ naming convention.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
# limitations under the License.
"""The Python implementation of the GRPC helloworld.Greeter client."""

from concurrent import futures
import contextlib
import datetime
import logging
import unittest

import grpc

from google.protobuf import duration_pb2
from google.protobuf import timestamp_pb2
from concurrent import futures
import grpc
import helloworld_pb2
import helloworld_pb2_grpc

Expand Down Expand Up @@ -56,6 +55,7 @@ def _listening_server():


class ImportTest(unittest.TestCase):

def test_import(self):
with _listening_server() as port:
with grpc.insecure_channel('{}:{}'.format(_HOST, port)) as channel:
Expand All @@ -66,7 +66,7 @@ def test_import(self):
name='you',
request_initiation=request_timestamp,
),
wait_for_ready=True)
wait_for_ready=True)
self.assertEqual(response.message, "Hello, you!")
self.assertGreater(response.request_duration.nanos, 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
# limitations under the License.
"""The Python implementation of the GRPC helloworld.Greeter client."""

from concurrent import futures
import contextlib
import datetime
import logging
import unittest

# TODO(https://github.com/grpc/grpc/issues/29284)
# isort: off
import grpc

from google.protobuf import duration_pb2
from google.protobuf import timestamp_pb2
from concurrent import futures
from google.cloud import helloworld_pb2
from google.cloud import helloworld_pb2_grpc
# isort: on

_HOST = 'localhost'
_SERVER_ADDRESS = '{}:0'.format(_HOST)
Expand Down Expand Up @@ -56,6 +58,7 @@ def _listening_server():


class ImportTest(unittest.TestCase):

def test_import(self):
with _listening_server() as port:
with grpc.insecure_channel('{}:{}'.format(_HOST, port)) as channel:
Expand All @@ -66,7 +69,7 @@ def test_import(self):
name='you',
request_initiation=request_timestamp,
),
wait_for_ready=True)
wait_for_ready=True)
self.assertEqual(response.message, "Hello, you!")
self.assertGreater(response.request_duration.nanos, 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@


class ImportTest(unittest.TestCase):

def test_import(self):
from foo.bar.namespaced.upper.example.namespaced_example_pb2 import NamespacedExample
from foo.bar.namespaced.upper.example.namespaced_example_pb2 import \
NamespacedExample
namespaced_example = NamespacedExample()
namespaced_example.value = "hello"
# Dummy assert, important part is namespaced example was imported.
# Superfluous assert, important part is namespaced example was imported.
self.assertEqual(namespaced_example.value, "hello")

def test_grpc(self):
from foo.bar.namespaced.upper.example.namespaced_example_pb2_grpc import NamespacedServiceStub
from foo.bar.namespaced.upper.example.namespaced_example_pb2_grpc import \
NamespacedServiceStub

# No error from import
self.assertEqual(1, 1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@


class ImportTest(unittest.TestCase):

def test_import(self):
from foo.bar.namespaced_example_pb2 import NamespacedExample
namespaced_example = NamespacedExample()
namespaced_example.value = "hello"
# Dummy assert, important part is namespaced example was imported.
# Superfluous assert, important part is namespaced example was imported.
self.assertEqual(namespaced_example.value, "hello")

def test_grpc(self):
from foo.bar.namespaced_example_pb2_grpc import NamespacedServiceStub

# No error from import
self.assertEqual(1, 1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@


class ImportTest(unittest.TestCase):

def test_import(self):
from namespaced.upper.example.namespaced_example_pb2 import NamespacedExample
from namespaced.upper.example.namespaced_example_pb2 import \
NamespacedExample
namespaced_example = NamespacedExample()
namespaced_example.value = "hello"
# Dummy assert, important part is namespaced example was imported.
# Superfluous assert, important part is namespaced example was imported.
self.assertEqual(namespaced_example.value, "hello")

def test_grpc(self):
from namespaced.upper.example.namespaced_example_pb2_grpc import NamespacedServiceStub
from namespaced.upper.example.namespaced_example_pb2_grpc import \
NamespacedServiceStub

# No error from import
self.assertEqual(1, 1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@


class ImportTest(unittest.TestCase):

def test_import(self):
from namespaced_example_pb2 import NamespacedExample
namespaced_example = NamespacedExample()
namespaced_example.value = "hello"
# Dummy assert, important part is namespaced example was imported.
# Superfluous assert, important part is namespaced example was imported.
self.assertEqual(namespaced_example.value, "hello")

def test_grpc(self):
from namespaced_example_pb2_grpc import NamespacedServiceStub

# No error from import
self.assertEqual(1, 1)

Expand Down
1 change: 1 addition & 0 deletions test/distrib/bazel/python/tools/bazel
13 changes: 11 additions & 2 deletions test/distrib/bazel/test_single_bazel_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,25 @@ EXCLUDED_TARGETS=(
"-//examples/android/binder/..."
)

TEST_DIRECTORIES=(
"cpp"
"python"
)

FAILED_TESTS=""

export OVERRIDE_BAZEL_VERSION="$VERSION"
# when running under bazel docker image, the workspace is read only.
export OVERRIDE_BAZEL_WRAPPER_DOWNLOAD_DIR=/tmp
bazel build -- //... "${EXCLUDED_TARGETS[@]}" || FAILED_TESTS="${FAILED_TESTS}Build "

cd test/distrib/bazel/cpp/
for TEST_DIRECTORY in "${TEST_DIRECTORIES[@]}"; do
pushd "test/distrib/bazel/$TEST_DIRECTORY/"

bazel test --test_output=all //:all || FAILED_TESTS="${FAILED_TESTS}${TEST_DIRECTORY} Distribtest"

bazel test //:all || FAILED_TESTS="${FAILED_TESTS}C++ Distribtest"
popd
done

if [ "$FAILED_TESTS" != "" ]
then
Expand Down
7 changes: 0 additions & 7 deletions tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,3 @@ BAZEL_FLAGS="--test_output=errors"
bazel test ${BAZEL_FLAGS} ${TEST_TARGETS}
bazel test --config=python_single_threaded_unary_stream ${BAZEL_FLAGS} ${TEST_TARGETS}
bazel test --config=python_poller_engine ${BAZEL_FLAGS} ${TEST_TARGETS}


# TODO(https://github.com/grpc/grpc/issues/19854): Move this to a new Kokoro
# job.
(cd /var/local/git/grpc/bazel/test/python_test_repo;
bazel test --test_output=errors //...
)

0 comments on commit f688f5f

Please sign in to comment.