gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: use integration test helpers everywher


From: gnunet
Subject: [libeufin] branch master updated: use integration test helpers everywhere
Date: Mon, 08 Jun 2020 14:27:19 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 142df41  use integration test helpers everywhere
142df41 is described below

commit 142df4189b48f00ebf0b227ff646dc62a86efe40
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Mon Jun 8 17:57:09 2020 +0530

    use integration test helpers everywhere
---
 integration-tests/test-ebics-backup.py       | 70 ++--------------------------
 integration-tests/test-ebics-highlevel.py    |  2 -
 integration-tests/test-ebics.py              | 69 ++-------------------------
 integration-tests/test-loopback-highlevel.py | 48 ++-----------------
 integration-tests/test-sandbox.py            | 38 ++-------------
 integration-tests/test-taler-facade.py       | 53 ++-------------------
 integration-tests/util.py                    | 42 +++++++++--------
 7 files changed, 41 insertions(+), 281 deletions(-)

diff --git a/integration-tests/test-ebics-backup.py 
b/integration-tests/test-ebics-backup.py
index ea51f6c..7b4b126 100755
--- a/integration-tests/test-ebics-backup.py
+++ b/integration-tests/test-ebics-backup.py
@@ -8,6 +8,8 @@ import socket
 import hashlib
 import base64
 
+from util import startNexus, startSandbox
+
 # Steps implemented in this test.
 #
 # 0 Prepare sandbox.
@@ -52,82 +54,20 @@ NEXUS_DB="test-nexus.sqlite3"
 
 def fail(msg):
     print(msg)
-    nexus.terminate()
-    sandbox.terminate()
     exit(1)
 
-
-def checkPorts(ports):
-    for i in ports:
-        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        try:
-            s.bind(("0.0.0.0", i))
-            s.close()
-        except:
-            print("Port {} is not available".format(i))
-            exit(77)
-
-
 def assertResponse(response):
     if response.status_code != 200:
         print("Test failed on URL: {}".format(response.url))
         # stdout/stderr from both services is A LOT of text.
         # Confusing to dump all that to console.
         print("Check nexus.log and sandbox.log, probably under /tmp")
-        nexus.terminate()
-        sandbox.terminate()
         exit(1)
     # Allows for finer grained checks.
     return response
 
-
-# -1 Clean databases and start services.
-os.chdir("..")
-assert 0 == call(["rm", "-f", "sandbox/libeufin-sandbox.sqlite3"])
-assert 0 == call(["rm", "-f", "nexus/{}".format(NEXUS_DB)])
-DEVNULL = open(os.devnull, "w")
-
-assert 0 == call(
-    ["./gradlew", "nexus:run", "--console=plain", "--args=superuser admin 
--password x --db-name={}".format(NEXUS_DB)]
-)
-
-# Start nexus
-checkPorts([5001])
-nexus = Popen(
-    ["./gradlew", "nexus:run", "--console=plain", "--args=serve 
--db-name={}".format(NEXUS_DB)],
-    stdout=PIPE,
-    stderr=PIPE,
-)
-for i in range(10):
-    try:
-        get("http://localhost:5001/";)
-    except:
-        if i == 9:
-            nexus.terminate()
-            stdout, stderr = nexus.communicate()
-            print("Nexus timed out")
-            print("{}\n{}".format(stdout.decode(), stderr.decode()))
-            exit(77)
-        sleep(2)
-        continue
-    break
-# Start sandbox
-checkPorts([5000])
-sandbox = Popen(["./gradlew", "sandbox:run"], stdout=PIPE, stderr=PIPE)
-for i in range(10):
-    try:
-        get("http://localhost:5000/";)
-    except:
-        if i == 9:
-            nexus.terminate()
-            sandbox.terminate()
-            stdout, stderr = nexus.communicate()
-            print("Sandbox timed out")
-            print("{}\n{}".format(stdout.decode(), stderr.decode()))
-            exit(77)
-        sleep(2)
-        continue
-    break
+startNexus(NEXUS_DB)
+startSandbox()
 
 # 0.a
 assertResponse(
@@ -227,6 +167,4 @@ assertResponse(
     )
 )
 
-nexus.terminate()
-sandbox.terminate()
 print("Test passed!")
diff --git a/integration-tests/test-ebics-highlevel.py 
b/integration-tests/test-ebics-highlevel.py
index 22ad4b3..f78f09f 100755
--- a/integration-tests/test-ebics-highlevel.py
+++ b/integration-tests/test-ebics-highlevel.py
@@ -78,8 +78,6 @@ def assertResponse(response):
     return response
 
 
-os.chdir("..")
-
 startNexus(NEXUS_DB)
 startSandbox()
 
diff --git a/integration-tests/test-ebics.py b/integration-tests/test-ebics.py
index 5c37a58..04d1c81 100755
--- a/integration-tests/test-ebics.py
+++ b/integration-tests/test-ebics.py
@@ -8,6 +8,8 @@ import socket
 import hashlib
 import base64
 
+from util import startNexus, startSandbox
+
 # Steps implemented in this test.
 #
 # 0 Prepare sandbox.
@@ -63,82 +65,21 @@ NEXUS_DB="test-nexus.sqlite3"
 
 def fail(msg):
     print(msg)
-    nexus.terminate()
-    sandbox.terminate()
     exit(1)
 
-
-def checkPorts(ports):
-    for i in ports:
-        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        try:
-            s.bind(("0.0.0.0", i))
-            s.close()
-        except:
-            print("Port {} is not available".format(i))
-            exit(77)
-
-
 def assertResponse(response):
     if response.status_code != 200:
         print("Test failed on URL: {}".format(response.url))
         # stdout/stderr from both services is A LOT of text.
         # Confusing to dump all that to console.
         print("Check nexus.log and sandbox.log, probably under /tmp")
-        nexus.terminate()
-        sandbox.terminate()
         exit(1)
     # Allows for finer grained checks.
     return response
 
+startSandbox()
+startNexus(NEXUS_DB)
 
-# -1 Clean databases and start services.
-os.chdir("..")
-assert 0 == call(["rm", "-f", "sandbox/libeufin-sandbox.sqlite3"])
-assert 0 == call(["rm", "-f", "nexus/{}".format(NEXUS_DB)])
-DEVNULL = open(os.devnull, "w")
-
-assert 0 == call(
-    ["./gradlew", "nexus:run", "--console=plain", "--args=superuser admin 
--password x --db-name={}".format(NEXUS_DB)]
-)
-
-# Start nexus
-checkPorts([5001])
-nexus = Popen(
-    ["./gradlew", "nexus:run", "--console=plain", "--args=serve 
--db-name={}".format(NEXUS_DB)],
-    stdout=PIPE,
-    stderr=PIPE,
-)
-for i in range(10):
-    try:
-        get("http://localhost:5001/";)
-    except:
-        if i == 9:
-            nexus.terminate()
-            stdout, stderr = nexus.communicate()
-            print("Nexus timed out")
-            print("{}\n{}".format(stdout.decode(), stderr.decode()))
-            exit(77)
-        sleep(2)
-        continue
-    break
-# Start sandbox
-checkPorts([5000])
-sandbox = Popen(["./gradlew", "sandbox:run"], stdout=PIPE, stderr=PIPE)
-for i in range(10):
-    try:
-        get("http://localhost:5000/";)
-    except:
-        if i == 9:
-            nexus.terminate()
-            sandbox.terminate()
-            stdout, stderr = nexus.communicate()
-            print("Sandbox timed out")
-            print("{}\n{}".format(stdout.decode(), stderr.decode()))
-            exit(77)
-        sleep(2)
-        continue
-    break
 
 # 0.a
 assertResponse(
@@ -302,6 +243,4 @@ resp = assertResponse(
 if len(resp.json().get("transactions")) != 1:
     fail("Unexpected number of transactions; should be 1")
 
-nexus.terminate()
-sandbox.terminate()
 print("Test passed!")
diff --git a/integration-tests/test-loopback-highlevel.py 
b/integration-tests/test-loopback-highlevel.py
index 74d037e..dcda643 100755
--- a/integration-tests/test-loopback-highlevel.py
+++ b/integration-tests/test-loopback-highlevel.py
@@ -8,6 +8,8 @@ import socket
 import hashlib
 import base64
 
+from util import startSandbox, startNexus
+
 # Steps implemented in this test.
 #
 # 0 Prepare nexus.
@@ -33,62 +35,19 @@ NEXUS_DB="test-nexus.sqlite3"
 
 def fail(msg):
     print(msg)
-    nexus.terminate()
     exit(1)
 
-
-def checkPorts(ports):
-    for i in ports:
-        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        try:
-            s.bind(("0.0.0.0", i))
-            s.close()
-        except:
-            print("Port {} is not available".format(i))
-            exit(77)
-
-
 def assertResponse(response):
     if response.status_code != 200:
         print("Test failed on URL: {}".format(response.url))
         # stdout/stderr from both services is A LOT of text.
         # Confusing to dump all that to console.
         print("Check nexus.log and sandbox.log, probably under /tmp")
-        nexus.terminate()
         exit(1)
     # Allows for finer grained checks.
     return response
 
-
-# -1 Clean databases and start services.
-os.chdir("..")
-assert 0 == call(["rm", "-f", "nexus/{}".format(NEXUS_DB)])
-DEVNULL = open(os.devnull, "w")
-
-assert 0 == call(
-    ["./gradlew", "nexus:run", "--console=plain", "--args=superuser admin 
--password x --db-name={}".format(NEXUS_DB)]
-)
-
-# Start nexus
-checkPorts([5001])
-nexus = Popen(
-    ["./gradlew", "nexus:run", "--console=plain", "--args=serve 
--db-name={}".format(NEXUS_DB)],
-    stdout=PIPE,
-    stderr=PIPE,
-)
-for i in range(10):
-    try:
-        get("http://localhost:5001/";)
-    except:
-        if i == 9:
-            nexus.terminate()
-            stdout, stderr = nexus.communicate()
-            print("Nexus timed out")
-            print("{}\n{}".format(stdout.decode(), stderr.decode()))
-            exit(77)
-        sleep(2)
-        continue
-    break
+startNexus(NEXUS_DB)
 
 # 0.a, make a new nexus user.
 assertResponse(
@@ -120,5 +79,4 @@ assertResponse(
     )
 )
 
-nexus.terminate()
 print("Test passed!")
diff --git a/integration-tests/test-sandbox.py 
b/integration-tests/test-sandbox.py
index 944514a..ba9b709 100755
--- a/integration-tests/test-sandbox.py
+++ b/integration-tests/test-sandbox.py
@@ -8,6 +8,8 @@ import socket
 import hashlib
 import base64
 
+from util import startSandbox
+
 # EBICS details
 EBICS_URL = "http://localhost:5000/ebicsweb";
 HOST_ID = "HOST01"
@@ -24,53 +26,19 @@ BANK_ACCOUNT_LABEL = "savings"
 
 def fail(msg):
     print(msg)
-    sandbox.terminate()
     exit(1)
 
-
-def checkPorts(ports):
-    for i in ports:
-        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        try:
-            s.bind(("0.0.0.0", i))
-            s.close()
-        except:
-            print("Port {} is not available".format(i))
-            exit(77)
-
-
 def assertResponse(response):
     if response.status_code != 200:
         print("Test failed on URL: {}".format(response.url))
         # stdout/stderr from both services is A LOT of text.
         # Confusing to dump all that to console.
         print("Check sandbox.log, probably under /tmp")
-        sandbox.terminate()
         exit(1)
     # Allows for finer grained checks.
     return response
 
-
-# -1 Clean databases and start the service.
-os.chdir("..")
-assert 0 == call(["rm", "-f", "sandbox/libeufin-sandbox.sqlite3"])
-DEVNULL = open(os.devnull, "w")
-
-# Start sandbox
-checkPorts([5000])
-sandbox = Popen(["./gradlew", "sandbox:run"], stdout=PIPE, stderr=PIPE)
-for i in range(10):
-    try:
-        get("http://localhost:5000/";)
-    except:
-        if i == 9:
-            sandbox.terminate()
-            print("Sandbox timed out")
-            print("{}\n{}".format(stdout.decode(), stderr.decode()))
-            exit(77)
-        sleep(2)
-        continue
-    break
+startSandbox()
 
 # Create a Ebics host.
 assertResponse(
diff --git a/integration-tests/test-taler-facade.py 
b/integration-tests/test-taler-facade.py
index 8b2e15d..30025cc 100755
--- a/integration-tests/test-taler-facade.py
+++ b/integration-tests/test-taler-facade.py
@@ -8,6 +8,8 @@ import socket
 import hashlib
 import base64
 
+from util import startNexus, startSandbox
+
 # Nexus user details
 USERNAME = "person"
 PASSWORD = "y"
@@ -40,8 +42,6 @@ SANDBOX_DB="/tmp/test-sandbox.sqlite3"
 
 def fail(msg):
     print(msg)
-    nexus.terminate()
-    sandbox.terminate()
     exit(1)
 
 def checkPorts(ports):
@@ -60,55 +60,14 @@ def assertResponse(response):
         # stdout/stderr from both services is A LOT of text.
         # Confusing to dump all that to console.
         print("Check nexus.log and sandbox.log, probably under /tmp")
-        nexus.terminate()
-        sandbox.terminate()
         exit(1)
     # Allows for finer grained checks.
     return response
 
-# Clean databases and start services.
-os.chdir("..")
-assert 0 == call(["rm", "-f", SANDBOX_DB])
-assert 0 == call(["rm", "-f", NEXUS_DB])
-DEVNULL = open(os.devnull, "w")
-
-assert 0 == call(
-    ["nexus", "superuser", "admin", "--password=x", 
"--db-name={}".format(NEXUS_DB)]
-)
 
-# start nexus
-checkPorts([5001])
-nexus = Popen(["nexus", "serve", "--db-name={}".format(NEXUS_DB)])
-for i in range(10):
-    try:
-        get("http://localhost:5001/";)
-    except:
-        if i == 9:
-            nexus.terminate()
-            print("Nexus timed out")
-            print("{}\n{}".format(stdout.decode(), stderr.decode()))
-            exit(77)
-        sleep(2)
-        continue
-    break
-
-# start sandbox
-checkPorts([5000])
-sandbox = Popen(["sandbox", "serve", "--db-name={}".format(SANDBOX_DB)])
-for i in range(10):
-    try:
-        get("http://localhost:5000/";)
-    except:
-        if i == 9:
-            nexus.terminate()
-            sandbox.terminate()
-            stdout, stderr = nexus.communicate()
-            print("Sandbox timed out")
-            print("{}\n{}".format(stdout.decode(), stderr.decode()))
-            exit(77)
-        sleep(2)
-        continue
-    break
+os.chdir("..")
+startNexus(NEXUS_DB)
+startSandbox()
 
 # make ebics host at sandbox
 assertResponse(
@@ -239,6 +198,4 @@ assertResponse(
 print("sleeping 100s")
 sleep(100)
 
-nexus.terminate()
-sandbox.terminate()
 print("Test passed!")
diff --git a/integration-tests/util.py b/integration-tests/util.py
index aae7f5e..86e3f6a 100644
--- a/integration-tests/util.py
+++ b/integration-tests/util.py
@@ -5,6 +5,7 @@ import socket
 from requests import post, get
 from time import sleep
 import atexit
+from pathlib import Path
 
 
 def checkPort(port):
@@ -13,21 +14,20 @@ def checkPort(port):
         s.bind(("0.0.0.0", port))
         s.close()
     except:
-        print("Port {} is not available".format(i))
+        print(f"Port {port} is not available")
         exit(77)
 
 
 def startSandbox():
-    check_call(["rm", "-f", "sandbox/libeufin-sandbox.sqlite3"])
-    check_call(["./gradlew", "sandbox:assemble"])
+    db_full_path = str(Path.cwd() / "libeufin-sandbox.sqlite3")
+    check_call(["rm", "-f", db_full_path])
+    check_call(["../gradlew", "-p", "..", "sandbox:assemble"])
     checkPort(5000)
-    sandbox = Popen(["./gradlew",
-        "sandbox:run",
-            "--console=plain",
-        "--args=serve"],
-            stdout=open("sandbox-stdout.log", "w"),
-            stderr=open("sandbox-stderr.log", "w"),
-            )
+    sandbox = Popen(
+        ["../gradlew", "-p", "..", "sandbox:run", "--console=plain", 
"--args=serve --db-name={}".format(db_full_path)],
+        stdout=open("sandbox-stdout.log", "w"),
+        stderr=open("sandbox-stderr.log", "w"),
+    )
     atexit.register(lambda: sandbox.terminate())
     for i in range(10):
         try:
@@ -43,29 +43,31 @@ def startSandbox():
         break
 
 
-def startNexus(dbfile):
-    check_call(["rm", "-f", "nexus/{}".format(dbfile)])
+def startNexus(dbname):
+    db_full_path = str(Path.cwd() / dbname)
+    check_call(["rm", "-f", "--", db_full_path])
     check_call(
-        [
-            "./gradlew",
-            "nexus:assemble",
-        ]
+        ["../gradlew", "-p", "..", "nexus:assemble",]
     )
     check_call(
         [
-            "./gradlew",
+            "../gradlew",
+            "-p",
+            "..",
             "nexus:run",
             "--console=plain",
-            "--args=superuser admin --password x --db-name={}".format(dbfile),
+            "--args=superuser admin --password x 
--db-name={}".format(db_full_path),
         ]
     )
     checkPort(5001)
     nexus = Popen(
         [
-            "./gradlew",
+            "../gradlew",
+            "-p",
+            "..",
             "nexus:run",
             "--console=plain",
-            "--args=serve --db-name={}".format(dbfile),
+            "--args=serve --db-name={}".format(db_full_path),
         ],
         stdout=open("nexus-stdout.log", "w"),
         stderr=open("nexus-stderr.log", "w"),

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]