diff --git a/hgitaly/testing/grpc.py b/hgitaly/testing/grpc.py new file mode 100644 index 0000000000000000000000000000000000000000..86e2b479c390d439b22a895b5fde81c404d895e1_aGdpdGFseS90ZXN0aW5nL2dycGMucHk= --- /dev/null +++ b/hgitaly/testing/grpc.py @@ -0,0 +1,23 @@ +from hgitaly.stub.repository_pb2 import RepositoryExistsRequest +from hgitaly.stub.shared_pb2 import Repository +from hgitaly.stub.repository_pb2_grpc import RepositoryServiceStub + + +def wait_server_accepts_connection(gitaly_channel, timeout=5): + """Wait for a server using the Gitaly protocol to accept connections. + + wait for server to start enough that the address in bound + Then the `wait_for_ready` option is there to ensure full readiness, but + the client must at least receive something, e.g., the `CONNECTING` status + for that to work. + """ + repo_stub = RepositoryServiceStub(gitaly_channel) + repo_stub.RepositoryExists( + RepositoryExistsRequest( + repository=Repository( + relative_path="we/dont/care/waiting/for/any/connection", + storage_name="default") + ), + timeout=timeout, + wait_for_ready=True + ) diff --git a/tests_with_gitaly/gitaly.py b/tests_with_gitaly/gitaly.py index 15c56172544ffbbafc4bb202096de0a890a07cea_dGVzdHNfd2l0aF9naXRhbHkvZ2l0YWx5LnB5..86e2b479c390d439b22a895b5fde81c404d895e1_dGVzdHNfd2l0aF9naXRhbHkvZ2l0YWx5LnB5 100644 --- a/tests_with_gitaly/gitaly.py +++ b/tests_with_gitaly/gitaly.py @@ -10,9 +10,7 @@ import os import subprocess -from hgitaly.stub.repository_pb2 import RepositoryExistsRequest -from hgitaly.stub.shared_pb2 import Repository -from hgitaly.stub.repository_pb2_grpc import RepositoryServiceStub +from hgitaly.testing.grpc import wait_server_accepts_connection from . import ( GITALY_BIN_REL_PATH, @@ -20,26 +18,6 @@ ) -def wait_gitaly_accepts_connection(gitaly_channel, timeout=5): - """Wait for the Gitaly server to accept connections. - - wait for server to start enough that the address in bound - Then the `wait_for_ready` optionis there to ensure full readiness, but - the client must at least receive something, e.g., the `CONNECTING` status - for that to work. - """ - repo_stub = RepositoryServiceStub(gitaly_channel) - repo_stub.RepositoryExists( - RepositoryExistsRequest( - repository=Repository( - relative_path="we/dont/care/waiting/for/any/connection", - storage_name="default") - ), - timeout=timeout, - wait_for_ready=True - ) - - @attr.s class GitalyServer: home_dir = attr.ib() @@ -96,7 +74,7 @@ with grpc.insecure_channel('unix:' + str(self.gitaly_socket), ) as gitaly_channel: - wait_gitaly_accepts_connection(gitaly_channel, timeout=timeout) + wait_server_accepts_connection(gitaly_channel, timeout=timeout) yield gitaly_channel gitaly.terminate() diff --git a/tests_with_gitaly/rhgitaly.py b/tests_with_gitaly/rhgitaly.py index 15c56172544ffbbafc4bb202096de0a890a07cea_dGVzdHNfd2l0aF9naXRhbHkvcmhnaXRhbHkucHk=..86e2b479c390d439b22a895b5fde81c404d895e1_dGVzdHNfd2l0aF9naXRhbHkvcmhnaXRhbHkucHk= 100644 --- a/tests_with_gitaly/rhgitaly.py +++ b/tests_with_gitaly/rhgitaly.py @@ -12,7 +12,7 @@ import grpc -from .gitaly import wait_gitaly_accepts_connection +from hgitaly.testing.grpc import wait_server_accepts_connection HGITALY_SOURCE_ROOT = Path(__file__).parent.parent @@ -44,7 +44,7 @@ try: with grpc.insecure_channel(url) as channel: - wait_gitaly_accepts_connection(channel, timeout=timeout) + wait_server_accepts_connection(channel, timeout=timeout) yield channel finally: rhgitaly.terminate()