Changeset: b517cb6ce8a4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b517cb6ce8a4
Modified Files:
        sql/test/testdb-reload/Tests/reload.py
        testing/process.py
        testing/sqllogictest.py
Branch: default
Log Message:

process.server now stores connection URIs (from .conn file) in .urls (a list).
process.client and sqllogictest.connect use the URI to connect if the
server named argument is used.
Also some cleanup.


diffs (190 lines):

diff --git a/sql/test/testdb-reload/Tests/reload.py 
b/sql/test/testdb-reload/Tests/reload.py
--- a/sql/test/testdb-reload/Tests/reload.py
+++ b/sql/test/testdb-reload/Tests/reload.py
@@ -83,7 +83,8 @@ if len(sys.argv) == 2 and sys.argv[1] ==
     output = ''.join(d2out).splitlines(keepends=True)
     while len(output) > 0 and output[0].startswith('--'):
         del output[0]
-    stableout = os.path.join(tstsrcdir, '..', '..', 'testdb', 'Tests', 
'dump-nogeom.stable.out')
+    stableout = os.path.join(tstsrcdir, os.pardir, os.pardir,
+                             'testdb', 'Tests', 'dump-nogeom.stable.out')
     with open(stableout, encoding='utf-8') as fil:
         stable = fil.readlines()
     import difflib
diff --git a/testing/process.py b/testing/process.py
--- a/testing/process.py
+++ b/testing/process.py
@@ -53,8 +53,10 @@ def _delfiles():
         except OSError:
             pass
 
+
 atexit.register(_delfiles)
 
+
 def _remainingtime(endtime):
     if endtime is None:
         return None
@@ -63,6 +65,7 @@ def _remainingtime(endtime):
         raise queue.Empty
     return endtime - curtime
 
+
 class _BufferedPipe:
     def __init__(self, fd):
         self._queue = queue.Queue()
@@ -79,8 +82,6 @@ class _BufferedPipe:
         self._thread.start()
 
     def _readerthread(self, fh, q):
-        s = 0
-        w = 0
         first = True
         while self._continue:
             if verbose:
@@ -180,6 +181,7 @@ class _BufferedPipe:
                 break
         return self._empty.join(ret)
 
+
 # signals that by default produce a core dump, i.e. bad
 # this of course doesn't work on Windows
 _coresigs = set()
@@ -228,6 +230,7 @@ try:
 except AttributeError:
     pass
 
+
 class Popen(subprocess.Popen):
     def __init__(self, *args, **kwargs):
         self.dotmonetdbfile = None
@@ -246,8 +249,11 @@ class Popen(subprocess.Popen):
             self.wait()
         self._clean_dotmonetdbfile()
         super().__exit__(exc_type, value, traceback)
-        if self.returncode and self.returncode < 0 and -self.returncode in 
_coresigs:
-            raise RuntimeError(f'process exited with coredump generating 
signal {signal.Signals(-self.returncode)}')
+        if self.returncode and \
+           self.returncode < 0 and \
+           -self.returncode in _coresigs:
+            raise RuntimeError('process exited with coredump generating signal'
+                               f' {signal.Signals(-self.returncode)}')
 
     def __del__(self):
         if self._child_created and self.returncode is None:
@@ -279,7 +285,8 @@ class Popen(subprocess.Popen):
 
     def communicate(self, input=None, timeout=None):
         # since we always use threads for stdout/stderr, we can just read()
-        if not isinstance(self.stdout, _BufferedPipe) and not 
isinstance(self.stderr, _BufferedPipe):
+        if not isinstance(self.stdout, _BufferedPipe) and \
+           not isinstance(self.stderr, _BufferedPipe):
             if verbose:
                 print('relegating communicate to super()', flush=True)
             return super().communicate(input=input, timeout=timeout)
@@ -317,6 +324,7 @@ class Popen(subprocess.Popen):
         self.wait()
         return stdout, stderr
 
+
 class client(Popen):
     def __init__(self, lang, args=[], stdin=None, stdout=None, stderr=None,
                  server=None, port=None, dbname=None, host=None,
@@ -377,7 +385,10 @@ class client(Popen):
         # if server instance is specified, it provides defaults for
         # database name and port
         if server is not None:
-            if port is None and dbname is None and hasattr(server, 'usock') 
and server.usock is not None:
+            if port is None and dbname is None and host is None and 
server.urls:
+                dbname = server.urls[0]
+            elif port is None and dbname is None and \
+                 hasattr(server, 'usock') and server.usock is not None:
                 dbname = server.usock
             else:
                 if port is None:
@@ -422,7 +433,7 @@ class client(Popen):
             if host:
                 cmd.append(f'--host={host}')
         if verbose:
-            print('Executing: ' + ' '.join(cmd +  args), flush=True)
+            print('Executing: ' + ' '.join(cmd + args), flush=True)
         if stdin is None:
             # if no input provided, use /dev/null as input
             stdin = DEVNULL
@@ -457,6 +468,7 @@ class client(Popen):
         if verbose:
             print('client created', flush=True)
 
+
 class server(Popen):
     def __init__(self, args=[], stdin=None, stdout=None, stderr=None,
                  mapiport=None, dbname=os.getenv('TSTDB'), dbfarm=None,
@@ -471,7 +483,7 @@ class server(Popen):
         if os.getenv('NOWAL'):
             cmd.extend(['--set', 'sql_debug=128'])
         if verbose:
-            print('Default server: ' + ' '.join(cmd +  args))
+            print('Default server: ' + ' '.join(cmd + args))
         if notrace and '--trace' in cmd:
             cmd.remove('--trace')
         if mapiport is not None:
@@ -554,7 +566,8 @@ class server(Popen):
             if args[i] == '--set' and i+1 < len(args):
                 s = args[i+1].partition('=')[0]
                 for j in range(len(cmd)):
-                    if cmd[j] == '--set' and j+1 < len(cmd) and 
cmd[j+1].startswith(s + '='):
+                    if cmd[j] == '--set' and \
+                       j + 1 < len(cmd) and cmd[j+1].startswith(s + '='):
                         del cmd[j:j+2]
                         break
         started = dbpath / '.started'
@@ -586,6 +599,7 @@ class server(Popen):
         self.dbname = dbname
         self.dbport = mapiport
         self.usock = None
+        self.urls = None
         while True:
             self.poll()
             if self.returncode is not None:
@@ -597,13 +611,14 @@ class server(Popen):
                 try:
                     with connfile.open() as fil:
                         conn = fil.read()
-                except:
+                except Exception:
                     if verbose:
                         print(f'failed to open {connfile}')
                     pass
                 else:
                     # retrieve mapi port if available
-                    for c in conn.splitlines():
+                    self.urls = conn.splitlines()
+                    for c in self.urls:
                         if c.startswith('mapi:monetdb:///') or \
                            (c.startswith('monetdb://') and 'sock=' in c):
                             if no_unix_sockets:
diff --git a/testing/sqllogictest.py b/testing/sqllogictest.py
--- a/testing/sqllogictest.py
+++ b/testing/sqllogictest.py
@@ -184,12 +184,15 @@ class SQLLogic:
         self.language = language
         self.hostname = hostname
         if server is not None:
-            if port is None:
-                port = server.dbport
-            if database is None:
-                database = server.dbname
-            if usock is None:
-                usock = server.usock
+            if port is None and database is None and usock is None and 
server.urls:
+                database = server.urls[0]
+            else:
+                if port is None:
+                    port = server.dbport
+                if database is None:
+                    database = server.dbname
+                if usock is None:
+                    usock = server.usock
         self.port = port
         self.database = database or 'demo'
         self.timeout = timeout
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to