memgraph/tests/drivers/python/v4_1/max_query_length.py
antonio2368 0bcc1d67bc
Add support for Bolt v4(.1) (#10)
* Added handshake support
* Add support for v4 hello and goodbye
* Add support for pulling n results
* Add support for transactions
* Add pull n for the dump
* Add support for NOOP
* Add support for multiple queries
* Update bolt session to support qid
* Update drivers test with multiple versions and go
* Extract failure handling into a function
* Use unique ptr instead of optional for query execution
* Destroy stream before query execution

Co-authored-by: Antonio Andelic <antonio.andelic@memgraph.io>
2020-10-16 12:49:33 +02:00

40 lines
1.4 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from neo4j import GraphDatabase, basic_auth
driver = GraphDatabase.driver("bolt://localhost:7687",
auth=basic_auth("", ""),
encrypted=False)
query_template = 'CREATE (n {name:"%s"})'
template_size = len(query_template) - 2 # because of %s
min_len = 1
max_len = 1000000
# binary search because we have to find the maximum size (in number of chars)
# of a query that can be executed via driver
while True:
assert min_len > 0 and max_len > 0, \
"The lengths have to be positive values! If this happens something" \
" is terrible wrong with min & max lengths OR the database" \
" isn't available."
property_size = (max_len + min_len) // 2
try:
driver.session().run(query_template % ("a" * property_size)).consume()
if min_len == max_len or property_size + 1 > max_len:
break
min_len = property_size + 1
except Exception as e:
print("Query size %s is too big!" % (template_size + property_size))
max_len = property_size - 1
assert property_size == max_len, "max_len probably has to be increased!"
print("\nThe max length of a query from Python driver is: %s\n" %
(template_size + property_size))
# sessions are not closed bacause all sessions that are
# executed with wrong query size might be broken
driver.close()