Skip to content

Commit 3b8577b

Browse files
committed
add docker-based tests with two nodes, stub for major/referee tests
1 parent 1fa4fee commit 3b8577b

File tree

3 files changed

+170
-0
lines changed

3 files changed

+170
-0
lines changed

tests2/lib/test_helper.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import unittest
2+
import time
3+
import datetime
4+
5+
TEST_WARMING_TIME = 5
6+
TEST_DURATION = 10
7+
TEST_RECOVERY_TIME = 30
8+
TEST_SETUP_TIME = 20
9+
TEST_STOP_DELAY = 5
10+
11+
class TestHelper(object):
12+
13+
def assertIsolation(self, aggs):
14+
isolated = True
15+
for conn_id, agg in enumerate(aggs):
16+
isolated = isolated and agg['sumtotal']['isolation'] == 0
17+
if not isolated:
18+
raise AssertionError('Isolation failure')
19+
20+
def assertCommits(self, aggs):
21+
commits = True
22+
for conn_id, agg in enumerate(aggs):
23+
commits = commits and 'commit' in agg['transfer']['finish']
24+
if not commits:
25+
print('No commits during aggregation interval')
26+
time.sleep(100000)
27+
raise AssertionError('No commits during aggregation interval')
28+
29+
def assertNoCommits(self, aggs):
30+
commits = True
31+
for conn_id, agg in enumerate(aggs):
32+
commits = commits and 'commit' in agg['transfer']['finish']
33+
if commits:
34+
raise AssertionError('There are commits during aggregation interval')
35+
36+
def performFailure(self, failure):
37+
38+
time.sleep(TEST_WARMING_TIME)
39+
40+
print('Simulate failure at ',datetime.datetime.utcnow())
41+
42+
failure.start()
43+
44+
self.client.clean_aggregates()
45+
print('Started failure at ',datetime.datetime.utcnow())
46+
47+
time.sleep(TEST_DURATION)
48+
49+
print('Getting aggs at ',datetime.datetime.utcnow())
50+
aggs_failure = self.client.get_aggregates()
51+
52+
53+
failure.stop()
54+
55+
print('Eliminate failure at ',datetime.datetime.utcnow())
56+
57+
self.client.clean_aggregates()
58+
time.sleep(TEST_RECOVERY_TIME)
59+
aggs = self.client.get_aggregates()
60+
61+
return (aggs_failure, aggs)

tests2/support/two_nodes.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: '2'
2+
3+
services:
4+
5+
node1:
6+
container_name: node1
7+
build: ../..
8+
privileged: true
9+
ulimits:
10+
core: 14294967296
11+
environment:
12+
POSTGRES_USER: 'pg'
13+
POSTGRES_DB: 'regression'
14+
NODE_ID: 1
15+
CONNSTRS: >-
16+
dbname=regression user=pg host=node1,
17+
dbname=regression user=pg host=node2
18+
ports:
19+
- "15432:5432"
20+
21+
node2:
22+
container_name: node2
23+
build: ../..
24+
privileged: true
25+
ulimits:
26+
core: 14294967296
27+
environment:
28+
POSTGRES_USER: 'pg'
29+
POSTGRES_DB: 'regression'
30+
NODE_ID: 2
31+
CONNSTRS: >-
32+
dbname=regression user=pg host=node1,
33+
dbname=regression user=pg host=node2
34+
ports:
35+
- "15433:5432"

tests2/test_major.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#
2+
# Based on Aphyr's test for CockroachDB.
3+
#
4+
5+
import unittest
6+
import time
7+
import subprocess
8+
import datetime
9+
import docker
10+
import warnings
11+
12+
from lib.bank_client import MtmClient
13+
from lib.failure_injector import *
14+
from lib.test_helper import *
15+
16+
17+
class MajorTest(unittest.TestCase, TestHelper):
18+
19+
@classmethod
20+
def setUpClass(cls):
21+
subprocess.check_call(['docker-compose',
22+
'-f', 'support/two_nodes.yml',
23+
'up',
24+
'--force-recreate',
25+
'--build',
26+
'-d'])
27+
28+
# XXX: add normal wait here
29+
time.sleep(TEST_SETUP_TIME)
30+
31+
cls.client = MtmClient([
32+
"dbname=regression user=postgres host=127.0.0.1 port=15432",
33+
"dbname=regression user=postgres host=127.0.0.1 port=15433"
34+
], n_accounts=1000)
35+
cls.client.bgrun()
36+
37+
@classmethod
38+
def tearDownClass(cls):
39+
print('tearDown')
40+
cls.client.stop()
41+
42+
time.sleep(TEST_STOP_DELAY)
43+
44+
if not cls.client.is_data_identic():
45+
raise AssertionError('Different data on nodes')
46+
47+
if cls.client.no_prepared_tx() != 0:
48+
raise AssertionError('There are some uncommitted tx')
49+
50+
# XXX: check nodes data identity here
51+
# subprocess.check_call(['docker-compose','down'])
52+
53+
def setUp(self):
54+
warnings.simplefilter("ignore", ResourceWarning)
55+
time.sleep(20)
56+
print('Start new test at ',datetime.datetime.utcnow())
57+
58+
def tearDown(self):
59+
print('Finish test at ',datetime.datetime.utcnow())
60+
61+
def test_node_partition(self):
62+
print('### test_node_partition ###')
63+
64+
aggs_failure, aggs = self.performFailure(SingleNodePartition('node2'))
65+
66+
self.assertNoCommits(aggs_failure)
67+
self.assertIsolation(aggs_failure)
68+
69+
self.assertCommits(aggs)
70+
self.assertIsolation(aggs)
71+
72+
if __name__ == '__main__':
73+
unittest.main()
74+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy