Skip to content

Commit

Permalink
Add graph client test.
Browse files Browse the repository at this point in the history
  • Loading branch information
CPWstatic committed Sep 29, 2021
1 parent 0de4fb0 commit 07e1bca
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
from tests.common.utils import get_conn_pool
from tests.common.constants import NB_TMP_PATH, SPACE_TMP_PATH

from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from nebula2.gclient.net import Connection
from nebula2.graph import GraphService

tests_collected = set()
tests_executed = set()
data_dir = os.getenv('NEBULA_DATA_DIR')
Expand Down Expand Up @@ -186,3 +192,13 @@ def workarround_for_class(request, pytestconfig, conn_pool,
if request.cls.client is not None:
request.cls.cleanup()
request.cls.drop_data()

@pytest.fixture(scope="class")
def establish_a_rare_connection(pytestconfig):
addr = pytestconfig.getoption("address")
host_addr = addr.split(":") if addr else ["localhost", get_ports()[0]]
socket = TSocket.TSocket(host_addr[0], host_addr[1])
transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
transport.open()
return GraphService.Client(protocol)
31 changes: 31 additions & 0 deletions tests/tck/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
from tests.tck.utils.table import dataset, table
from tests.tck.utils.nbv import murmurhash2

from nebula2.graph.ttypes import VerifyClientVersionReq
from nebula2.graph.ttypes import VerifyClientVersionResp

parse = functools.partial(parsers.parse)
rparse = functools.partial(parsers.re)
example_pattern = re.compile(r"<(\w+)>")
Expand Down Expand Up @@ -532,3 +535,31 @@ def executing_query_with_params(query, indices, keys, graph_spaces, session, req
register_lock.release()
ngql = combine_query(query).format(*vals)
exec_query(request, ngql, session, graph_spaces)

@given(parse("nothing"))
def nothing():
pass

@when(parse("connecting the servers with a compatible client version"))
def connecting_servers_with_a_compatible_client_version(establish_a_rare_connection, graph_spaces):
conn = establish_a_rare_connection
graph_spaces["resp"] = conn.verifyClientVersion(VerifyClientVersionReq())
conn._iprot.trans.close()

@then(parse("the connection should be established"))
def check_client_compatible(graph_spaces):
resp = graph_spaces["resp"]
assert resp.error_code == ErrorCode.SUCCEEDED, f'The client was rejected by server: {resp}'

@when(parse("connecting the servers with a client version of {version}"))
def connecting_servers_with_a_compatible_client_version(version, establish_a_rare_connection, graph_spaces):
conn = establish_a_rare_connection
req = VerifyClientVersionReq()
req.version = version
graph_spaces["resp"] = conn.verifyClientVersion(req)
conn._iprot.trans.close()

@then(parse("the connection should be rejected"))
def check_client_compatible(graph_spaces):
resp = graph_spaces["resp"]
assert resp.error_code == ErrorCode.E_CLIENT_SERVER_INCOMPATIBLE, f'The client was not rejected by server: {resp}'

0 comments on commit 07e1bca

Please sign in to comment.