Skip to content

Migrating stub tests to testkit #545

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

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 17 additions & 1 deletion testkitbackend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from inspect import getmembers, isfunction
from inspect import (
getmembers,
isfunction,
)
import io
from json import loads, dumps
import logging
import sys
Expand All @@ -28,9 +32,13 @@

import testkitbackend.requests as requests

buffer_handler = logging.StreamHandler(io.StringIO())
buffer_handler.setLevel(logging.DEBUG)

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
logging.getLogger("neo4j").addHandler(handler)
logging.getLogger("neo4j").addHandler(buffer_handler)
logging.getLogger("neo4j").setLevel(logging.DEBUG)

log = logging.getLogger("testkitbackend")
Expand Down Expand Up @@ -165,6 +173,14 @@ def _process(self, request):
def send_response(self, name, data):
""" Sends a response to backend.
"""
buffer_handler.acquire()
log_output = buffer_handler.stream.getvalue()
buffer_handler.stream.truncate(0)
buffer_handler.stream.seek(0)
buffer_handler.release()
if not log_output.endswith("\n"):
log_output += "\n"
self._wr.write(log_output.encode("utf-8"))
response = {"name": name, "data": data}
response = dumps(response)
log.info(">>> " + name + dumps(data))
Expand Down
44 changes: 41 additions & 3 deletions testkitbackend/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@
from testkitbackend.fromtestkit import to_meta_and_timeout


with open(path.join(path.dirname(__file__), "skipped_tests.json"), "r") as fd:
SKIPPED_TESTS = json.load(fd)
def load_config():
with open(path.join(path.dirname(__file__), "test_config.json"), "r") as fd:
config = json.load(fd)
return (config["skips"],
[k for k, v in config["features"].items() if v is True])


SKIPPED_TESTS, FEATURES = load_config()


def StartTest(backend, data):
Expand All @@ -35,6 +41,10 @@ def StartTest(backend, data):
backend.send_response("RunTest", {})


def GetFeatures(backend, data):
backend.send_response("FeatureList", {"features": FEATURES})


def NewDriver(backend, data):
auth_token = data["authorizationToken"]["data"]
data["authorizationToken"].mark_item_as_read_if_equals(
Expand Down Expand Up @@ -294,7 +304,8 @@ def ResultConsume(backend, data):
"serverInfo": {
"protocolVersion":
".".join(map(str, summary.server.protocol_version)),
"agent": summary.server.agent
"agent": summary.server.agent,
# "address": ":".join(map(str, summary.server.address))
}
})

Expand All @@ -310,3 +321,30 @@ def RetryableNegative(backend, data):
session_tracker = backend.sessions[key]
session_tracker.state = '-'
session_tracker.error_id = data.get('errorId', '')


def ForcedRoutingTableUpdate(backend, data):
driver_id = data["driverId"]
driver = backend.drivers[driver_id]
database = data["database"]
bookmarks = data["bookmarks"]
with driver._pool.refresh_lock:
driver._pool.create_routing_table(database)
driver._pool.update_routing_table(database=database,
bookmarks=bookmarks)
backend.send_response("Driver", {"id": driver_id})


def GetRoutingTable(backend, data):
driver_id = data["driverId"]
database = data["database"]
driver = backend.drivers[driver_id]
routing_table = driver._pool.routing_tables[database]
response_data = {
"database": routing_table.database,
"ttl": routing_table.ttl,
}
for role in ("routers", "readers", "writers"):
addresses = routing_table.__getattribute__(role)
response_data[role] = list(map(str, addresses))
backend.send_response("RoutingTable", response_data)
28 changes: 0 additions & 28 deletions testkitbackend/skipped_tests.json

This file was deleted.

37 changes: 37 additions & 0 deletions testkitbackend/test_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"skips": {
"stub.routing.Routing.test_should_retry_write_until_success_with_leader_change_using_tx_function":
"Driver closes connection to router if DNS resolved name not in routing table",
"stub.routing.RoutingV3.test_should_retry_write_until_success_with_leader_change_using_tx_function":
"Driver closes connection to router if DNS resolved name not in routing table",
"stub.routing.RoutingV4.test_should_retry_write_until_success_with_leader_change_using_tx_function":
"Driver closes connection to router if DNS resolved name not in routing table",
"stub.routing.Routing.test_should_retry_write_until_success_with_leader_shutdown_during_tx_using_tx_function":
"Driver closes connection to router if DNS resolved name not in routing table",
"stub.routing.RoutingV3.test_should_retry_write_until_success_with_leader_shutdown_during_tx_using_tx_function":
"Driver closes connection to router if DNS resolved name not in routing table",
"stub.routing.RoutingV4.test_should_retry_write_until_success_with_leader_shutdown_during_tx_using_tx_function":
"Driver closes connection to router if DNS resolved name not in routing table",
"stub.routing.Routing.test_should_successfully_acquire_rt_when_router_ip_changes":
"Test makes assumptions about how verify_connectivity is implemented",
"stub.routing.RoutingV3.test_should_successfully_acquire_rt_when_router_ip_changes":
"Test makes assumptions about how verify_connectivity is implemented",
"stub.routing.RoutingV4.test_should_successfully_acquire_rt_when_router_ip_changes":
"Test makes assumptions about how verify_connectivity is implemented",
"stub.retry.TestRetryClustering.test_retry_ForbiddenOnReadOnlyDatabase_ChangingWriter":
"Test makes assumptions about how verify_connectivity is implemented",
"stub.authorization.AuthorizationTests.test_should_retry_on_auth_expired_on_begin_using_tx_function":
"Flaky: test requires the driver to contact servers in a specific order",
"stub.authorization.AuthorizationTestsV3.test_should_retry_on_auth_expired_on_begin_using_tx_function":
"Flaky: test requires the driver to contact servers in a specific order",
"stub.authorization.AuthorizationTestsV4.test_should_retry_on_auth_expired_on_begin_using_tx_function":
"Flaky: test requires the driver to contact servers in a specific order"
},
"features": {
"AuthorizationExpiredTreatment": true,
"Optimization:ImplicitDefaultArguments": true,
"Optimization:MinimalResets": "Driver resets some clean connections when put back into pool",
"Optimization:ConnectionReuse": true,
"Optimization:PullPipelining": true
}
}
4 changes: 3 additions & 1 deletion tests/performance/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class ReadWorkload(object):
def setup_class(cls):
cls.server = server = RemoteGraphDatabaseServer()
server.start()
cls.driver = GraphDatabase.driver(server.server_uri, auth=server.auth_token, encrypted=server.encrypted)
cls.driver = GraphDatabase.driver(server.server_uri,
auth=server.auth_token,
encrypted=server.encrypted)

@classmethod
def teardown_class(cls):
Expand Down
11 changes: 1 addition & 10 deletions tests/performance/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,17 @@
# limitations under the License.


from test.integration.tools import IntegrationTestCase

from os import makedirs, remove
from os.path import basename, dirname, join as path_join, realpath, isfile, expanduser
import platform
from unittest import TestCase, SkipTest
from shutil import copyfile
from sys import exit, stderr

try:
from urllib.request import urlretrieve
except ImportError:
from urllib import urlretrieve

from boltkit.controller import WindowsController, UnixController

from neo4j import GraphDatabase
from neo4j.exceptions import AuthError

from test.env import NEO4J_USER, NEO4J_PASSWORD, NEO4J_SERVER_URI
from tests.env import NEO4J_USER, NEO4J_PASSWORD, NEO4J_SERVER_URI


def is_listening(address):
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ coverage
pytest
pytest-benchmark
pytest-cov
pytest-mock
teamcity-messages
Loading