Skip to content

RemoteOperations::exec_command explicitly transfers LANG, LANGUAGE and LC_* envvars to the server side #187

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

Prev Previous commit
Next Next commit
New tests in TestgresRemoteTests are added
New tests:
 - test_init__LANG_С
 - test_init__unk_LANG_and_LC_CTYPE
  • Loading branch information
dmitry-lipetsk committed Feb 21, 2025
commit 4eb833040f2f72e93e07a866b52c123e5003cc5d
56 changes: 56 additions & 0 deletions tests/test_simple_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,56 @@ def test_custom_init(self):
# there should be no trust entries at all
self.assertFalse(any('trust' in s for s in lines))

def test_init__LANG_С(self):
# PBCKP-1744
prev_LANG = os.environ.get("LANG")

try:
os.environ["LANG"] = "C"

with get_remote_node(conn_params=conn_params) as node:
node.init().start()
finally:
__class__.helper__restore_envvar("LANG", prev_LANG)

def test_init__unk_LANG_and_LC_CTYPE(self):
# PBCKP-1744
prev_LANG = os.environ.get("LANG")
prev_LANGUAGE = os.environ.get("LANGUAGE")
prev_LC_CTYPE = os.environ.get("LC_CTYPE")
prev_LC_COLLATE = os.environ.get("LC_COLLATE")

try:
os.environ["LANG"] = "UNKNOWN_LANG"
os.environ.pop("LANGUAGE", None)
os.environ["LC_CTYPE"] = "UNKNOWN_CTYPE"
os.environ.pop("LC_COLLATE", None)

assert os.environ.get("LANG") == "UNKNOWN_LANG"
assert not ("LANGUAGE" in os.environ.keys())
assert os.environ.get("LC_CTYPE") == "UNKNOWN_CTYPE"
assert not ("LC_COLLATE" in os.environ.keys())

while True:
try:
with get_remote_node(conn_params=conn_params):
pass
except testgres.exceptions.ExecUtilException as e:
# warning: setlocale: LC_CTYPE: cannot change locale (UNKNOWN_CTYPE): No such file or directory
# postgres (PostgreSQL) 14.12
errMsg = str(e)
assert "LC_CTYPE" in errMsg
assert "UNKNOWN_CTYPE" in errMsg
assert "warning: setlocale: LC_CTYPE: cannot change locale (UNKNOWN_CTYPE): No such file or directory" in errMsg
assert "postgres" in errMsg
break
raise Exception("We expected an error!")
finally:
__class__.helper__restore_envvar("LANG", prev_LANG)
__class__.helper__restore_envvar("LANGUAGE", prev_LANGUAGE)
__class__.helper__restore_envvar("LC_CTYPE", prev_LC_CTYPE)
__class__.helper__restore_envvar("LC_COLLATE", prev_LC_COLLATE)

def test_double_init(self):
with get_remote_node(conn_params=conn_params).init() as node:
# can't initialize node more than once
Expand Down Expand Up @@ -994,6 +1044,12 @@ def test_child_process_dies(self):
# try to handle children list -- missing processes will have ptype "ProcessType.Unknown"
[ProcessProxy(p) for p in children]

def helper__restore_envvar(name, prev_value):
if prev_value is None:
os.environ.pop(name, None)
else:
os.environ[name] = prev_value


if __name__ == '__main__':
if os_ops.environ('ALT_CONFIG'):
Expand Down