Problems with system time

I have a Ruby on Rails app that I’m testing with Rspec, and I’ve encountered a slightly odd issue. I’ve been running the tests in parallel in 4 separate containers, and in three of those, everything works fine. However, in the fourth one, the timestamps on the objects created by Rails are being set to the following:

2021-01-01T00:00:00.000Z

rather than the current UTC date/time.

The app relies on sorting objects by the created_at timestamp, and returning the last object (the most recent). But since the created_at and updated_at timestamps are all identical, it may return any one of the created objects, which then means that the tests fail. I’ve tried setting the timezones on the containers, but this seems to have no effect, and when I SSH into them and check the timezone being used by Rails, it returns the correct date/time. So this only seems to affect the test environment, and the third container (logging from the tests shows that other containers are populating the timestamps correctly).

Has anyone else encountered anything like this before? Any insight would be very gratefully received!

I have stumbled upon the same problem. When comparing Active Record objects, created_at timestamps are precisely at midnight:

created_at: #<ActiveSupport::TimeWithZone {
        year: 2021,
        month: 11,
        day: 4,
        hour: 0,
        min: 0,
        sec: 0,
        subsec: 0,
        zone: "EET",
        utc_offset: 7200
      }>

Sorry to hear that you’re having similar issues. I think I tracked my issue down to an issue with Timecop in the end, and realised that I wasn’t unfreezing the time properly in one place. This was really hard to spot because it only showed up as an issue when two tests happened to be back to back on the same container - otherwise they happened to pass locally and in all other containers. Sorry not to be able to offer any help with this (unless you’re also using Timecop). Good luck fixing the issue!