gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: integration test util lib


From: gnunet
Subject: [libeufin] branch master updated: integration test util lib
Date: Mon, 08 Jun 2020 13:48:43 +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 ce7049b  integration test util lib
ce7049b is described below

commit ce7049b28e8809ffb2ea9fe86b05a05bcfc166c5
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Mon Jun 8 17:18:32 2020 +0530

    integration test util lib
---
 .gitignore                                |  2 +
 integration-tests/test-ebics-highlevel.py | 71 +++-----------------------
 integration-tests/test-taler-facade.py    |  7 ++-
 integration-tests/util.py                 | 85 +++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+), 69 deletions(-)

diff --git a/.gitignore b/.gitignore
index 054cedf..eb82cd2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,5 @@ presentation/*.out
 presentation/*.snm
 presentation/*.toc
 .idea/misc.xml
+__pycache__
+*.log
diff --git a/integration-tests/test-ebics-highlevel.py 
b/integration-tests/test-ebics-highlevel.py
index 3192fa1..22ad4b3 100755
--- a/integration-tests/test-ebics-highlevel.py
+++ b/integration-tests/test-ebics-highlevel.py
@@ -1,13 +1,13 @@
 #!/usr/bin/env python3
 
 from requests import post, get
-from subprocess import call, Popen, PIPE
 from time import sleep
 import os
-import socket
 import hashlib
 import base64
 
+from util import startNexus, startSandbox
+
 # Steps implemented in this test.
 #
 # 0 Prepare sandbox.
@@ -59,86 +59,29 @@ SUBSCRIBER_NAME = "Oliver Smith"
 BANK_ACCOUNT_LABEL = "savings"
 
 # Databases
-NEXUS_DB="test-nexus.sqlite3"
+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", "--args=serve"], 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(
@@ -284,6 +227,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-taler-facade.py 
b/integration-tests/test-taler-facade.py
index 8b1d9e9..8b2e15d 100755
--- a/integration-tests/test-taler-facade.py
+++ b/integration-tests/test-taler-facade.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 
 from requests import post, get
-from subprocess import call, Popen, PIPE
+from subprocess import call, Popen
 from time import sleep
 import os
 import socket
@@ -78,14 +78,13 @@ assert 0 == call(
 
 # start nexus
 checkPorts([5001])
-nexus = Popen(["nexus", "serve", "--db-name={}".format(NEXUS_DB)], 
stdout=PIPE, stderr=PIPE)
+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()
-            stdout, stderr = nexus.communicate()
             print("Nexus timed out")
             print("{}\n{}".format(stdout.decode(), stderr.decode()))
             exit(77)
@@ -95,7 +94,7 @@ for i in range(10):
 
 # start sandbox
 checkPorts([5000])
-sandbox = Popen(["sandbox", "serve", "--db-name={}".format(SANDBOX_DB)], 
stdout=PIPE, stderr=PIPE)
+sandbox = Popen(["sandbox", "serve", "--db-name={}".format(SANDBOX_DB)])
 for i in range(10):
     try:
         get("http://localhost:5000/";)
diff --git a/integration-tests/util.py b/integration-tests/util.py
new file mode 100644
index 0000000..aae7f5e
--- /dev/null
+++ b/integration-tests/util.py
@@ -0,0 +1,85 @@
+# Helpers for the integration tests.
+
+from subprocess import check_call, Popen, PIPE
+import socket
+from requests import post, get
+from time import sleep
+import atexit
+
+
+def checkPort(port):
+    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    try:
+        s.bind(("0.0.0.0", port))
+        s.close()
+    except:
+        print("Port {} is not available".format(i))
+        exit(77)
+
+
+def startSandbox():
+    check_call(["rm", "-f", "sandbox/libeufin-sandbox.sqlite3"])
+    check_call(["./gradlew", "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"),
+            )
+    atexit.register(lambda: sandbox.terminate())
+    for i in range(10):
+        try:
+            get("http://localhost:5000/";)
+        except:
+            if i == 9:
+                stdout, stderr = nexus.communicate()
+                print("Sandbox timed out")
+                print("{}\n{}".format(stdout.decode(), stderr.decode()))
+                exit(77)
+            sleep(2)
+            continue
+        break
+
+
+def startNexus(dbfile):
+    check_call(["rm", "-f", "nexus/{}".format(dbfile)])
+    check_call(
+        [
+            "./gradlew",
+            "nexus:assemble",
+        ]
+    )
+    check_call(
+        [
+            "./gradlew",
+            "nexus:run",
+            "--console=plain",
+            "--args=superuser admin --password x --db-name={}".format(dbfile),
+        ]
+    )
+    checkPort(5001)
+    nexus = Popen(
+        [
+            "./gradlew",
+            "nexus:run",
+            "--console=plain",
+            "--args=serve --db-name={}".format(dbfile),
+        ],
+        stdout=open("nexus-stdout.log", "w"),
+        stderr=open("nexus-stderr.log", "w"),
+    )
+    atexit.register(lambda: nexus.terminate())
+    for i in range(10):
+        try:
+            get("http://localhost:5001/";)
+        except:
+            if i == 9:
+                nexus.terminate()
+                print("Nexus timed out")
+                exit(77)
+            sleep(1)
+            continue
+        break
+    return nexus

-- 
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]