From 5ff474442854babced6a94aa8eb0821532c6ba5a Mon Sep 17 00:00:00 2001 From: Ernest Allen Date: Wed, 27 Jun 2018 14:09:21 -0400 Subject: [PATCH 1/2] DISPATCH-1054 add console tests to cmake --- console/stand-alone/test/links.js | 13 ++++- tests/CMakeLists.txt | 1 + tests/system_tests_console.py | 84 +++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tests/system_tests_console.py diff --git a/console/stand-alone/test/links.js b/console/stand-alone/test/links.js index f07482f8de..f6aff448bf 100644 --- a/console/stand-alone/test/links.js +++ b/console/stand-alone/test/links.js @@ -44,8 +44,19 @@ var unknowns = []; const width = 1024; const height = 768; + before(function(done){ - fs.readFile('./test/nodes.json', 'utf8', function(err, fileContents) { + let src = ''; + let LAST_PARAM = process.argv[process.argv.length-1]; + + let PARAM_NAME = LAST_PARAM.split('=')[0].replace('--',''); + let PARAM_VALUE = LAST_PARAM.split('=')[1]; + if (PARAM_NAME == 'src') { + src = PARAM_VALUE; + } + + console.log('src: ', src); + fs.readFile(src + './test/nodes.json', 'utf8', function(err, fileContents) { if (err) throw err; nodeInfo = JSON.parse(fileContents); done(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 408c57440b..315693ee38 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -112,6 +112,7 @@ foreach(py_test_module system_tests_bad_configuration system_tests_ssl ${SYSTEM_TESTS_HTTP} + system_tests_console ) add_test(${py_test_module} ${TEST_WRAP} -x unit2 -v ${py_test_module}) diff --git a/tests/system_tests_console.py b/tests/system_tests_console.py new file mode 100644 index 0000000000..aba8578af3 --- /dev/null +++ b/tests/system_tests_console.py @@ -0,0 +1,84 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License +# + +from __future__ import unicode_literals +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + +import os +import re +import system_test +import unittest +from subprocess import PIPE +import subprocess +import shutil +from proton import Url, SSLDomain, SSLUnavailable, SASL +from system_test import main_module + +class ConsoleTest(system_test.TestCase): + """Run console tests""" + @classmethod + def setUpClass(cls): + super(ConsoleTest, cls).setUpClass() + config = system_test.Qdrouterd.Config([ + ('router', {'id': 'QDR.A', 'workerThreads': 1}), + ('listener', {'port': cls.tester.get_port()}), + ]) + cls.router = cls.tester.qdrouterd('test-router', config) + + def run_console_test(self): + cwd = os.getcwd() # expecting /build/system_test.dir/system_tests_console/ConsoleTest/test_console + base = cwd.split('/')[:-6] #path that ends with qpid-dispatch's home dir + test_cmd = '/'.join(base + ['build', 'console', 'node_modules', '.bin', 'mocha']) + test_dir = '/'.join(base + ['console', 'stand-alone', 'test']) + src_dir = '/'.join(base + ['console', 'stand-alone']) + + # The console test needs a node_modules dir in the source directory + # If the node_modules dir is not present in the source dir, create it. + # An alternative is to copy all the source files to the build/console dir. + node_dir = '/'.join(base + ['console', 'stand-alone', 'node_modules']) + node_modules = os.path.isdir(node_dir) + if not node_modules: + p0 = subprocess.Popen(['npm', 'install'], stdout=PIPE, cwd=src_dir) + p0.wait(); + + prg = [test_cmd,'--require', 'babel-core/register', test_dir, '--src=%s/' % src_dir] + p = self.popen(prg, stdout=PIPE, expect=None) + out = p.communicate()[0] + + # write the output + with open('run_console_test.out', 'w') as popenfile: + popenfile.write('returncode was %s\n' % p.returncode) + popenfile.write('out was:\n') + popenfile.writelines(out) + + # if we created the node_modules dir, remove it + if not node_modules: + shutil.rmtree(node_dir) + + assert p.returncode == 0, \ + "console test exit status %s, output:\n%s" % (p.returncode, out) + return out + + def test_console(self): + self.run_console_test() + +if __name__ == '__main__': + unittest.main(main_module()) From 0146a68f92ad5d64798298a5c123a19e01504e2e Mon Sep 17 00:00:00 2001 From: Ernest Allen Date: Wed, 27 Jun 2018 14:35:18 -0400 Subject: [PATCH 2/2] DISPATCH-1054 Suppress npm install warnings --- tests/system_tests_console.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system_tests_console.py b/tests/system_tests_console.py index aba8578af3..619c81fae8 100644 --- a/tests/system_tests_console.py +++ b/tests/system_tests_console.py @@ -56,7 +56,7 @@ def run_console_test(self): node_dir = '/'.join(base + ['console', 'stand-alone', 'node_modules']) node_modules = os.path.isdir(node_dir) if not node_modules: - p0 = subprocess.Popen(['npm', 'install'], stdout=PIPE, cwd=src_dir) + p0 = subprocess.Popen(['npm', 'install', '--loglevel=error'], stdout=PIPE, cwd=src_dir) p0.wait(); prg = [test_cmd,'--require', 'babel-core/register', test_dir, '--src=%s/' % src_dir]