From 95c43d431b2f2944516806a56798835aab64c94a Mon Sep 17 00:00:00 2001 From: Alexander Turenko Date: Tue, 16 Feb 2021 23:49:09 +0300 Subject: [PATCH] test: move basic mesh test under './setup.py test' In short: this commit moves the basic MeshConnection test cases to the `./setup.py test` test suites (which are located in the unit/ now) and removes the test-run submodule, which is not needed anymore. A bit background: we have a testing framework called test-run, whose primary goal is to give ability to manage tarantool instances from a test. Historically tarantool-python does not use test-run for testing (it uses several simple python helpers instead), but a test-run based test was added in the scope of #106. The idea was to reuse test-run code more and eventually port other tests to test-run. The objective reality reveals several problems in the idea, which looked nice in theory. The main problem is the cyclic dependency between test-run and tarantool-python submodules. It consumes an extra time at recursive git clone and places old submodule revisions in a deeply nested level. The latter may confuse linter tools, which search for files recursively (see [1]). Other problems look solvable, but I'll list them, because they give considerable weight in my impression that we should get rid of the test-run submodule within this repository: 1. test-run based tests were not run in CI and may break silently so (it already occurs once). 2. The first bullet looks easy to fix, but it is unclear whether it is right to depend on a submodule in the `./setup.py test` testing or we should keep only built-in and packaged testing tools in the dependencies. 3. Porting tests to test-run may require extra effort and nobody was eager to pay time for that. 4. Existing tooling for managing tarantool instances is enough for testing of the connector and, at the same time, it is quite simple. So if we'll meet a problem, it is easier to fix. 5. test-run supports only Python 2 at the moment (however it'll be fixed soon, see [2]). To sum up, the experiment with the test-run submodule looks unsuccessful and I think we should stop it for now. If we'll decide to try again, we should consider all described problems and implement everything in a way that does not hurt us. [1]: https://github.com/tarantool/test-run/pull/266#issuecomment-779891165 [2]: https://github.com/tarantool/test-run/issues/20 Fixes #111 --- .gitmodules | 3 -- Makefile | 1 - test-run | 1 - test/.tarantoolctl | 15 -------- test/cluster-py/instance.lua | 16 -------- test/cluster-py/instance1.lua | 1 - test/cluster-py/instance2.lua | 1 - test/cluster-py/master.lua | 9 ----- test/cluster-py/multi.result | 22 ----------- test/cluster-py/multi.test.py | 71 ----------------------------------- test/cluster-py/suite.ini | 5 --- test/test-run.py | 1 - unit/suites/test_mesh.py | 36 ++++++++++++++++++ 13 files changed, 36 insertions(+), 146 deletions(-) delete mode 160000 test-run delete mode 100644 test/.tarantoolctl delete mode 100644 test/cluster-py/instance.lua delete mode 120000 test/cluster-py/instance1.lua delete mode 120000 test/cluster-py/instance2.lua delete mode 100644 test/cluster-py/master.lua delete mode 100644 test/cluster-py/multi.result delete mode 100644 test/cluster-py/multi.test.py delete mode 100644 test/cluster-py/suite.ini delete mode 120000 test/test-run.py diff --git a/.gitmodules b/.gitmodules index 63e76fe2..e69de29b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "test-run"] - path = test-run - url = https://github.com/tarantool/test-run diff --git a/Makefile b/Makefile index 4705feaa..c9dd894c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ .PHONY: test test: python setup.py test - cd test && ./test-run.py coverage: python -m coverage run -p --source=. setup.py test cov-html: diff --git a/test-run b/test-run deleted file mode 160000 index 72f8b893..00000000 --- a/test-run +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 72f8b89332b552cf20b2143e6dae7fe5042a9f79 diff --git a/test/.tarantoolctl b/test/.tarantoolctl deleted file mode 100644 index 5c46f8ac..00000000 --- a/test/.tarantoolctl +++ /dev/null @@ -1,15 +0,0 @@ --- Options for test-run tarantoolctl - -local workdir = os.getenv('TEST_WORKDIR') -default_cfg = { - pid_file = workdir, - wal_dir = workdir, - memtx_dir = workdir, - vinyl_dir = workdir, - log = workdir, - background = false, -} - -instance_dir = workdir - --- vim: set ft=lua : diff --git a/test/cluster-py/instance.lua b/test/cluster-py/instance.lua deleted file mode 100644 index 2fcba42e..00000000 --- a/test/cluster-py/instance.lua +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env tarantool - -local INSTANCE_ID = string.match(arg[0], "%d") -local SOCKET_DIR = require('fio').cwd() - -local function instance_uri(instance_id) - return SOCKET_DIR..'/instance'..instance_id..'.sock'; -end - -require('console').listen(os.getenv('ADMIN')) - -box.cfg({ - --listen = os.getenv("LISTEN"), - listen = instance_uri(INSTANCE_ID), - memtx_memory = 107374182, -}) diff --git a/test/cluster-py/instance1.lua b/test/cluster-py/instance1.lua deleted file mode 120000 index 2087830f..00000000 --- a/test/cluster-py/instance1.lua +++ /dev/null @@ -1 +0,0 @@ -instance.lua \ No newline at end of file diff --git a/test/cluster-py/instance2.lua b/test/cluster-py/instance2.lua deleted file mode 120000 index 2087830f..00000000 --- a/test/cluster-py/instance2.lua +++ /dev/null @@ -1 +0,0 @@ -instance.lua \ No newline at end of file diff --git a/test/cluster-py/master.lua b/test/cluster-py/master.lua deleted file mode 100644 index b43bafd5..00000000 --- a/test/cluster-py/master.lua +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env tarantool -local os = require('os') -box.cfg({ - listen = os.getenv("LISTEN"), - memtx_memory = 107374182, - replication_timeout = 0.1 -}) - -require('console').listen(os.getenv('ADMIN')) diff --git a/test/cluster-py/multi.result b/test/cluster-py/multi.result deleted file mode 100644 index 5e3a8573..00000000 --- a/test/cluster-py/multi.result +++ /dev/null @@ -1,22 +0,0 @@ -box.schema.user.grant('guest', 'read,write,execute', 'universe') ---- -... -_ = box.schema.space.create('test') ---- -... -_ = box.space.test:create_index('primary') ---- -... -box.schema.user.grant('guest', 'read,write,execute', 'universe') ---- -... -_ = box.schema.space.create('test') ---- -... -_ = box.space.test:create_index('primary') ---- -... -- [1, 0] -- [1, 1] -- [1, 0] -NetworkError ! diff --git a/test/cluster-py/multi.test.py b/test/cluster-py/multi.test.py deleted file mode 100644 index 0db520b0..00000000 --- a/test/cluster-py/multi.test.py +++ /dev/null @@ -1,71 +0,0 @@ -import sys -import os -import time -import yaml -from lib.tarantool_server import TarantoolServer -sys.path.append('../tarantool') -from mesh_connection import MeshConnection -from tarantool.const import ( - SOCKET_TIMEOUT, - RECONNECT_DELAY, -) -from tarantool.error import NetworkError -from tarantool.utils import ENCODING_DEFAULT - -INSTANCE_N = 2 - - -def check_connection(con): - try: - s = con.space('test') - print(s.select()) - except NetworkError: - print('NetworkError !') - except Exception as e: - print(e) - - -# Start instances -master = server -cluster = [master] -for i in range(INSTANCE_N): - server = TarantoolServer(server.ini) - server.script = 'cluster-py/instance%d.lua' % (i+1) - server.vardir = os.path.join(server.vardir, 'instance', str(i)) - server.deploy() - server.admin("box.schema.user.grant('guest', 'read,write,execute', 'universe')") - server.admin("_ = box.schema.space.create('test')") - server.admin("_ = box.space.test:create_index('primary')") - server.admin("box.space.test:insert{%d, %s}" % (1, i), silent = True) - cluster.append(server) - -# Make a list of servers -sources = [] -for server in cluster[1:]: - sources.append(yaml.safe_load(server.admin('box.cfg.listen', silent=True))[0]) - -addrs = [] -for addr in sources: - addrs.append({'host': None, 'port': addr}) - -con = MeshConnection(addrs=addrs, - user=None, - password=None, - socket_timeout=SOCKET_TIMEOUT, - reconnect_max_attempts=0, - reconnect_delay=RECONNECT_DELAY, - connect_now=True, - encoding=ENCODING_DEFAULT) - -cluster[0].stop() # stop server - no effect -check_connection(con) # instance#1 -cluster[1].stop() # stop instance#1 -check_connection(con) # instance#2 -cluster[1].start() # start instance#1 -cluster[2].stop() # stop instance#2 -check_connection(con) # instance#1 again -cluster[1].stop() # stop instance#1 -check_connection(con) # both stopped: NetworkError ! - -master.cleanup() -master.deploy() diff --git a/test/cluster-py/suite.ini b/test/cluster-py/suite.ini deleted file mode 100644 index a2fea18b..00000000 --- a/test/cluster-py/suite.ini +++ /dev/null @@ -1,5 +0,0 @@ -[default] -core = tarantool -script = master.lua -description = reconnect -is_parallel = False diff --git a/test/test-run.py b/test/test-run.py deleted file mode 120000 index 21bb780a..00000000 --- a/test/test-run.py +++ /dev/null @@ -1 +0,0 @@ -../test-run/test-run.py \ No newline at end of file diff --git a/unit/suites/test_mesh.py b/unit/suites/test_mesh.py index dda59a89..cb613674 100644 --- a/unit/suites/test_mesh.py +++ b/unit/suites/test_mesh.py @@ -8,7 +8,9 @@ from time import sleep import tarantool from tarantool.error import ( + NetworkError, ConfigurationError, + NetworkWarning, ClusterDiscoveryWarning, ) from .lib.tarantool_server import TarantoolServer @@ -70,6 +72,40 @@ def setUp(self): self.define_cluster_function(self.get_all_nodes_func_name, self.servers) + def test_00_basic(self): + def assert_srv_id(con, srv_id): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', category=NetworkWarning) + resp = con.call('srv_id') + self.assertEqual(resp.data and resp.data[0], srv_id) + + con = tarantool.MeshConnection(addrs=[ + {'host': self.host_1, 'port': self.port_1}, + {'host': self.host_2, 'port': self.port_2}, + ], user='test', password='test') + + # Response from instance#1. + assert_srv_id(con, 1) + + # Stop instance#1 -- response from instance#2. + self.srv.stop() + assert_srv_id(con, 2) + + # Start instance#1, stop instance#2 -- response from + # instance#1 again. + self.srv.start() + self.srv.admin('function srv_id() return 1 end') + self.srv2.stop() + assert_srv_id(con, 1) + + # Stop instance #2 -- NetworkError (because we have no + # alive servers anymore). + self.srv.stop() + with self.assertRaises(NetworkError): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', category=NetworkWarning) + con.ping() + def test_01_contructor(self): # Verify that an error is risen when no addresses are # configured (neither with host/port, nor with addrs).