Skip to content

Commit 46beffb

Browse files
author
Konstantin Belyavskiy
committed
Add test-run and a test
1 parent fd992b0 commit 46beffb

10 files changed

+214
-23
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

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

testclient.py

-23
This file was deleted.

0 commit comments

Comments
 (0)