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

Commit6a089e8

Browse files
committed
Add tests for concurrent updates
1 parent08eb0f4 commit6a089e8

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

‎Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ isolationcheck: | submake-isolation
9393
$(ISOLATIONCHECKS)
9494

9595
python_tests:
96-
$(MAKE) -C tests/python partitioning_tests
96+
$(MAKE) -C tests/python partitioning_tests CASE=$(CASE)
9797

9898
cmocka_tests:
9999
$(MAKE) -C tests/cmocka check

‎tests/python/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
partitioning_tests:
2-
python -m unittest --verbose --failfast partitioning_test.py
2+
ifneq ($(CASE),)
3+
python partitioning_test.py Tests.$(CASE)
4+
else
5+
python partitioning_test.py
6+
endif

‎tests/python/partitioning_test.py

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77
Copyright (c) 2015-2017, Postgres Professional
88
"""
99

10+
importfunctools
1011
importjson
1112
importmath
13+
importmultiprocessing
1214
importos
15+
importrandom
1316
importre
1417
importsubprocess
18+
importsys
1519
importthreading
1620
importtime
1721
importunittest
18-
importfunctools
1922

2023
fromdistutils.versionimportLooseVersion
2124
fromtestgresimportget_new_node,get_pg_version
@@ -85,10 +88,17 @@ def set_trace(self, con, command="pg_debug"):
8588
p=subprocess.Popen([command],stdin=subprocess.PIPE)
8689
p.communicate(str(pid).encode())
8790

88-
defstart_new_pathman_cluster(self,allow_streaming=False,test_data=False):
91+
defstart_new_pathman_cluster(self,
92+
allow_streaming=False,
93+
test_data=False,
94+
enable_partitionrouter=False):
95+
8996
node=get_new_node()
9097
node.init(allow_streaming=allow_streaming)
9198
node.append_conf("shared_preload_libraries='pg_pathman'\n")
99+
ifenable_partitionrouter:
100+
node.append_conf("pg_pathman.enable_partitionrouter=on\n")
101+
92102
node.start()
93103
node.psql('create extension pg_pathman')
94104

@@ -1065,6 +1075,57 @@ def test_update_node_plan1(self):
10651075
node.psql('postgres','DROP SCHEMA test_update_node CASCADE;')
10661076
node.psql('postgres','DROP EXTENSION pg_pathman CASCADE;')
10671077

1078+
deftest_concurrent_updates(self):
1079+
'''
1080+
Test whether conncurrent updates work correctly between
1081+
partitions.
1082+
'''
1083+
1084+
create_sql='''
1085+
CREATE TABLE test1(id INT, b INT NOT NULL);
1086+
INSERT INTO test1
1087+
SELECT i, i FROM generate_series(1, 100) i;
1088+
SELECT create_range_partitions('test1', 'b', 1, 5);
1089+
'''
1090+
1091+
withself.start_new_pathman_cluster(enable_partitionrouter=True)asnode:
1092+
node.safe_psql(create_sql)
1093+
1094+
pool=multiprocessing.Pool(processes=4)
1095+
forcountinrange(1,200):
1096+
pool.apply_async(make_updates, (node,count, ))
1097+
1098+
pool.close()
1099+
pool.join()
1100+
1101+
# check all data is there and not duplicated
1102+
withnode.connect()ascon:
1103+
foriinrange(1,100):
1104+
row=con.execute("select count(*) from test1 where id = %d"%i)[0]
1105+
self.assertEqual(row[0],1)
1106+
1107+
self.assertEqual(node.execute("select count(*) from test1")[0][0],100)
1108+
1109+
1110+
defmake_updates(node,count):
1111+
update_sql='''
1112+
BEGIN;
1113+
UPDATE test1 SET b = trunc(random() * 100 + 1) WHERE id in (%s);
1114+
COMMIT;
1115+
'''
1116+
1117+
withnode.connect()ascon:
1118+
foriinrange(count):
1119+
rows_to_update=random.randint(20,50)
1120+
ids=set([str(random.randint(1,100))foriinrange(rows_to_update)])
1121+
con.execute(update_sql%','.join(ids))
1122+
10681123

10691124
if__name__=="__main__":
1070-
unittest.main()
1125+
iflen(sys.argv)>1:
1126+
suite=unittest.TestLoader().loadTestsFromName(sys.argv[1],
1127+
module=sys.modules[__name__])
1128+
else:
1129+
suite=unittest.TestLoader().loadTestsFromTestCase(Tests)
1130+
1131+
unittest.TextTestRunner(verbosity=2,failfast=True).run(suite)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp