Skip to content

Commit cfbccf2

Browse files
committed
test: add test cases for reconnections
Fixes #125.
1 parent 9352e7e commit cfbccf2

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

unit/suites/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
from .test_schema import TestSuite_Schema
88
from .test_dml import TestSuite_Request
99
from .test_protocol import TestSuite_Protocol
10+
from .test_reconnect import TestSuite_Reconnect
1011

11-
test_cases = (TestSuite_Schema, TestSuite_Request, TestSuite_Protocol)
12+
test_cases = (TestSuite_Schema, TestSuite_Request, TestSuite_Protocol,
13+
TestSuite_Reconnect)
1214

1315
def load_tests(loader, tests, pattern):
1416
suite = unittest.TestSuite()

unit/suites/test_reconnect.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
import warnings
5+
import tarantool
6+
from .lib.tarantool_server import TarantoolServer
7+
8+
9+
class TestSuite_Reconnect(unittest.TestCase):
10+
@classmethod
11+
def setUpClass(self):
12+
print(' RECONNECT '.center(70, '='))
13+
print('-' * 70)
14+
self.srv = TarantoolServer()
15+
self.srv.script = 'unit/suites/box.lua'
16+
17+
def test_01_simple(self):
18+
# Create a connection, but don't connect it.
19+
con = tarantool.Connection('localhost', self.srv.args['primary'],
20+
connect_now=False)
21+
22+
# Trigger a reconnection due to server unavailability.
23+
with warnings.catch_warnings():
24+
warnings.simplefilter("ignore")
25+
with self.assertRaises(tarantool.error.NetworkError):
26+
con.ping()
27+
28+
# Start a server and verify that the reconnection
29+
# succeeds.
30+
self.srv.start()
31+
self.assertIs(con.ping(notime=True), "Success")
32+
33+
# Close the connection and stop the server.
34+
con.close()
35+
self.srv.stop()
36+
37+
def test_02_wrong_auth(self):
38+
# Create a connection with wrong credentials, but don't
39+
# connect it.
40+
con = tarantool.Connection('localhost', self.srv.args['primary'],
41+
connect_now=False, user='not_exist')
42+
43+
# Start a server.
44+
self.srv.start()
45+
46+
# Trigger a reconnection due to wrong credentials.
47+
with warnings.catch_warnings():
48+
warnings.simplefilter("ignore")
49+
with self.assertRaises(tarantool.error.DatabaseError):
50+
con.ping()
51+
52+
# Set right credentials and verify that the reconnection
53+
# succeeds.
54+
con.user = None
55+
self.assertIs(con.ping(notime=True), "Success")
56+
57+
# Close the connection and stop the server.
58+
con.close()
59+
self.srv.stop()
60+
61+
@classmethod
62+
def tearDownClass(self):
63+
self.srv.clean()

0 commit comments

Comments
 (0)