After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 749080 - gdatetime test: fails if close to rollover between seconds
gdatetime test: fails if close to rollover between seconds
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.45.x
Other Linux
: Normal normal
: ---
Assigned To: Simon McVittie
gtkdev
: 725668 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2015-05-07 17:08 UTC by Simon McVittie
Modified: 2015-09-14 11:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gdatetime test: don't assume that time stands still (3.74 KB, patch)
2015-05-07 17:08 UTC, Simon McVittie
none Details | Review
[v2] gdatetime test: don't assume that time stands still (4.91 KB, patch)
2015-05-08 15:39 UTC, Simon McVittie
committed Details | Review

Description Simon McVittie 2015-05-07 17:08:25 UTC
Created attachment 303041 [details] [review]
gdatetime test: don't assume that time stands still

If we call time(NULL), then do something (however trivial), then call
g_date_time_new_now_utc(), they do not necessarily share a seconds
value. Let's say the gmtime call takes 2ms. time(NULL) could
return xx:xx:23 when the time is actually xx:xx:23.999999, resulting
in the g_date_time_new_now_utc() happening at xx:xx:24.000001. This is
unlikely, but did happen to me in a parallel build:

GLib:ERROR:.../glib/tests/gdatetime.c:674:test_GDateTime_now_utc: assertion failed (tm.tm_sec == g_date_time_get_second (dt)): (23 == 24)

A similar argument applies to the rollover from xx:23:59.999999 to
xx:24:00, so comparing seconds with a 1s "fuzz" or a >= comparison
is not sufficient; and so on into higher-order fields.

I haven't seen the other tests that use _now() fail in the same way,
but they could.
Comment 1 Philip Withnall 2015-05-08 08:29:14 UTC
Review of attachment 303041 [details] [review]:

The loops could do with a brief comment stating they’re there to handle the rare case of rollover in the number of seconds.
Comment 2 Simon McVittie 2015-05-08 15:39:27 UTC
Created attachment 303087 [details] [review]
[v2] gdatetime test: don't assume that time stands still

[same long commit message as before]

---

v2:

* add a comment before each loop
* replace an earlier attempt at this, with comment "XXX we need some fuzzyness here", with a check for strict equality; the earlier version would be OK at the boundary between seconds, but would fail at the boundary between minutes
Comment 3 Tim-Philipp Müller 2015-05-08 16:21:35 UTC
For what it's worth, this is how I fixed the same(?) issue in GstDatetime back in the day: http://cgit.freedesktop.org/gstreamer/gstreamer/commit/tests/check/gst/gstdatetime.c?id=64effe78e76ec434606962a83a250c3b1ab5d612

(don't judge me)
Comment 4 Simon McVittie 2015-05-08 16:35:19 UTC
(In reply to Tim-Philipp Müller from comment #3)
> For what it's worth, this is how I fixed the same(?) issue in GstDatetime
> back in the day

That has the same issue at the rollover between minutes (or higher-order time periods), afaics, so it makes the issue 60x less likely but doesn't actually eliminate it.
Comment 5 Philip Withnall 2015-05-11 15:37:11 UTC
Review of attachment 303087 [details] [review]:

Great!
Comment 6 Simon McVittie 2015-06-09 17:32:49 UTC
Does anyone object to this patch, or shall I commit it as reviewed by Philip?
Comment 7 Iain Lane 2015-09-14 10:32:11 UTC
*** Bug 725668 has been marked as a duplicate of this bug. ***
Comment 8 Iain Lane 2015-09-14 11:41:14 UTC
This went in.