diff --git a/init b/init index 81f57fcb0..598c44de4 100755 --- a/init +++ b/init @@ -16,6 +16,7 @@ required_pkgs=(git arcanist # source code control optional_pkgs=(clang-format # source code formatting doxygen graphviz # source documentation generators php-cli # for user technical documentation generators + mono-runtime mono-mcs nodejs # for driver tests ) use_sudo=0 diff --git a/tests/drivers/.gitignore b/tests/drivers/.gitignore index 5f3bedada..4e898487f 100644 --- a/tests/drivers/.gitignore +++ b/tests/drivers/.gitignore @@ -1,10 +1,11 @@ # csharp driver csharp/*.dll csharp/*.exe +csharp/driver.* # java driver -java/*.jar java/*.class +java/*.jar # javascript driver javascript/node_modules diff --git a/tests/drivers/apollo_runs.yaml b/tests/drivers/apollo_runs.yaml new file mode 100644 index 000000000..e9e019d84 --- /dev/null +++ b/tests/drivers/apollo_runs.yaml @@ -0,0 +1,6 @@ +- name: drivers + commands: ./run.sh + infiles: + - . # all files present here + - ../../build_debug/memgraph # memgraph binary + enable_network: true diff --git a/tests/drivers/csharp/run.sh b/tests/drivers/csharp/run.sh index 871ed48a3..b89df9d11 100755 --- a/tests/drivers/csharp/run.sh +++ b/tests/drivers/csharp/run.sh @@ -1,37 +1,30 @@ -#!/bin/bash +#!/bin/bash -e -set -e +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$DIR" -script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd $script_dir +for i in mono mcs; do + if ! which $i >/dev/null; then + echo "Please install $i!" + exit 1 + fi +done -if ! which nuget >/dev/null; then - echo "Please install nuget!" - exit 1 +DRIVER=Neo4j.Driver.dll + +if [ ! -f $DRIVER ]; then + driver_dir=$( mktemp -d driver.XXXXXXXX ) || exit 1 + cd $driver_dir || exit 1 + # Driver downloaded from: https://www.nuget.org/packages/Neo4j.Driver/1.5.3 + wget -nv http://deps.memgraph.io/drivers/csharp/neo4j.driver.1.5.3.nupkg || exit 1 + unzip -q neo4j.driver.1.5.3.nupkg || exit 1 + cp lib/net452/Neo4j.Driver.dll .. || exit 1 + cd .. || exit 1 + rm -rf $driver_dir || exit 1 fi -if ! which mono >/dev/null; then - echo "Please install mono!" - exit 1 -fi - -if ! which mcs >/dev/null; then - echo "Please install mcs!" - exit 1 -fi - -driver=Neo4j.Driver -version=1.5.0 - -if [ ! -f $driver.dll ]; then - nuget_dir=`mktemp -d nuget.XXXXXXXX` || exit 1 - nuget install $driver -Version $version -OutputDirectory $nuget_dir || exit 1 - cp $nuget_dir/$driver.$version/lib/net452/$driver.dll ./ || exit 1 - rm -rf $nuget_dir || exit 1 -fi - -mcs -reference:$driver.dll Basic.cs +mcs -reference:$DRIVER Basic.cs mono Basic.exe -mcs -reference:$driver.dll Transactions.cs +mcs -reference:$DRIVER Transactions.cs mono Transactions.exe diff --git a/tests/drivers/java/run.sh b/tests/drivers/java/run.sh index fe98e5a39..5a5555243 100755 --- a/tests/drivers/java/run.sh +++ b/tests/drivers/java/run.sh @@ -1,24 +1,20 @@ -#!/bin/bash +#!/bin/bash -e -set -e +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$DIR" -JAVA=java -JAVAC=javac - -if ! which $JAVA >/dev/null; then - echo "Please install java!" - exit 1 -fi - -if ! which $JAVAC >/dev/null; then - echo "Please install javac!" - exit 1 -fi +for i in java javac; do + if ! which $i >/dev/null; then + echo "Please install $i!" + exit 1 + fi +done DRIVER=neo4j-java-driver.jar if [ ! -f $DRIVER ]; then - wget -O $DRIVER http://central.maven.org/maven2/org/neo4j/driver/neo4j-java-driver/1.3.1/neo4j-java-driver-1.3.1.jar || exit 1 + # Driver downloaded from: http://central.maven.org/maven2/org/neo4j/driver/neo4j-java-driver/1.5.2/neo4j-java-driver-1.5.2.jar + wget -nv http://deps.memgraph.io/drivers/java/neo4j-java-driver-1.5.2.jar -O $DRIVER || exit 1 fi javac -classpath .:$DRIVER Basic.java diff --git a/tests/drivers/javascript/run.sh b/tests/drivers/javascript/run.sh index 29cde8130..f003a5175 100755 --- a/tests/drivers/javascript/run.sh +++ b/tests/drivers/javascript/run.sh @@ -1,21 +1,19 @@ -#!/bin/bash +#!/bin/bash -e -set -e +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$DIR" -NODE=nodejs -NPM=npm - -if ! which $NODE >/dev/null; then - echo "Please install Node.JS!" +if ! which nodejs >/dev/null; then + echo "Please install nodejs!" exit 1 fi -if ! which $NPM >/dev/null; then - echo "Please install NPM!" - exit 1 +if [ ! -d node_modules ]; then + # Driver generated with: `npm install neo4j-driver` + wget -nv http://deps.memgraph.io/drivers/javascript/neo4j-javascript-driver-1.6.1.tar.gz -O driver.tar.gz || exit 1 + tar -xzf driver.tar.gz || exit 1 + rm driver.tar.gz || exit 1 fi -$NPM install neo4j-driver - -$NODE basic.js -$NODE max_query_length.js +nodejs basic.js +nodejs max_query_length.js diff --git a/tests/drivers/python/run.sh b/tests/drivers/python/run.sh index 25a011f2d..d23e81b69 100755 --- a/tests/drivers/python/run.sh +++ b/tests/drivers/python/run.sh @@ -1,29 +1,33 @@ -#!/bin/bash +#!/bin/bash -e -set -e - -VIRTUALENV=virtualenv -PIP=pip -PYTHON=python -WORKING_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -cd ${WORKING_DIR} +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$DIR" # system check -if ! which $VIRTUALENV >/dev/null; then +if ! which virtualenv >/dev/null; then echo "Please install virtualenv!" exit 1 fi # setup virtual environment if [ ! -d "ve3" ]; then + # Driver downloaded from: https://pypi.org/project/neo4j-driver/1.5.3/ + wget -nv http://deps.memgraph.io/drivers/python/neo4j-driver-1.5.3.tar.gz -O neo4j-driver.tar.gz || exit 1 + tar -xzf neo4j-driver.tar.gz || exit 1 + mv neo4j-driver-1.5.3 neo4j-driver || exit 1 virtualenv -p python3 ve3 || exit 1 + source ve3/bin/activate + cd neo4j-driver + python3 setup.py install || exit 1 + cd .. + deactivate + rm -rf neo4j-driver neo4j-driver.tar.gz || exit 1 fi + +# activate virtualenv source ve3/bin/activate -$PIP install --upgrade pip -$PIP install neo4j-driver==1.5.0 # execute test -$PYTHON basic.py -$PYTHON max_query_length.py -$PYTHON transactions.py +python3 basic.py || exit 1 +python3 max_query_length.py || exit 1 +python3 transactions.py || exit 1 diff --git a/tests/drivers/python/transactions.py b/tests/drivers/python/transactions.py index 43dc039da..9f5c2dcdf 100644 --- a/tests/drivers/python/transactions.py +++ b/tests/drivers/python/transactions.py @@ -41,10 +41,16 @@ with GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("", ""), session.run("UNWIND range(1, 100000) AS x CREATE ()") # Query that will run for a very long time, transient error expected. - with driver.session() as session: - try: + timed_out = False + try: + with driver.session() as session: session.run("MATCH (a), (b), (c), (d), (e), (f) RETURN COUNT(*) AS cnt") - except TransientError: - print("transient error") + except TransientError: + timed_out = True + + if timed_out: + print("The query timed out as was expected.") + else: + raise Exception("The query should have timed out, but it didn't!") print("All ok!") diff --git a/tests/drivers/run.sh b/tests/drivers/run.sh index e8de35921..99b90a16d 100755 --- a/tests/drivers/run.sh +++ b/tests/drivers/run.sh @@ -1,21 +1,74 @@ #!/bin/bash -pushd () { - command pushd "$@" > /dev/null -} +pushd () { command pushd "$@" > /dev/null; } +popd () { command popd "$@" > /dev/null; } -popd () { - command popd "$@" > /dev/null +function wait_for_server { + port=$1 + while ! nc -z -w 1 127.0.0.1 $port; do + sleep 0.1 + done + sleep 1 } DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd $DIR +cd "$DIR" +# Create a temporary directory. +tmpdir=/tmp/memgraph_drivers +if [ -d $tmpdir ]; then + rm -rf $tmpdir +fi +mkdir -p $tmpdir + +# Find memgraph binaries. +binary_dir="$DIR/../../build" +if [ ! -d $binary_dir ]; then + binary_dir="$DIR/../../build_debug" +fi + +# Start memgraph. +$binary_dir/memgraph \ + --durability-directory=$tmpdir \ + --query-execution-time-sec=5 \ + --session-inactivity-timeout=10 & +pid=$! +wait_for_server 7687 + +# Run all available tests +code_test=0 for i in *; do if [ ! -d $i ]; then continue; fi pushd $i echo "Running: $i" - ./run.sh || exit 1 + ./run.sh + code_test=$? + if [ $code_test -ne 0 ]; then + echo "FAILED: $i" + break + fi echo popd done + +# Stop memgraph. +kill $pid +wait -n +code_mg=$? + +# Temporary directory cleanup. +if [ -d $tmpdir ]; then + rm -rf $tmpdir +fi + +# Check memgraph exit code. +if [ $code_mg -ne 0 ]; then + echo "The memgraph process didn't terminate properly!" + exit $code_mg +fi + +# Check test exit code. +if [ $code_test -ne 0 ]; then + echo "One of the tests failed!" + exit $code_test +fi