Skip to content

Commit 6d62982

Browse files
author
Konstantin Belyavskiy
committed
Add test-run and a test
1 parent b799675 commit 6d62982

File tree

9 files changed

+215
-0
lines changed

9 files changed

+215
-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/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

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
fiber = require('fiber')
2+
---
3+
...
4+
box.schema.user.grant('guest', 'replication')
5+
---
6+
...
7+
box.schema.user.grant('guest', 'execute', 'universe')
8+
---
9+
...
10+
----------------------------------------------------------------------
11+
Bootstrap replicas
12+
----------------------------------------------------------------------
13+
done
14+
----------------------------------------------------------------------
15+
Make a full mesh
16+
----------------------------------------------------------------------
17+
server 1 connected
18+
server 1 connected
19+
server 1 connected
20+
box.info.vclock
21+
---
22+
- {1: 4}
23+
...
24+
server 2 connected
25+
server 2 connected
26+
server 2 connected
27+
box.info.vclock
28+
---
29+
- {1: 4}
30+
...
31+
server 3 connected
32+
server 3 connected
33+
server 3 connected
34+
box.info.vclock
35+
---
36+
- {1: 4}
37+
...
38+
done
39+
----------------------------------------------------------------------
40+
Check mesh connection
41+
----------------------------------------------------------------------
42+
43+
----------------------------------------------------------------------
44+
Cleanup
45+
----------------------------------------------------------------------
46+
ping Ok
47+
server 1 done
48+
server 2 done
49+
server 3 done
50+
51+
NetworkError !

test/cluster-py/multi.test.py

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import sys
2+
import os
3+
from threading import Thread
4+
import time
5+
import yaml
6+
from lib.tarantool_server import TarantoolServer
7+
from ....tarantool 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+
REPLICA_N = 3
16+
ROW_N = REPLICA_N * 20
17+
18+
19+
def check_cluster(addrs):
20+
con = MeshConnection(addrs=addrs,
21+
user=None,
22+
password=None,
23+
socket_timeout=SOCKET_TIMEOUT,
24+
reconnect_max_attempts=1,
25+
reconnect_delay=RECONNECT_DELAY,
26+
connect_now=True,
27+
encoding=ENCODING_DEFAULT)
28+
while True:
29+
try:
30+
x = con.ping()
31+
print 'ping Ok'
32+
except NetworkError:
33+
print 'NetworkError !'
34+
break
35+
except Exception as e:
36+
print e
37+
time.sleep(1)
38+
39+
##
40+
41+
# master server
42+
master = server
43+
master.admin("fiber = require('fiber')")
44+
master.admin("box.schema.user.grant('guest', 'replication')")
45+
master.admin("box.schema.user.grant('guest', 'execute', 'universe')")
46+
47+
print '----------------------------------------------------------------------'
48+
print 'Bootstrap replicas'
49+
print '----------------------------------------------------------------------'
50+
51+
# Start replicas
52+
master.id = master.get_param('id')
53+
cluster = [master]
54+
for i in range(REPLICA_N - 1):
55+
server = TarantoolServer(server.ini)
56+
server.script = 'cluster-py/replica.lua'
57+
server.vardir = os.path.join(server.vardir, 'replica', str(master.id + i))
58+
server.rpl_master = master
59+
server.deploy()
60+
# Wait replica to fully bootstrap.
61+
# Otherwise can get ACCESS_DENIED error.
62+
cluster.append(server)
63+
64+
# Make a list of servers
65+
sources = []
66+
for server in cluster:
67+
sources.append(yaml.load(server.admin('box.cfg.listen', silent=True))[0])
68+
server.id = server.get_param('id')
69+
70+
print 'done'
71+
72+
print '----------------------------------------------------------------------'
73+
print 'Make a full mesh'
74+
print '----------------------------------------------------------------------'
75+
76+
addrs = []
77+
for addr in sources[1:]:
78+
arr = addr.split(':')
79+
addrs.append({'host': arr[0], 'port': int(arr[1])})
80+
81+
# Connect each server to each other to make full mesh
82+
for server in cluster:
83+
server.iproto.py_con.eval("box.cfg { replication = ... }", [sources])
84+
85+
# Wait connections to establish
86+
for server in cluster:
87+
for server2 in cluster:
88+
server.iproto.py_con.eval("""
89+
while #box.info.vclock[...] ~= nil do
90+
fiber.sleep(0.01)
91+
end;""", server2.id)
92+
print 'server', server.id, "connected"
93+
server.admin("box.info.vclock")
94+
95+
print 'done'
96+
97+
print '----------------------------------------------------------------------'
98+
print 'Check mesh connection'
99+
print '----------------------------------------------------------------------'
100+
101+
thread = Thread(target=check_cluster, args=(addrs, ))
102+
thread.start()
103+
104+
print
105+
print '----------------------------------------------------------------------'
106+
print 'Cleanup'
107+
print '----------------------------------------------------------------------'
108+
109+
for server in cluster:
110+
server.stop()
111+
print 'server', server.id, 'done'
112+
print
113+
114+
thread.join()
115+
116+
master.cleanup()
117+
master.deploy()

test/cluster-py/replica.lua

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

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 = tarantool/box, replication
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)