Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TestTestgresCommon - unified tests for local and remote #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5488ecd
TestTestgresCommon - unified tests for local and remote
dmitry-lipetsk Mar 12, 2025
a6edd3a
TestTestgresCommon is updated
dmitry-lipetsk Mar 12, 2025
3c055af
TestTestgresCommon is updated
dmitry-lipetsk Mar 13, 2025
188b3b2
TestTestgresCommon is updated
dmitry-lipetsk Mar 13, 2025
9b137ca
Merge branch 'master' into D20250312_002--TestTestgresCommon
dmitry-lipetsk Mar 13, 2025
9bddc3b
Merge branch 'master' into D20250312_002--TestTestgresCommon
dmitry-lipetsk Mar 14, 2025
75f0326
Merge branch 'master' into D20250312_002--TestTestgresCommon
dmitry-lipetsk Mar 16, 2025
292b403
TestTestgresCommon is updated
dmitry-lipetsk Mar 16, 2025
0fb22e8
PostgresNode_Base is added
dmitry-lipetsk Mar 16, 2025
2e5bd9d
test_simple_remote.py is cleaned
dmitry-lipetsk Mar 16, 2025
7f89186
Merge branch 'master' into D20250312_002--TestTestgresCommon
dmitry-lipetsk Mar 16, 2025
48fd887
Formatting (flake8)
dmitry-lipetsk Mar 16, 2025
bf28a1a
Formatting
dmitry-lipetsk Mar 17, 2025
f64dd60
PostgresNode_Base is updated (documentation)
dmitry-lipetsk Mar 17, 2025
490130e
PostgresNode is updated (documentation)
dmitry-lipetsk Mar 17, 2025
ff9b7bc
PostgresNode_Base::_prefix is removed
dmitry-lipetsk Mar 17, 2025
9e1979f
PostgresNode::clean is corrected
dmitry-lipetsk Mar 17, 2025
3e9cad1
node_base.py is updated
dmitry-lipetsk Mar 17, 2025
12fa7f2
node_base.py is updated
dmitry-lipetsk Mar 17, 2025
cef7982
node.py is updated
dmitry-lipetsk Mar 17, 2025
61feb2c
NodeApp::make_empty is updated
dmitry-lipetsk Mar 17, 2025
84a51c7
PostgresNode::cleanup is fixed
dmitry-lipetsk Mar 17, 2025
f7f915d
PostgresNode::cleanup is updated (flake8)
dmitry-lipetsk Mar 17, 2025
882b8ec
PostgresNode_Base::clone_with_new_name_and_base_dir is added
dmitry-lipetsk Mar 17, 2025
e8e392e
PostgresNode is updated (comment)
dmitry-lipetsk Mar 17, 2025
06287f2
Merge remote-tracking branch 'origin/D20250316_003--PostgresNode_Base…
dmitry-lipetsk Mar 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TestTestgresCommon is updated
New tests:
 - test_double_init
 - test_init_after_cleanup
 - test_init_unique_system_id
 - test_node_exit
 - test_double_start
 - test_uninitialized_start
 - test_restart
 - test_reload
 - test_pg_ctl
 - test_status

New methods:
 - helper__skip_test_if_pg_version_is_not_ge
 - helper__skip_test_if_util_not_exist
 - helper__util_exists
  • Loading branch information
dmitry-lipetsk committed Mar 13, 2025
commit 188b3b2327b99a4b457c60b80ff609ecdda01ab5
139 changes: 0 additions & 139 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
pop_config

from ..testgres import \
NodeStatus, \
get_new_node

from ..testgres import \
Expand Down Expand Up @@ -125,144 +124,6 @@ def test_custom_init(self):
# there should be no trust entries at all
assert not (any('trust' in s for s in lines))

def test_double_init(self):
with get_new_node().init() as node:
# can't initialize node more than once
with pytest.raises(expected_exception=InitNodeException):
node.init()

def test_init_after_cleanup(self):
with get_new_node() as node:
node.init().start().execute('select 1')
node.cleanup()
node.init().start().execute('select 1')

def test_init_unique_system_id(self):
# this function exists in PostgreSQL 9.6+
__class__.helper__skip_test_if_util_not_exist("pg_resetwal")
__class__.helper__skip_test_if_pg_version_is_not_ge("9.6")

query = 'select system_identifier from pg_control_system()'

with scoped_config(cache_initdb=False):
with get_new_node().init().start() as node0:
id0 = node0.execute(query)[0]

with scoped_config(cache_initdb=True,
cached_initdb_unique=True) as config:
assert (config.cache_initdb)
assert (config.cached_initdb_unique)

# spawn two nodes; ids must be different
with get_new_node().init().start() as node1, \
get_new_node().init().start() as node2:

id1 = node1.execute(query)[0]
id2 = node2.execute(query)[0]

# ids must increase
assert (id1 > id0)
assert (id2 > id1)

def test_node_exit(self):
base_dir = None

with pytest.raises(expected_exception=QueryException):
with get_new_node().init() as node:
base_dir = node.base_dir
node.safe_psql('select 1')

# we should save the DB for "debugging"
assert (os.path.exists(base_dir))
rmtree(base_dir, ignore_errors=True)

with get_new_node().init() as node:
base_dir = node.base_dir

# should have been removed by default
assert not (os.path.exists(base_dir))

def test_double_start(self):
with get_new_node().init().start() as node:
# can't start node more than once
node.start()
assert (node.is_started)

def test_uninitialized_start(self):
with get_new_node() as node:
# node is not initialized yet
with pytest.raises(expected_exception=StartNodeException):
node.start()

def test_restart(self):
with get_new_node() as node:
node.init().start()

# restart, ok
res = node.execute('select 1')
assert (res == [(1, )])
node.restart()
res = node.execute('select 2')
assert (res == [(2, )])

# restart, fail
with pytest.raises(expected_exception=StartNodeException):
node.append_conf('pg_hba.conf', 'DUMMY')
node.restart()

def test_reload(self):
with get_new_node() as node:
node.init().start()

# change client_min_messages and save old value
cmm_old = node.execute('show client_min_messages')
node.append_conf(client_min_messages='DEBUG1')

# reload config
node.reload()

# check new value
cmm_new = node.execute('show client_min_messages')
assert ('debug1' == cmm_new[0][0].lower())
assert (cmm_old != cmm_new)

def test_pg_ctl(self):
with get_new_node() as node:
node.init().start()

status = node.pg_ctl(['status'])
assert ('PID' in status)

def test_status(self):
assert (NodeStatus.Running)
assert not (NodeStatus.Stopped)
assert not (NodeStatus.Uninitialized)

# check statuses after each operation
with get_new_node() as node:
assert (node.pid == 0)
assert (node.status() == NodeStatus.Uninitialized)

node.init()

assert (node.pid == 0)
assert (node.status() == NodeStatus.Stopped)

node.start()

assert (node.pid != 0)
assert (node.status() == NodeStatus.Running)

node.stop()

assert (node.pid == 0)
assert (node.status() == NodeStatus.Stopped)

node.cleanup()

assert (node.pid == 0)
assert (node.status() == NodeStatus.Uninitialized)

def test_psql(self):
with get_new_node().init().start() as node:

Expand Down
139 changes: 0 additions & 139 deletions tests/test_simple_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from ..testgres.exceptions import \
InitNodeException, \
StartNodeException, \
ExecUtilException, \
BackupException, \
QueryException, \
Expand All @@ -30,9 +29,6 @@
scoped_config, \
pop_config, testgres_config

from ..testgres import \
NodeStatus

from ..testgres import \
get_bin_path, \
get_pg_config, \
Expand Down Expand Up @@ -207,141 +203,6 @@ def test_init__unk_LANG_and_LC_CTYPE(self):
__class__.helper__restore_envvar("LC_CTYPE", prev_LC_CTYPE)
__class__.helper__restore_envvar("LC_COLLATE", prev_LC_COLLATE)

def test_double_init(self):
with __class__.helper__get_node().init() as node:
# can't initialize node more than once
with pytest.raises(expected_exception=InitNodeException):
node.init()

def test_init_after_cleanup(self):
with __class__.helper__get_node() as node:
node.init().start().execute('select 1')
node.cleanup()
node.init().start().execute('select 1')

def test_init_unique_system_id(self):
# this function exists in PostgreSQL 9.6+
__class__.helper__skip_test_if_util_not_exist("pg_resetwal")
__class__.helper__skip_test_if_pg_version_is_not_ge('9.6')

query = 'select system_identifier from pg_control_system()'

with scoped_config(cache_initdb=False):
with __class__.helper__get_node().init().start() as node0:
id0 = node0.execute(query)[0]

with scoped_config(cache_initdb=True,
cached_initdb_unique=True) as config:
assert (config.cache_initdb)
assert (config.cached_initdb_unique)

# spawn two nodes; ids must be different
with __class__.helper__get_node().init().start() as node1, \
__class__.helper__get_node().init().start() as node2:
id1 = node1.execute(query)[0]
id2 = node2.execute(query)[0]

# ids must increase
assert (id1 > id0)
assert (id2 > id1)

def test_node_exit(self):
with pytest.raises(expected_exception=QueryException):
with __class__.helper__get_node().init() as node:
base_dir = node.base_dir
node.safe_psql('select 1')

# we should save the DB for "debugging"
assert (__class__.sm_os_ops.path_exists(base_dir))
__class__.sm_os_ops.rmdirs(base_dir, ignore_errors=True)

with __class__.helper__get_node().init() as node:
base_dir = node.base_dir

# should have been removed by default
assert not (__class__.sm_os_ops.path_exists(base_dir))

def test_double_start(self):
with __class__.helper__get_node().init().start() as node:
# can't start node more than once
node.start()
assert (node.is_started)

def test_uninitialized_start(self):
with __class__.helper__get_node() as node:
# node is not initialized yet
with pytest.raises(expected_exception=StartNodeException):
node.start()

def test_restart(self):
with __class__.helper__get_node() as node:
node.init().start()

# restart, ok
res = node.execute('select 1')
assert (res == [(1,)])
node.restart()
res = node.execute('select 2')
assert (res == [(2,)])

# restart, fail
with pytest.raises(expected_exception=StartNodeException):
node.append_conf('pg_hba.conf', 'DUMMY')
node.restart()

def test_reload(self):
with __class__.helper__get_node() as node:
node.init().start()

# change client_min_messages and save old value
cmm_old = node.execute('show client_min_messages')
node.append_conf(client_min_messages='DEBUG1')

# reload config
node.reload()

# check new value
cmm_new = node.execute('show client_min_messages')
assert ('debug1' == cmm_new[0][0].lower())
assert (cmm_old != cmm_new)

def test_pg_ctl(self):
with __class__.helper__get_node() as node:
node.init().start()

status = node.pg_ctl(['status'])
assert ('PID' in status)

def test_status(self):
assert (NodeStatus.Running)
assert not (NodeStatus.Stopped)
assert not (NodeStatus.Uninitialized)

# check statuses after each operation
with __class__.helper__get_node() as node:
assert (node.pid == 0)
assert (node.status() == NodeStatus.Uninitialized)

node.init()

assert (node.pid == 0)
assert (node.status() == NodeStatus.Stopped)

node.start()

assert (node.pid != 0)
assert (node.status() == NodeStatus.Running)

node.stop()

assert (node.pid == 0)
assert (node.status() == NodeStatus.Stopped)

node.cleanup()

assert (node.pid == 0)
assert (node.status() == NodeStatus.Uninitialized)

def test_psql(self):
with __class__.helper__get_node().init().start() as node:
# check returned values (1 arg)
Expand Down
Loading