Skip to content

Commit 3c3ab0b

Browse files
d-w-moorealanking
authored andcommitted
[#781] modify access_time test with guaranteed passing assertions
The test now fetches the modify and access timestamps during the interval in which the replica is open, then asserts those timestamps as equal to each other, as well as that they are greater than a system-generated datetime of about two seconds prior. (This is due to some timestamps including a microseconds count whereas others do not.)
1 parent d5de89b commit 3c3ab0b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

irods/test/data_obj_test.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def is_localhost_synonym(name):
6565
from irods.manager import data_object_manager
6666
from irods.message import RErrorStack
6767
from irods.message import ET, XML_Parser_Type, default_XML_parser, current_XML_parser
68-
from datetime import datetime
68+
from datetime import datetime, timezone, timedelta
6969
from tempfile import NamedTemporaryFile, gettempdir, mktemp
7070
from irods.test.helpers import unique_name, my_function_name
7171
from irods.ticket import Ticket
@@ -3305,16 +3305,20 @@ def test_access_time__issue_700(self):
33053305
if self.sess.server_version < (5,):
33063306
self.skipTest("iRODS servers < 5.0.0 do not provide an access_time attribute for data objects.")
33073307

3308-
data_path= iRODSPath(self.coll.path,
3309-
unique_name(my_function_name(), datetime.now())
3310-
)
3311-
with self.sess.data_objects.open(data_path,"w") as f:
3312-
f.write(b'_')
3313-
with self.sess.data_objects.open(data_path,"r") as f:
3314-
f.read()
3308+
prior_ts = datetime.now(timezone.utc) - timedelta(seconds=2)
3309+
3310+
# Create a new, uniquely named test data object.
3311+
data = self.sess.data_objects.create(
3312+
logical_path:=f'{helpers.home_collection(self.sess)}/{unique_name(my_function_name(), datetime.now())}'
3313+
)
3314+
3315+
with data.open('w') as f:
3316+
data = self.sess.data_objects.get(logical_path)
3317+
self.assertEqual(data.access_time, data.modify_time)
3318+
self.assertGreaterEqual(data.access_time, prior_ts)
33153319

3316-
data = self.sess.data_objects.get(data_path)
3317-
self.assertGreaterEqual(data.access_time, data.modify_time)
3320+
# Test that access_time is there, and of the right type.
3321+
self.assertIs(type(data.access_time), datetime)
33183322

33193323
if __name__ == "__main__":
33203324
# let the tests find the parent irods lib

0 commit comments

Comments
 (0)