Skip to content

Commit adf7d87

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

File tree

9 files changed

+216
-0
lines changed

9 files changed

+216
-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

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