Skip to content

Commit c696004

Browse files
committed
fixes in code & tests
1 parent e10520a commit c696004

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

testgres/cache.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,10 @@ def call_initdb(initdb_dir, log=None):
5959
# XXX: build new WAL segment with our system id
6060
_params = [get_bin_path("pg_resetwal"), "-D", data_dir, "-f"]
6161
execute_utility(_params, logfile)
62+
63+
except ExecUtilException as e:
64+
msg = "Failed to reset WAL for system id"
65+
raise_from(InitNodeException(msg), e)
66+
6267
except Exception as e:
6368
raise_from(InitNodeException("Failed to spawn a node"), e)

testgres/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ def generate_system_id():
7676
import datetime
7777
import struct
7878

79-
date = datetime.datetime.now()
80-
secs = int(date.timestamp())
81-
usecs = date.microsecond
79+
date1 = datetime.datetime.utcfromtimestamp(0)
80+
date2 = datetime.datetime.utcnow()
81+
82+
secs = int((date2 - date1).total_seconds())
83+
usecs = date2.microsecond
8284

8385
system_id = 0
8486
system_id |= (secs << 32)

tests/test_simple.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from testgres.utils import pg_version_ge
4242

4343

44-
def util_is_executable(util):
44+
def util_exists(util):
4545
def good_properties(f):
4646
# yapf: disable
4747
return (os.path.exists(f) and
@@ -91,6 +91,7 @@ def test_init_after_cleanup(self):
9191
node.cleanup()
9292
node.init().start().execute('select 1')
9393

94+
@unittest.skipUnless(util_exists('pg_resetwal'), 'might be missing')
9495
@unittest.skipUnless(pg_version_ge('9.6'), 'query works on 9.6+')
9596
def test_init_unique_system_id(self):
9697
with scoped_config(
@@ -507,7 +508,7 @@ def test_logging(self):
507508
master.restart()
508509
self.assertTrue(master._logger.is_alive())
509510

510-
@unittest.skipUnless(util_is_executable('pgbench'), 'might be missing')
511+
@unittest.skipUnless(util_exists('pgbench'), 'might be missing')
511512
def test_pgbench(self):
512513
with get_new_node().init().start() as node:
513514

0 commit comments

Comments
 (0)