Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: get rid of the test-run submodule #189

Merged
merged 4 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "test-run"]
path = test-run
url = https://github.com/tarantool/test-run
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ On Linux:
On Windows:

* Setup a Linux machine with installed tarantool (called ``remote`` later).
* (on ``remote``) Copy ``unit/suites/lib/tarantool_python_ci.lua`` to
* (on ``remote``) Copy ``test/suites/lib/tarantool_python_ci.lua`` to
``/etc/tarantool/instances.available``.
* (on ``remote``) Run ``tarantoolctl start tarantool_python_ci``.
* Set the following environment variables:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# Test runner
# python setup.py test
try:
from unit.setup_command import test
from test.setup_command import test
cmdclass["test"] = test
except ImportError:
pass
Expand Down
73 changes: 48 additions & 25 deletions tarantool/mesh_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@


def parse_uri(uri):
# TODO: Support Unix sockets.
def parse_error(uri, msg):
msg = 'URI "%s": %s' % (uri, msg)
return None, msg
Expand All @@ -59,31 +60,53 @@ def parse_error(uri, msg):


def validate_address(address):
messages = []

if isinstance(address, dict):
if "host" not in address:
messages.append("host key must be set")
elif not isinstance(address["host"], string_types):
messages.append("host value must be string type")

if "port" not in address:
messages.append("port is not set")
elif not isinstance(address["port"], int):
messages.append("port value must be int type")
elif address["port"] == 0:
messages.append("port value must not be zero")
elif address["port"] > 65535:
messages.append("port value must not be above 65535")
else:
messages.append("address must be a dict")

if messages:
messages_str = ', '.join(messages)
msg = 'Address %s: %s' % (str(address), messages_str)
return None, msg

return True, None
def format_error(address, err):
return None, 'Address %s: %s' % (str(address), err)

if not isinstance(address, dict):
return format_error(address, 'address must be a dict')

if 'port' not in address or address['port'] is None:
return format_error(address, 'port is not set or None')

if isinstance(address['port'], int):
# Looks like an inet address.

# Validate host.
if 'host' not in address or address['host'] is None:
return format_error(address,
'host is mandatory for an inet address')
if not isinstance(address['host'], string_types):
return format_error(address,
'host must be a string for an inet address')

# Validate port.
if not isinstance(address['port'], int):
return format_error(address,
'port must be an int for an inet address')
if address['port'] < 1 or address['port'] > 65535:
return format_error(address, 'port must be in range [1, 65535] '
'for an inet address')

# Looks okay.
return True, None
elif isinstance(address['port'], string_types):
# Looks like a unix address.

# Expect no host.
if 'host' in address and address['host'] is not None:
return format_error(
address, 'host must be unset or None for a unix address')

# Validate port.
if not isinstance(address['port'], string_types):
return format_error(address,
'port must be a string for a unix address')

# Looks okay.
return True, None

return format_error(address, 'port must be an int or a string')


class RoundRobinStrategy(object):
Expand Down
1 change: 0 additions & 1 deletion test-run
Submodule test-run deleted from 72f8b8
15 changes: 0 additions & 15 deletions test/.tarantoolctl

This file was deleted.

File renamed without changes.
16 changes: 0 additions & 16 deletions test/cluster-py/instance.lua

This file was deleted.

1 change: 0 additions & 1 deletion test/cluster-py/instance1.lua

This file was deleted.

1 change: 0 additions & 1 deletion test/cluster-py/instance2.lua

This file was deleted.

9 changes: 0 additions & 9 deletions test/cluster-py/master.lua

This file was deleted.

22 changes: 0 additions & 22 deletions test/cluster-py/multi.result

This file was deleted.

71 changes: 0 additions & 71 deletions test/cluster-py/multi.test.py

This file was deleted.

5 changes: 0 additions & 5 deletions test/cluster-py/suite.ini

This file was deleted.

4 changes: 2 additions & 2 deletions unit/setup_command.py → test/setup_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class test(setuptools.Command):
user_options = []
description = 'Run unit tests'
description = 'Run tests'

def initialize_options(self):
pass
Expand All @@ -23,7 +23,7 @@ def run(self):
Find all tests in test/tarantool/ and run them
'''

tests = unittest.defaultTestLoader.discover('unit', pattern='suites')
tests = unittest.defaultTestLoader.discover('test', pattern='suites')
test_runner = unittest.TextTestRunner(verbosity=2)
result = test_runner.run(tests)
if not result.wasSuccessful():
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def start(self):
self.wait_until_started()

def stop(self):
self.admin.disconnect()
if self.process.poll() is None:
self.process.terminate()
self.process.wait()
Expand Down
2 changes: 1 addition & 1 deletion unit/suites/test_dbapi.py → test/suites/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setUpClass(self):
print(' DBAPI '.center(70, '='), file=sys.stderr)
print('-' * 70, file=sys.stderr)
self.srv = TarantoolServer()
self.srv.script = 'unit/suites/box.lua'
self.srv.script = 'test/suites/box.lua'
self.srv.start()
self.con = tarantool.Connection(self.srv.host, self.srv.args['primary'])
self.driver = dbapi
Expand Down
2 changes: 1 addition & 1 deletion unit/suites/test_dml.py → test/suites/test_dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUpClass(self):
print(' DML '.center(70, '='), file=sys.stderr)
print('-' * 70, file=sys.stderr)
self.srv = TarantoolServer()
self.srv.script = 'unit/suites/box.lua'
self.srv.script = 'test/suites/box.lua'
self.srv.start()
self.con = tarantool.Connection(self.srv.host, self.srv.args['primary'])
self.adm = self.srv.admin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setUpClass(self):
print(' EXECUTE '.center(70, '='), file=sys.stderr)
print('-' * 70, file=sys.stderr)
self.srv = TarantoolServer()
self.srv.script = 'unit/suites/box.lua'
self.srv.script = 'test/suites/box.lua'
self.srv.start()
self.con = tarantool.Connection(self.srv.host, self.srv.args['primary'])

Expand Down
38 changes: 37 additions & 1 deletion unit/suites/test_mesh.py → test/suites/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
from time import sleep
import tarantool
from tarantool.error import (
NetworkError,
ConfigurationError,
NetworkWarning,
ClusterDiscoveryWarning,
)
from .lib.tarantool_server import TarantoolServer


def create_server(_id):
srv = TarantoolServer()
srv.script = 'unit/suites/box.lua'
srv.script = 'test/suites/box.lua'
srv.start()
srv.admin("box.schema.user.create('test', {password = 'test', " +
"if_not_exists = true})")
Expand Down Expand Up @@ -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).
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setUpClass(self):
print(' RECONNECT '.center(70, '='), file=sys.stderr)
print('-' * 70, file=sys.stderr)
self.srv = TarantoolServer()
self.srv.script = 'unit/suites/box.lua'
self.srv.script = 'test/suites/box.lua'

def setUp(self):
# prevent a remote tarantool from clean our session
Expand Down
2 changes: 1 addition & 1 deletion unit/suites/test_schema.py → test/suites/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setUpClass(self):
print(' SCHEMA ({}) '.format(params).center(70, '='), file=sys.stderr)
print('-' * 70, file=sys.stderr)
self.srv = TarantoolServer()
self.srv.script = 'unit/suites/box.lua'
self.srv.script = 'test/suites/box.lua'
self.srv.start()
self.con = tarantool.Connection(self.srv.host, self.srv.args['primary'],
encoding=self.encoding)
Expand Down
Loading