Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tck test cases for session #3486

Merged
merged 5 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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+)\]"
HarrisChu marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -30,6 +30,7 @@
response,
resp_ok,
params,
parse_service_index,
)
from tests.common.nebula_service import NebulaService
from tests.tck.utils.table import dataset, table
Expand Down Expand Up @@ -338,6 +339,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 @@ -608,6 +624,19 @@ def result_should_contain(request, result, graph_spaces):
)


@then(parse("the result should contain, replace the holders with cluster info:\n{result}"))
HarrisChu marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -804,3 +833,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 3 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" |