Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 261b5bf

Browse files
funbringerkelvich
authored andcommitted
add tests for bootstrap and truncate
1 parent 63381e2 commit 261b5bf

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

testgres_tests/run.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/bash
2+
3+
if [ -z "$PG_CONFIG" ]; then
4+
>&2 echo ERROR: you must set PG_CONFIG
5+
exit 1
6+
fi
7+
8+
if [ -z "$VIRTUAL_ENV" ]; then
9+
>&2 echo WARNING: not in virtualenv
10+
fi
11+
12+
python -m unittest discover --pattern=*.py

testgres_tests/tests/__init__.py

Whitespace-only changes.

testgres_tests/tests/bootstrap.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import unittest
2+
from cluster import Cluster
3+
4+
5+
class Bootstrap(unittest.TestCase):
6+
def test_bootstrap(self):
7+
with Cluster(3).start().install() as cluster:
8+
for node in cluster.nodes:
9+
status = 'select status from mtm.get_cluster_state()'
10+
11+
self.assertTrue(node.status())
12+
self.assertTrue(node.execute('postgres', 'select true'))
13+
self.assertTrue(node.execute('postgres', status))

testgres_tests/tests/truncate.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import unittest
2+
import subprocess
3+
import time
4+
5+
from cluster import Cluster
6+
7+
8+
NUM_NODES = 2
9+
BENCH_SEC = 30
10+
11+
12+
class TestTruncate(unittest.TestCase):
13+
def test_truncate(self):
14+
with Cluster(NUM_NODES).start().install() as cluster:
15+
assert(NUM_NODES >= 2)
16+
17+
for node in cluster.nodes:
18+
self.assertTrue(node.status())
19+
20+
node_1 = cluster.nodes[0]
21+
node_1.pgbench_init(dbname=cluster.dbname)
22+
23+
pgbench = node_1.pgbench(dbname=cluster.dbname,
24+
stdout=subprocess.PIPE,
25+
stderr=subprocess.STDOUT,
26+
options=['-T%i' % BENCH_SEC])
27+
28+
count = 0
29+
started = time.time()
30+
while time.time() - started < BENCH_SEC:
31+
for node in cluster.nodes:
32+
node.safe_psql(dbname=cluster.dbname,
33+
username=cluster.username,
34+
query='truncate pgbench_history;')
35+
36+
node.safe_psql(dbname=cluster.dbname,
37+
username=cluster.username,
38+
query='vacuum full;')
39+
40+
count += 1
41+
42+
# check that pgbench has been running for at least 1 loop
43+
assert (count > 0 or pgbench.poll is not None)
44+
45+
time.sleep(0.5)
46+
47+
assert(count > 0)
48+
print("{}: executed truncate {} times"
49+
.format(self.test_truncate.__name__, count))
50+
51+
pgbench.wait()

0 commit comments

Comments
 (0)