From 6f875882148d68d55828374938f86c593df97b34 Mon Sep 17 00:00:00 2001
From: Marko Budiselic <marko.budiselic@memgraph.io>
Date: Tue, 7 Mar 2017 12:44:40 +0100
Subject: [PATCH] First version of external integration test.

Summary: First version of external integration test.

Reviewers: matej.gradicek, dgleich, teon.banek, mferencevic

Reviewed By: mferencevic

Subscribers: buda

Differential Revision: https://phabricator.memgraph.io/D81
---
 .arcconfig       |  5 +++++
 README.md        | 11 +++++++++++
 dbms/.gitignore  |  2 ++
 init             | 45 ++++++++++++++++++++++++++++++++++++++++++++
 run              | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 tests/.gitignore |  2 ++
 6 files changed, 114 insertions(+)
 create mode 100644 .arcconfig
 create mode 100644 dbms/.gitignore
 create mode 100755 init
 create mode 100755 run
 create mode 100644 tests/.gitignore

diff --git a/.arcconfig b/.arcconfig
new file mode 100644
index 000000000..3f9c578bc
--- /dev/null
+++ b/.arcconfig
@@ -0,0 +1,5 @@
+{
+  "project_id" : "memgraph",
+  "conduit_uri" : "https://phabricator.memgraph.io",
+  "phabricator_uri" : "https://phabricator.memgraph.io"
+}
diff --git a/README.md b/README.md
index e520b5989..7008deee6 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,12 @@
 # Memgraph quality assurance
+
+In order to test dressipi's queries agains memgraph the following commands have
+to be executed:
+    1. ./init [Dxyz] # downloads query implementations + memgraph
+                     # (the auth is manually for now) + optionally user can
+                     # define arcanist diff which will be applied on the
+                     # memgraph source code
+    2. ./run         # compiles and runs database instance, also runs the
+                     # test queries
+
+TODO: automate further
diff --git a/dbms/.gitignore b/dbms/.gitignore
new file mode 100644
index 000000000..d6b7ef32c
--- /dev/null
+++ b/dbms/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
diff --git a/init b/init
new file mode 100755
index 000000000..d1575c01b
--- /dev/null
+++ b/init
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+# exit if any subcommand returns a non-zero status
+set -e
+
+script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+# optional argument; if diff_id exists arcanist patch will be applied
+arcanist_diff_id=${1:-""}
+
+# install all dependencies on debian based operating systems
+for pkg in git arcanist python3-virtualenv python3-pip; do
+    dpkg -s $pkg 2>/dev/null >/dev/null || sudo apt-get -y install $pkg
+done
+
+# TODO: use pullbot and read a password from program arg or env var
+#       (in order to use this script inside CI infrastructure)
+
+# clean tests folder
+tests_folder=${script_dir}/tests
+rm -rf ${tests_folder}/*
+
+# clone dressipi's tests
+cd ${tests_folder}
+git clone https://phabricator.memgraph.io/source/pilot_dressipi.git
+
+# clean dbms folder
+dbms_folder=${script_dir}/dbms
+rm -rf ${dbms_folder}/*
+
+# clone memgraph & checkout right commit
+cd ${dbms_folder}
+git clone https://phabricator.memgraph.io/diffusion/MG/memgraph.git
+memgraph_folder=${dbms_folder}/memgraph
+cd ${memgraph_folder}
+git checkout dev
+# optionally apply arcanist patch
+if [[ !  -z  ${arcanist_diff_id}  ]]; then
+    # nocommit is here because arc tries to commit the patch
+    # and it fails if user isn't set (inside CI infrastructure the user
+    # probably won't be defined because CI infrastructure doesn't push
+    # any code back to the repository)
+    arc parch ${arcanist_diff_id} --nocommit
+fi
+./init
diff --git a/run b/run
new file mode 100755
index 000000000..9e27af659
--- /dev/null
+++ b/run
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+# exit if any subcommand returns a non-zero status
+set -e
+
+## build memgraph
+
+# save the path where this script is
+script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+memgraph_src_dir=${script_dir}/dbms/memgraph
+memgraph_build_dir=${script_dir}/dbms/memgraph/build
+
+# compile memgraph
+cd ${memgraph_build_dir}
+cmake ..
+make -j8
+make copy_hardcoded_queries
+
+# setup dressipi
+cd ${script_dir}/tests/pilot_dressipi
+# setup ve
+if [ ! -d "ve3" ]; then
+    virtualenv -p python3 ve3
+    source ve3/bin/activate
+    pip3 install -r requirements.txt
+fi
+
+# binary is available after the build
+binary_name=$(find ${memgraph_build_dir}/ -maxdepth 1 -executable -name "memgraph*")
+# get full path to memgraph config
+config_path="${memgraph_src_dir}/config/memgraph.yaml"
+# run memgraph
+MEMGRAPH_CONFIG=${config_path} ${binary_name} &
+
+# the script has to be carefull because one process has been detached
+set +e
+
+## run tests
+
+# run Dressipi test
+source ve3/bin/activate
+python run.py
+exit_code=$?
+
+# cleanup
+pkill -9 -f "${binary_name}"
+
+# return test status
+exit $exit_code
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 000000000..d6b7ef32c
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore