Skip to content

test: wait until admin connection is ready #306

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

Merged
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
8 changes: 4 additions & 4 deletions .github/workflows/packing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ jobs:
- name: Setup WSL for tarantool
uses: Vampire/setup-wsl@v1
with:
distribution: Ubuntu-20.04
distribution: Ubuntu-22.04

- name: Install tarantool
shell: wsl-bash_Ubuntu-20.04 {0}
shell: wsl-bash_Ubuntu-22.04 {0}
run: |
curl -L https://tarantool.io/release/2/installer.sh | bash -s
sudo apt install -y tarantool tarantool-dev

- name: Setup test tarantool instance
shell: wsl-bash_Ubuntu-20.04 {0}
shell: wsl-bash_Ubuntu-22.04 {0}
run: |
rm -f ./tarantool.pid ./tarantool.log
TNT_PID=$(tarantool ./test/suites/lib/tarantool_python_ci.lua > tarantool.log 2>&1 & echo $!)
Expand All @@ -172,7 +172,7 @@ jobs:

- name: Stop test tarantool instance
if: ${{ always() }}
shell: wsl-bash_Ubuntu-20.04 {0}
shell: wsl-bash_Ubuntu-22.04 {0}
run: |
cat tarantool.log || true
kill $(cat tarantool.pid) || true
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,16 @@ jobs:
- name: Setup WSL for tarantool
uses: Vampire/setup-wsl@v2
with:
distribution: Ubuntu-20.04
distribution: Ubuntu-22.04

- name: Install tarantool ${{ matrix.tarantool }} for WSL (2.10 and newer)
shell: wsl-bash_Ubuntu-20.04 {0}
shell: wsl-bash_Ubuntu-22.04 {0}
run: |
curl -L https://tarantool.io/release/2/installer.sh | bash -s
sudo apt install -y tarantool=${{ matrix.tarantool }} tarantool-dev=${{ matrix.tarantool }}

- name: Setup test tarantool instance
shell: wsl-bash_Ubuntu-20.04 {0}
shell: wsl-bash_Ubuntu-22.04 {0}
run: |
rm -f ./tarantool.pid ./tarantool.log
TNT_PID=$(tarantool ./test/suites/lib/tarantool_python_ci.lua > tarantool.log 2>&1 & echo $!)
Expand All @@ -286,7 +286,7 @@ jobs:

- name: Stop test tarantool instance
if: ${{ always() }}
shell: wsl-bash_Ubuntu-20.04 {0}
shell: wsl-bash_Ubuntu-22.04 {0}
run: |
cat tarantool.log || true
kill $(cat tarantool.pid) || true
Expand Down Expand Up @@ -334,16 +334,16 @@ jobs:
- name: Setup WSL for tarantool
uses: Vampire/setup-wsl@v2
with:
distribution: Ubuntu-20.04
distribution: Ubuntu-22.04

- name: Install tarantool ${{ matrix.tarantool }} for WSL
shell: wsl-bash_Ubuntu-20.04 {0}
shell: wsl-bash_Ubuntu-22.04 {0}
run: |
curl -L https://tarantool.io/release/2/installer.sh | bash -s
sudo apt install -y tarantool=${{ matrix.tarantool }} tarantool-dev=${{ matrix.tarantool }}

- name: Setup test tarantool instance
shell: wsl-bash_Ubuntu-20.04 {0}
shell: wsl-bash_Ubuntu-22.04 {0}
run: |
rm -f ./tarantool.pid ./tarantool.log
TNT_PID=$(tarantool ./test/suites/lib/tarantool_python_ci.lua > tarantool.log 2>&1 & echo $!)
Expand All @@ -358,7 +358,7 @@ jobs:

- name: Stop test tarantool instance
if: ${{ always() }}
shell: wsl-bash_Ubuntu-20.04 {0}
shell: wsl-bash_Ubuntu-22.04 {0}
run: |
cat tarantool.log || true
kill $(cat tarantool.pid) || true
2 changes: 2 additions & 0 deletions test/suites/box.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ box.cfg{
pid_file = "box.pid",
auth_type = (auth_type:len() > 0) and auth_type or nil,
}

rawset(_G, 'ready', true)
2 changes: 2 additions & 0 deletions test/suites/crud_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ if crud_imported == false or vshard_imported == false then
else
configure_crud_instance(primary_listen, crud, vshard)
end

rawset(_G, 'ready', true)
21 changes: 8 additions & 13 deletions test/suites/lib/tarantool_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,27 +302,22 @@ def prepare_args(self):

return shlex.split(self.binary if not self.script else self.script_dst)

def wait_until_started(self):
def wait_until_ready(self):
"""
Wait until server is started.
Wait until server is configured and ready to work.

Server consists of two parts:
1) wait until server is listening on sockets
2) wait until server tells us his status
2) wait until server finishes executing its script
"""

while True:
try:
temp = TarantoolAdmin('0.0.0.0', self.args['admin'])
while True:
ans = temp('box.info.status')[0]
if ans in ('running', 'hot_standby', 'orphan') or ans.startswith('replica'):
temp.disconnect()
return True
if ans in ('loading',):
continue

raise ValueError(f"Strange output for `box.info.status`: {ans}")
ans = temp('ready')[0]
temp.disconnect()
if isinstance(ans, bool) and ans:
return True
except socket.error as exc:
if exc.errno == errno.ECONNREFUSED:
time.sleep(0.1)
Expand Down Expand Up @@ -352,7 +347,7 @@ def start(self):
cwd=self.vardir,
stdout=self.log_des,
stderr=self.log_des)
self.wait_until_started()
self.wait_until_ready()

def stop(self):
"""
Expand Down
71 changes: 43 additions & 28 deletions test/suites/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@

import sys
import unittest

import decimal

import pkg_resources
import msgpack

import tarantool
import tarantool.msgpack_ext.decimal as ext_decimal

from .lib.skip import skip_or_run_decimal_test, skip_or_run_varbinary_test
from .lib.tarantool_server import TarantoolServer
from .utils import assert_admin_success


class TestSuiteConnection(unittest.TestCase):
Expand All @@ -26,35 +28,48 @@ def setUpClass(cls):
cls.srv.start()

cls.adm = cls.srv.admin
cls.adm(r"""
resp = cls.adm("""
box.schema.user.create('test', {password = 'test', if_not_exists = true})
box.schema.user.grant('test', 'read,write,execute', 'universe')

box.schema.create_space('space_varbin')

box.space['space_varbin']:format({
{
'id',
type = 'number',
is_nullable = false
},
{
'varbin',
type = 'varbinary',
is_nullable = false,
}
})

box.space['space_varbin']:create_index('id', {
type = 'tree',
parts = {1, 'number'},
unique = true})

box.space['space_varbin']:create_index('varbin', {
type = 'tree',
parts = {2, 'varbinary'},
unique = true})
box.schema.user.grant('test', 'read,write,execute', 'universe',
nil, {if_not_exists = true})

return true
""")
assert_admin_success(resp)

if cls.srv.admin.tnt_version >= pkg_resources.parse_version('2.2.1'):
resp = cls.adm("""
box.schema.create_space('space_varbin', {if_not_exists = true})

box.space['space_varbin']:format({
{
'id',
type = 'number',
is_nullable = false
},
{
'varbin',
type = 'varbinary',
is_nullable = false,
}
})

box.space['space_varbin']:create_index('id', {
type = 'tree',
parts = {1, 'number'},
unique = true,
if_not_exists = true})

box.space['space_varbin']:create_index('varbin', {
type = 'tree',
parts = {2, 'varbinary'},
unique = true,
if_not_exists = true})

return true
""")
assert_admin_success(resp)

cls.con = None

def setUp(self):
Expand Down
23 changes: 17 additions & 6 deletions test/suites/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from .lib.tarantool_server import TarantoolServer
from .lib.skip import skip_or_run_datetime_test, skip_or_run_datetime_2_11_test
from .utils import assert_admin_success


class TestSuiteDatetime(unittest.TestCase):
Expand All @@ -28,25 +29,28 @@ def setUpClass(cls):
cls.srv.start()

cls.adm = cls.srv.admin
cls.adm(r"""
resp = cls.adm("""
_, datetime = pcall(require, 'datetime')

box.schema.space.create('test')
box.schema.space.create('test', {if_not_exists = true})
box.space['test']:create_index('primary', {
type = 'tree',
parts = {1, 'string'},
unique = true})
unique = true,
if_not_exists = true})

pcall(function()
box.schema.space.create('test_pk')
box.space['test_pk']:create_index('primary', {
type = 'tree',
parts = {1, 'datetime'},
unique = true})
unique = true,
if_not_exists = true})
end)

box.schema.user.create('test', {password = 'test', if_not_exists = true})
box.schema.user.grant('test', 'read,write,execute', 'universe')
box.schema.user.grant('test', 'read,write,execute', 'universe',
nil, {if_not_exists = true})

local function add(arg1, arg2)
return arg1 + arg2
Expand All @@ -57,7 +61,10 @@ def setUpClass(cls):
return arg1 - arg2
end
rawset(_G, 'sub', sub)

return true
""")
assert_admin_success(resp)

cls.con = tarantool.Connection(cls.srv.host, cls.srv.args['primary'],
user='test', password='test')
Expand All @@ -67,7 +74,11 @@ def setUp(self):
if self.srv.is_started():
self.srv.touch_lock()

self.adm("box.space['test']:truncate()")
resp = self.adm("""
box.space['test']:truncate()
return true
""")
assert_admin_success(resp)

def test_datetime_class_api(self):
datetime = tarantool.Datetime(year=2022, month=8, day=31, hour=18, minute=7, sec=54,
Expand Down
13 changes: 9 additions & 4 deletions test/suites/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from tarantool import dbapi
from .lib.tarantool_server import TarantoolServer
from .lib.skip import skip_or_run_sql_test
from .utils import assert_admin_success


class TestSuiteDBAPI(dbapi20.DatabaseAPI20Test):
Expand Down Expand Up @@ -39,17 +40,21 @@ def setUpClass(cls):
"port": cls.srv.args['primary']
}

# grant full access to guest
resp = cls.srv.admin("""
box.schema.user.grant('guest', 'create,read,write,execute', 'universe',
nil, {if_not_exists = true})
return true
""")
assert_admin_success(resp)

@skip_or_run_sql_test
def setUp(self):
# prevent a remote tarantool from clean our session
if self.srv.is_started():
self.srv.touch_lock()
self.con.flush_schema()

# grant full access to guest
self.srv.admin("box.schema.user.grant('guest', 'create,read,write,"
"execute', 'universe')")

@classmethod
def tearDownClass(cls):
cls.con.close()
Expand Down
29 changes: 20 additions & 9 deletions test/suites/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from .lib.tarantool_server import TarantoolServer
from .lib.skip import skip_or_run_decimal_test
from .utils import assert_admin_success


class TestSuiteDecimal(unittest.TestCase):
Expand All @@ -28,26 +29,32 @@ def setUpClass(cls):
cls.srv.start()

cls.adm = cls.srv.admin
cls.adm(r"""
_, decimal = pcall(require, 'decimal')
resp = cls.adm("""
decimal_supported, decimal = pcall(require, 'decimal')

box.schema.space.create('test')
box.schema.space.create('test', {if_not_exists = true})
box.space['test']:create_index('primary', {
type = 'tree',
parts = {1, 'string'},
unique = true})
unique = true,
if_not_exists = true})

pcall(function()
if decimal_supported then
box.schema.space.create('test_pk')
box.space['test_pk']:create_index('primary', {
type = 'tree',
parts = {1, 'decimal'},
unique = true})
end)
unique = true,
if_not_exists = true})
end

box.schema.user.create('test', {password = 'test', if_not_exists = true})
box.schema.user.grant('test', 'read,write,execute', 'universe')
box.schema.user.grant('test', 'read,write,execute', 'universe',
nil, {if_not_exists = true})

return true
""")
assert_admin_success(resp)

cls.con = tarantool.Connection(cls.srv.host, cls.srv.args['primary'],
user='test', password='test')
Expand All @@ -57,7 +64,11 @@ def setUp(self):
if self.srv.is_started():
self.srv.touch_lock()

self.adm("box.space['test']:truncate()")
resp = self.adm("""
box.space['test']:truncate()
return true
""")
assert_admin_success(resp)

valid_cases = {
'simple_decimal_1': {
Expand Down
Loading