Skip to content

Commit

Permalink
add session cases
Browse files Browse the repository at this point in the history
clear parameter

fix client ip
  • Loading branch information
HarrisChu committed Dec 17, 2021
1 parent 2beee55 commit 3d0af8d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# This source code is licensed under Apache 2.0 License.

import os
import re
import random
import string
import time
Expand Down Expand Up @@ -441,3 +442,11 @@ def get_conn_pool(host: str, port: int):
if not pool.init([(host, port)], config):
raise Exception("Fail to init connection pool.")
return pool

def parse_service_index(name: str):
name = name.lower()
pattern = r"(graphd|storaged|metad)\[(\d+)\]"
m = re.match(pattern, name)
if m and len(m.groups()) == 2:
return int(m.groups()[1])
return None
44 changes: 44 additions & 0 deletions tests/tck/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
check_resp,
response,
resp_ok,
parse_service_index,
)
from tests.common.nebula_service import NebulaService
from tests.tck.utils.table import dataset, table
Expand Down Expand Up @@ -292,6 +293,21 @@ def given_nebulacluster_with_param(
class_fixture_variables["cluster"] = nebula_svc
class_fixture_variables["pool"] = pool

@when(parse("login {graph} with {user} and {password}"))
def when_login_graphd(graph, user, password, class_fixture_variables, pytestconfig):
index = parse_service_index(graph)
assert index is not None, "Invalid graph name, name is {}".format(graph)
nebula_svc = class_fixture_variables.get("cluster")
assert nebula_svc is not None, "Cannot get the cluster"
assert index < len(nebula_svc.graphd_processes)
graphd_process = nebula_svc.graphd_processes[index]
graph_ip, graph_port = graphd_process.host, graphd_process.tcp_port
pool = get_conn_pool(graph_ip, graph_port)
sess = pool.get_session(user, password)
# do not release original session, as we may have cases to test multiple sessions.
# connection could be released after cluster stopped.
class_fixture_variables["session"] = sess
class_fixture_variables["pool"] = pool

@when(parse("executing query:\n{query}"))
def executing_query(query, graph_spaces, session, request):
Expand Down Expand Up @@ -562,6 +578,19 @@ def result_should_contain(request, result, graph_spaces):
)


@then(parse("the result should contain, replace the holders with cluster info:\n{result}"))
def then_result_should_contain_replace(request, result, graph_spaces, class_fixture_variables):
result = replace_result_with_cluster_info(result, class_fixture_variables)
cmp_dataset(
request,
graph_spaces,
result,
order=False,
strict=True,
contains=CmpType.CONTAINS,
)


@then(parse("the result should not contain:\n{result}"))
def result_should_not_contain(request, result, graph_spaces):
cmp_dataset(
Expand Down Expand Up @@ -758,3 +787,18 @@ def check_client_compatible(graph_spaces):
assert (
resp.error_code == ErrorCode.E_CLIENT_SERVER_INCOMPATIBLE
), f'The client was not rejected by server: {resp}'


def replace_result_with_cluster_info(result, class_fixture_variables):
pattern = r"\$\{.*?\}"
holders = set(re.findall(pattern, result))
cluster = class_fixture_variables.get("cluster")
assert cluster is not None, "Cannot get the cluster"
for holder in holders:
try:
eval_string = holder[2:-1]
value = eval(eval_string)
result = result.replace(holder, str(value))
except:
raise
return result
33 changes: 33 additions & 0 deletions tests/tck/features/admin/Sessions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2021 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
Feature: Test sessions

Background:
Given a nebulacluster with 3 graphd and 1 metad and 1 storaged

Scenario: Show sessions
When executing query:
"""
SHOW SESSIONS;
"""
Then the result should contain:
| SessionId | UserName | SpaceName | CreateTime | UpdateTime | GraphAddr | Timezone | ClientIp |
| /\d+/ | "root" | "" | /.*/ | /.*/ | /.*/ | 0 | "127.0.0.1" |
When executing query:
"""
CREATE USER user1 WITH PASSWORD 'nebula1';
CREATE SPACE s1(vid_type=int);
USE s1;
"""
Then the execution should be successful
And wait 1 seconds
When login "graphd[1]" with "user1" and "nebula1"
And executing query:
"""
SHOW SESSIONS;
"""
Then the result should contain, replace the holders with cluster info:
| SessionId | UserName | SpaceName | CreateTime | UpdateTime | GraphAddr | Timezone | ClientIp |
| /\d+/ | "root" | "s1" | /.*/ | /.*/ | "127.0.0.1:${cluster.graphd_processes[0].tcp_port}" | 0 | "127.0.0.1" |
| /\d+/ | "user1" | "" | /.*/ | /.*/ | "127.0.0.1:${cluster.graphd_processes[1].tcp_port}" | 0 | "127.0.0.1" |

0 comments on commit 3d0af8d

Please sign in to comment.