Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3b8577b

Browse files
committed
add docker-based tests with two nodes, stub for major/referee tests
1 parent1fa4fee commit3b8577b

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+
importunittest
2+
importtime
3+
importdatetime
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+
classTestHelper(object):
12+
13+
defassertIsolation(self,aggs):
14+
isolated=True
15+
forconn_id,agginenumerate(aggs):
16+
isolated=isolatedandagg['sumtotal']['isolation']==0
17+
ifnotisolated:
18+
raiseAssertionError('Isolation failure')
19+
20+
defassertCommits(self,aggs):
21+
commits=True
22+
forconn_id,agginenumerate(aggs):
23+
commits=commitsand'commit'inagg['transfer']['finish']
24+
ifnotcommits:
25+
print('No commits during aggregation interval')
26+
time.sleep(100000)
27+
raiseAssertionError('No commits during aggregation interval')
28+
29+
defassertNoCommits(self,aggs):
30+
commits=True
31+
forconn_id,agginenumerate(aggs):
32+
commits=commitsand'commit'inagg['transfer']['finish']
33+
ifcommits:
34+
raiseAssertionError('There are commits during aggregation interval')
35+
36+
defperformFailure(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+
importunittest
6+
importtime
7+
importsubprocess
8+
importdatetime
9+
importdocker
10+
importwarnings
11+
12+
fromlib.bank_clientimportMtmClient
13+
fromlib.failure_injectorimport*
14+
fromlib.test_helperimport*
15+
16+
17+
classMajorTest(unittest.TestCase,TestHelper):
18+
19+
@classmethod
20+
defsetUpClass(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+
deftearDownClass(cls):
39+
print('tearDown')
40+
cls.client.stop()
41+
42+
time.sleep(TEST_STOP_DELAY)
43+
44+
ifnotcls.client.is_data_identic():
45+
raiseAssertionError('Different data on nodes')
46+
47+
ifcls.client.no_prepared_tx()!=0:
48+
raiseAssertionError('There are some uncommitted tx')
49+
50+
# XXX: check nodes data identity here
51+
# subprocess.check_call(['docker-compose','down'])
52+
53+
defsetUp(self):
54+
warnings.simplefilter("ignore",ResourceWarning)
55+
time.sleep(20)
56+
print('Start new test at ',datetime.datetime.utcnow())
57+
58+
deftearDown(self):
59+
print('Finish test at ',datetime.datetime.utcnow())
60+
61+
deftest_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)

[8]ページ先頭

©2009-2025 Movatter.jp