Skip to content

Commit efcef76

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

File tree

9 files changed

+140
-0
lines changed

9 files changed

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

+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+
22+
NetworkError !

test/cluster-py/multi.test.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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('../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 = 2
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+
s = con.space('test')
31+
print s.select()
32+
except NetworkError:
33+
print 'NetworkError !'
34+
break
35+
except Exception as e:
36+
print e
37+
time.sleep(1)
38+
39+
40+
# Start replicas
41+
master = server
42+
cluster = [master]
43+
for i in range(REPLICA_N):
44+
server = TarantoolServer(server.ini)
45+
server.script = 'cluster-py/replica.lua'
46+
server.vardir = os.path.join(server.vardir, 'replica', str(i))
47+
server.deploy()
48+
server.admin("box.schema.user.grant('guest', 'read,write,execute', 'universe')")
49+
server.admin("_ = box.schema.space.create('test')")
50+
server.admin("_ = box.space.test:create_index('primary')")
51+
server.admin("box.space.test:insert{%d, %s}" % (1, i), silent = True)
52+
cluster.append(server)
53+
54+
# Make a list of servers
55+
sources = []
56+
for server in cluster[1:]:
57+
sources.append(yaml.load(server.admin('box.cfg.listen', silent=True))[0])
58+
59+
addrs = []
60+
for addr in sources:
61+
host, port = addr.split(':')
62+
addrs.append({'host': host, 'port': int(port)})
63+
64+
thread = Thread(target=check_cluster, args=(addrs, ))
65+
thread.start()
66+
67+
cluster[0].stop()
68+
time.sleep(0.5)
69+
for server in cluster[1:]:
70+
server.stop()
71+
time.sleep(1)
72+
print
73+
74+
thread.join()
75+
76+
master.cleanup()
77+
master.deploy()

test/cluster-py/replica.lua

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

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)