memgraph/tests/drivers/javascript/v4_1/max_query_length.js
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

52 lines
1.7 KiB
JavaScript

// Determines how long could be a query executed
// from JavaScript driver.
//
// Performs binary search until the maximum possible
// query size has found.
// init driver
var neo4j = require('neo4j-driver');
var driver = neo4j.driver("bolt://localhost:7687",
neo4j.auth.basic("", ""),
{ encrypted: 'ENCRYPTION_OFF' });
// init state
var property_size = 0;
var min_len = 1;
var max_len = 1000000;
// hacking with JS and callbacks concept
function serial_execution() {
var next_size = [Math.floor((min_len + max_len) / 2)];
setInterval(function() {
if (next_size.length > 0) {
property_size = next_size.pop();
var query = "CREATE (n {name:\"" +
(new Array(property_size)).join("a")+ "\"})";
var session = driver.session();
session.run(query, {}).then(function (result) {
console.log("Success with the query length " + query.length);
if (min_len == max_len || property_size + 1 > max_len) {
console.log("\nThe max length of a query from JS driver is: " +
query.length + "\n");
session.close();
driver.close();
process.exit(0);
}
min_len = property_size + 1;
next_size.push(Math.floor((min_len + max_len) / 2));
}).catch(function (error) {
console.log("Failure with the query length " + query.length);
max_len = property_size - 1;
next_size.push(Math.floor((min_len + max_len) / 2));
}).then(function(){
session.close();
});
}
}, 100);
}
// execution
console.log("\nDetermine how long can be a query sent from JavaScript driver.");
serial_execution(); // I don't like JavaScript