Skip to content

Commit 57dd539

Browse files
authored
Testkit backend: new messages, more logging (#547)
1 parent c1bfb87 commit 57dd539

File tree

4 files changed

+93
-31
lines changed

4 files changed

+93
-31
lines changed

testkitbackend/backend.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
17-
from inspect import getmembers, isfunction
17+
from inspect import (
18+
getmembers,
19+
isfunction,
20+
)
21+
import io
1822
from json import loads, dumps
1923
import logging
2024
import sys
@@ -28,9 +32,13 @@
2832

2933
import testkitbackend.requests as requests
3034

35+
buffer_handler = logging.StreamHandler(io.StringIO())
36+
buffer_handler.setLevel(logging.DEBUG)
37+
3138
handler = logging.StreamHandler(sys.stdout)
3239
handler.setLevel(logging.DEBUG)
3340
logging.getLogger("neo4j").addHandler(handler)
41+
logging.getLogger("neo4j").addHandler(buffer_handler)
3442
logging.getLogger("neo4j").setLevel(logging.DEBUG)
3543

3644
log = logging.getLogger("testkitbackend")
@@ -165,6 +173,14 @@ def _process(self, request):
165173
def send_response(self, name, data):
166174
""" Sends a response to backend.
167175
"""
176+
buffer_handler.acquire()
177+
log_output = buffer_handler.stream.getvalue()
178+
buffer_handler.stream.truncate(0)
179+
buffer_handler.stream.seek(0)
180+
buffer_handler.release()
181+
if not log_output.endswith("\n"):
182+
log_output += "\n"
183+
self._wr.write(log_output.encode("utf-8"))
168184
response = {"name": name, "data": data}
169185
response = dumps(response)
170186
log.info(">>> " + name + dumps(data))

testkitbackend/requests.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@
2323
from testkitbackend.fromtestkit import to_meta_and_timeout
2424

2525

26-
with open(path.join(path.dirname(__file__), "skipped_tests.json"), "r") as fd:
27-
SKIPPED_TESTS = json.load(fd)
26+
def load_config():
27+
with open(path.join(path.dirname(__file__), "test_config.json"), "r") as fd:
28+
config = json.load(fd)
29+
return (config["skips"],
30+
[k for k, v in config["features"].items() if v is True])
31+
32+
33+
SKIPPED_TESTS, FEATURES = load_config()
2834

2935

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

3743

44+
def GetFeatures(backend, data):
45+
backend.send_response("FeatureList", {"features": FEATURES})
46+
47+
3848
def NewDriver(backend, data):
3949
auth_token = data["authorizationToken"]["data"]
4050
data["authorizationToken"].mark_item_as_read_if_equals(
@@ -310,3 +320,30 @@ def RetryableNegative(backend, data):
310320
session_tracker = backend.sessions[key]
311321
session_tracker.state = '-'
312322
session_tracker.error_id = data.get('errorId', '')
323+
324+
325+
def ForcedRoutingTableUpdate(backend, data):
326+
driver_id = data["driverId"]
327+
driver = backend.drivers[driver_id]
328+
database = data["database"]
329+
bookmarks = data["bookmarks"]
330+
with driver._pool.refresh_lock:
331+
driver._pool.create_routing_table(database)
332+
driver._pool.update_routing_table(database=database,
333+
bookmarks=bookmarks)
334+
backend.send_response("Driver", {"id": driver_id})
335+
336+
337+
def GetRoutingTable(backend, data):
338+
driver_id = data["driverId"]
339+
database = data["database"]
340+
driver = backend.drivers[driver_id]
341+
routing_table = driver._pool.routing_tables[database]
342+
response_data = {
343+
"database": routing_table.database,
344+
"ttl": routing_table.ttl,
345+
}
346+
for role in ("routers", "readers", "writers"):
347+
addresses = routing_table.__getattribute__(role)
348+
response_data[role] = list(map(str, addresses))
349+
backend.send_response("RoutingTable", response_data)

testkitbackend/skipped_tests.json

Lines changed: 0 additions & 28 deletions
This file was deleted.

testkitbackend/test_config.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"skips": {
3+
"stub.routing.Routing.test_should_retry_write_until_success_with_leader_change_using_tx_function":
4+
"Driver closes connection to router if DNS resolved name not in routing table",
5+
"stub.routing.RoutingV3.test_should_retry_write_until_success_with_leader_change_using_tx_function":
6+
"Driver closes connection to router if DNS resolved name not in routing table",
7+
"stub.routing.RoutingV4.test_should_retry_write_until_success_with_leader_change_using_tx_function":
8+
"Driver closes connection to router if DNS resolved name not in routing table",
9+
"stub.routing.Routing.test_should_retry_write_until_success_with_leader_shutdown_during_tx_using_tx_function":
10+
"Driver closes connection to router if DNS resolved name not in routing table",
11+
"stub.routing.RoutingV3.test_should_retry_write_until_success_with_leader_shutdown_during_tx_using_tx_function":
12+
"Driver closes connection to router if DNS resolved name not in routing table",
13+
"stub.routing.RoutingV4.test_should_retry_write_until_success_with_leader_shutdown_during_tx_using_tx_function":
14+
"Driver closes connection to router if DNS resolved name not in routing table",
15+
"stub.routing.Routing.test_should_successfully_acquire_rt_when_router_ip_changes":
16+
"Test makes assumptions about how verify_connectivity is implemented",
17+
"stub.routing.RoutingV3.test_should_successfully_acquire_rt_when_router_ip_changes":
18+
"Test makes assumptions about how verify_connectivity is implemented",
19+
"stub.routing.RoutingV4.test_should_successfully_acquire_rt_when_router_ip_changes":
20+
"Test makes assumptions about how verify_connectivity is implemented",
21+
"stub.retry.TestRetryClustering.test_retry_ForbiddenOnReadOnlyDatabase_ChangingWriter":
22+
"Test makes assumptions about how verify_connectivity is implemented",
23+
"stub.authorization.AuthorizationTests.test_should_retry_on_auth_expired_on_begin_using_tx_function":
24+
"Flaky: test requires the driver to contact servers in a specific order",
25+
"stub.authorization.AuthorizationTestsV3.test_should_retry_on_auth_expired_on_begin_using_tx_function":
26+
"Flaky: test requires the driver to contact servers in a specific order",
27+
"stub.authorization.AuthorizationTestsV4.test_should_retry_on_auth_expired_on_begin_using_tx_function":
28+
"Flaky: test requires the driver to contact servers in a specific order"
29+
},
30+
"features": {
31+
"AuthorizationExpiredTreatment": true,
32+
"Optimization:ImplicitDefaultArguments": true,
33+
"Optimization:MinimalResets": "Driver resets some clean connections when put back into pool",
34+
"Optimization:ConnectionReuse": true,
35+
"Optimization:PullPipelining": true
36+
}
37+
}

0 commit comments

Comments
 (0)