Skip to content

Commit ea9d082

Browse files
author
Konstantin Belyavskiy
committed
Add test-run and a test
1 parent 495dec1 commit ea9d082

11 files changed

+145
-0
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "test-run"]
2+
path = test-run
3+
url = https://github.com/tarantool/test-run

test-run

Submodule test-run added at b85d7ed

test/.tarantoolctl

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Options for test-run tarantoolctl
2+
3+
local workdir = os.getenv('TEST_WORKDIR')
4+
default_cfg = {
5+
pid_file = workdir,
6+
wal_dir = workdir,
7+
memtx_dir = workdir,
8+
vinyl_dir = workdir,
9+
log = workdir,
10+
background = false,
11+
}
12+
13+
instance_dir = workdir
14+
15+
-- vim: set ft=lua :

test/cluster-py/instance.lua

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env tarantool
2+
3+
local INSTANCE_ID = string.match(arg[0], "%d")
4+
local SOCKET_DIR = require('fio').cwd()
5+
6+
local function instance_uri(instance_id)
7+
return SOCKET_DIR..'/instance'..instance_id..'.sock';
8+
end
9+
10+
require('console').listen(os.getenv('ADMIN'))
11+
12+
box.cfg({
13+
--listen = os.getenv("LISTEN"),
14+
listen = instance_uri(INSTANCE_ID),
15+
memtx_memory = 107374182,
16+
})

test/cluster-py/instance1.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance.lua

test/cluster-py/instance2.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance.lua

test/cluster-py/master.lua

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env tarantool
2+
os = require('os')
3+
box.cfg({
4+
listen = os.getenv("LISTEN"),
5+
memtx_memory = 107374182,
6+
replication_timeout = 0.1
7+
})
8+
9+
require('console').listen(os.getenv('ADMIN'))

test/cluster-py/multi.result

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
box.schema.user.grant('guest', 'read,write,execute', 'universe')
2+
---
3+
...
4+
_ = box.schema.space.create('test')
5+
---
6+
...
7+
_ = box.space.test:create_index('primary')
8+
---
9+
...
10+
box.schema.user.grant('guest', 'read,write,execute', 'universe')
11+
---
12+
...
13+
_ = box.schema.space.create('test')
14+
---
15+
...
16+
_ = box.space.test:create_index('primary')
17+
---
18+
...
19+
- [1, 0]
20+
- [1, 1]
21+
- [1, 0]
22+
NetworkError !

test/cluster-py/multi.test.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import sys
2+
import os
3+
import time
4+
import yaml
5+
from lib.tarantool_server import TarantoolServer
6+
sys.path.append('../tarantool')
7+
from mesh_connection import MeshConnection
8+
from tarantool.const import (
9+
SOCKET_TIMEOUT,
10+
RECONNECT_DELAY,
11+
)
12+
from tarantool.error import NetworkError
13+
from tarantool.utils import ENCODING_DEFAULT
14+
15+
INSTANCE_N = 2
16+
17+
18+
def check_connection(con):
19+
try:
20+
s = con.space('test')
21+
print s.select()
22+
except NetworkError:
23+
print 'NetworkError !'
24+
except Exception as e:
25+
print e
26+
27+
28+
# Start instances
29+
master = server
30+
cluster = [master]
31+
for i in range(INSTANCE_N):
32+
server = TarantoolServer(server.ini)
33+
server.script = 'cluster-py/instance%d.lua' % (i+1)
34+
server.vardir = os.path.join(server.vardir, 'instance', str(i))
35+
server.deploy()
36+
server.admin("box.schema.user.grant('guest', 'read,write,execute', 'universe')")
37+
server.admin("_ = box.schema.space.create('test')")
38+
server.admin("_ = box.space.test:create_index('primary')")
39+
server.admin("box.space.test:insert{%d, %s}" % (1, i), silent = True)
40+
cluster.append(server)
41+
42+
# Make a list of servers
43+
sources = []
44+
for server in cluster[1:]:
45+
sources.append(yaml.load(server.admin('box.cfg.listen', silent=True))[0])
46+
47+
addrs = []
48+
for addr in sources:
49+
addrs.append({'host': None, 'port': addr})
50+
51+
con = MeshConnection(addrs=addrs,
52+
user=None,
53+
password=None,
54+
socket_timeout=SOCKET_TIMEOUT,
55+
reconnect_max_attempts=0,
56+
reconnect_delay=RECONNECT_DELAY,
57+
connect_now=True,
58+
encoding=ENCODING_DEFAULT)
59+
60+
cluster[0].stop() # stop server - no effect
61+
check_connection(con) # instance#1
62+
cluster[1].stop() # stop instance#1
63+
check_connection(con) # instance#2
64+
cluster[1].start() # start instance#1
65+
cluster[2].stop() # stop instance#2
66+
check_connection(con) # instance#1 again
67+
cluster[1].stop() # stop instance#1
68+
check_connection(con) # both stopped: NetworkError !
69+
70+
master.cleanup()
71+
master.deploy()

test/cluster-py/suite.ini

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[default]
2+
core = tarantool
3+
script = master.lua
4+
description = reconnect
5+
is_parallel = False

test/test-run.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../test-run/test-run.py

0 commit comments

Comments
 (0)