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

Commite76232f

Browse files
committed
Fix tests for pg_dump and pg_restore
2 parents5e3c0f3 +7bcb4f3 commite76232f

File tree

11 files changed

+638
-475
lines changed

11 files changed

+638
-475
lines changed

‎.gitignore

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
*.pyc
2-
dist
3-
tags
4-
*.egg-info/
52
*.egg
6-
Dockerfile
7-
.coverage
3+
*.egg-info/
4+
dist
5+
86
env/
97
venv/
108
build/
9+
10+
.coverage
1111
coverage.xml
12+
13+
Dockerfile
14+
15+
*~
1216
*.swp
17+
tags

‎README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,9 @@ with testgres.get_new_node('master') as master:
154154
# start a new node
155155
master.init().start()
156156

157-
# initialize default database for TPC-B
158-
master.pgbench_run(options=['-i'])
159-
160-
# run benchmark for 20 seconds and show results
161-
print(master.pgbench_run(options=['-T','20']))
157+
# initialize default DB and run bench for 10 seconds
158+
res= master.pgbench_init(scale=2).pgbench_run(time=10)
159+
print(res)
162160
```
163161

164162

‎testgres/backup.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
fromsiximportraise_from
88

99
from .constsimport \
10-
DATA_DIRas_DATA_DIR, \
11-
BACKUP_LOG_FILEas_BACKUP_LOG_FILE, \
12-
DEFAULT_XLOG_METHODas_DEFAULT_XLOG_METHOD
10+
DATA_DIR, \
11+
PG_CONF_FILE, \
12+
BACKUP_LOG_FILE, \
13+
DEFAULT_XLOG_METHOD
1314

1415
from .exceptionsimportBackupException
1516

1617
from .utilsimport \
1718
get_bin_path, \
18-
default_usernameas_default_username, \
19-
execute_utilityas_execute_utility
19+
default_username, \
20+
execute_utility
2021

2122

2223
classNodeBackup(object):
@@ -26,13 +27,13 @@ class NodeBackup(object):
2627

2728
@property
2829
deflog_file(self):
29-
returnos.path.join(self.base_dir,_BACKUP_LOG_FILE)
30+
returnos.path.join(self.base_dir,BACKUP_LOG_FILE)
3031

3132
def__init__(self,
3233
node,
3334
base_dir=None,
3435
username=None,
35-
xlog_method=_DEFAULT_XLOG_METHOD):
36+
xlog_method=DEFAULT_XLOG_METHOD):
3637
"""
3738
Create a new backup.
3839
@@ -47,7 +48,7 @@ def __init__(self,
4748
raiseBackupException('Node must be running')
4849

4950
# Set default arguments
50-
username=usernameor_default_username()
51+
username=usernameordefault_username()
5152
base_dir=base_dirortempfile.mkdtemp()
5253

5354
# public
@@ -58,7 +59,7 @@ def __init__(self,
5859
# private
5960
self._available=True
6061

61-
data_dir=os.path.join(self.base_dir,_DATA_DIR)
62+
data_dir=os.path.join(self.base_dir,DATA_DIR)
6263

6364
# yapf: disable
6465
_params= [
@@ -69,7 +70,7 @@ def __init__(self,
6970
"-D",data_dir,
7071
"-X",xlog_method
7172
]
72-
_execute_utility(_params,self.log_file)
73+
execute_utility(_params,self.log_file)
7374

7475
def__enter__(self):
7576
returnself
@@ -97,8 +98,8 @@ def _prepare_dir(self, destroy):
9798
ifavailable:
9899
dest_base_dir=tempfile.mkdtemp()
99100

100-
data1=os.path.join(self.base_dir,_DATA_DIR)
101-
data2=os.path.join(dest_base_dir,_DATA_DIR)
101+
data1=os.path.join(self.base_dir,DATA_DIR)
102+
data2=os.path.join(dest_base_dir,DATA_DIR)
102103

103104
try:
104105
# Copy backup to new data dir
@@ -139,8 +140,8 @@ def spawn_primary(self, name=None, destroy=True, use_logging=False):
139140
# New nodes should always remove dir tree
140141
node._should_rm_dirs=True
141142

142-
node.append_conf("postgresql.conf","\n")
143-
node.append_conf("postgresql.conf","port = {}".format(node.port))
143+
node.append_conf(PG_CONF_FILE,"\n")
144+
node.append_conf(PG_CONF_FILE,"port = {}".format(node.port))
144145

145146
returnnode
146147

‎testgres/cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from .utilsimport \
1717
get_bin_path, \
18-
execute_utilityas_execute_utility
18+
execute_utility
1919

2020

2121
defcached_initdb(data_dir,initdb_logfile,initdb_params=[]):
@@ -26,7 +26,7 @@ def cached_initdb(data_dir, initdb_logfile, initdb_params=[]):
2626
defcall_initdb(initdb_dir):
2727
try:
2828
_params= [get_bin_path("initdb"),"-D",initdb_dir,"-N"]
29-
_execute_utility(_params+initdb_params,initdb_logfile)
29+
execute_utility(_params+initdb_params,initdb_logfile)
3030
exceptExecUtilExceptionase:
3131
raise_from(InitNodeException("Failed to run initdb"),e)
3232

‎testgres/connection.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
fromenumimportEnum
1313

1414
from .exceptionsimportQueryException
15-
from .utilsimportdefault_usernameas_default_username
15+
16+
from .utilsimport \
17+
default_dbname, \
18+
default_username
19+
1620

1721
# export these exceptions
1822
InternalError=pglib.InternalError
@@ -32,26 +36,34 @@ class NodeConnection(object):
3236
Transaction wrapper returned by Node
3337
"""
3438

35-
def__init__(self,
36-
parent_node,
37-
dbname,
38-
host="127.0.0.1",
39-
username=None,
40-
password=None):
39+
def__init__(self,node,dbname=None,username=None,password=None):
4140

42-
# Use default user if not specified
43-
username=usernameor_default_username()
41+
# Set default arguments
42+
dbname=dbnameordefault_dbname()
43+
username=usernameordefault_username()
4444

45-
self.parent_node=parent_node
45+
self._node=node
4646

47-
self.connection=pglib.connect(
47+
self._connection=pglib.connect(
4848
database=dbname,
4949
user=username,
50-
port=parent_node.port,
51-
host=host,
52-
password=password)
50+
password=password,
51+
host=node.host,
52+
port=node.port)
53+
54+
self._cursor=self.connection.cursor()
55+
56+
@property
57+
defnode(self):
58+
returnself._node
59+
60+
@property
61+
defconnection(self):
62+
returnself._connection
5363

54-
self.cursor=self.connection.cursor()
64+
@property
65+
defcursor(self):
66+
returnself._cursor
5567

5668
def__enter__(self):
5769
returnself
@@ -73,7 +85,7 @@ def begin(self, isolation_level=IsolationLevel.ReadCommitted):
7385

7486
# Get index of isolation level
7587
level_idx=isolation_level.value
76-
assert(level_idxinrange(4))
88+
assertlevel_idxinrange(4)
7789

7890
# Replace isolation level with its name
7991
isolation_level=levels[level_idx]

‎testgres/consts.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
DATA_DIR="data"
55
LOGS_DIR="logs"
66

7+
RECOVERY_CONF_FILE="recovery.conf"
8+
PG_CONF_FILE="postgresql.conf"
9+
HBA_CONF_FILE="pg_hba.conf"
10+
711
# names for log files
812
PG_LOG_FILE="postgresql.log"
913
UTILS_LOG_FILE="utils.log"
1014
BACKUP_LOG_FILE="backup.log"
1115

12-
# default argumentvalue
16+
# default argumentvalues
1317
DEFAULT_XLOG_METHOD="fetch"
18+
DEFAULT_DUMP_FORMAT="plain"

‎testgres/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
classTestgresLogger(threading.Thread):
1010
"""
11-
Helper class to implement reading frompostgresql.log
11+
Helper class to implement reading from log files.
1212
"""
1313

1414
def__init__(self,node_name,log_file_name):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp