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 670864 - [gstdatetime] now and utc_now unit tests sometimes fail
[gstdatetime] now and utc_now unit tests sometimes fail
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal normal
: 0.10.37
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2012-02-27 08:48 UTC by David Svensson Fors
Modified: 2012-02-27 12:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Use g_get_current_time and try twice (1.97 KB, patch)
2012-02-27 08:48 UTC, David Svensson Fors
none Details | Review

Description David Svensson Fors 2012-02-27 08:48:02 UTC
Created attachment 208470 [details] [review]
Use g_get_current_time and try twice

To reproduce the bug, I run the GstDateTime unit tests test_GstDateTime_now and test_GstDateTime_utc_now, "forever":

GST_CHECKS=test_GstDateTime_now,test_GstDateTime_utc_now make -C tests/check gst/gstdatetime.forever

Within 10 seconds, I get a failure like the following:

Running suite(s): GstDateTime
50%: Checks: 2, Failures: 1, Errors: 0
gst/gstdatetime.c:52:F:general:test_GstDateTime_now:0: 'gst_date_time_get_second (dt)' (45) is not equal to 'tm.tm_sec' (44)

I've attached a proposed patch for this bug. The tests use the Linux system call time() for getting a time reference, and then call the tested functions gst_date_time_new_now_local_time and gst_date_time_new_now_utc. The tests expect to get times within the same second. We've found that there are two things that can cause the failure:

1) The Linux system call time() and g_get_current_time don't always return a time with the same second component, even if they are called simultaneously.
2) Between two calls that ask what time it is, some time may pass and we might simply get different seconds for that reason.

Regarding 1), I've changed from using time() to using g_get_current_time in the tests. g_get_current_time is used by the tested functions, and itself uses the system call gettimeofday. Some measurements showed that, on my system, time() switched over to a new seconds about 2-3 milliseconds later than gettimeofday. I.e., when I got the second 45 from gettimeofday, I could call time() many times during about 2-3 milliseconds, and still get 44. This may have to do with the different granularities of time() and gettimeofday.

Regarding 2), I added a while loop that tries twice if the tests get different seconds.
Comment 1 Tim-Philipp Müller 2012-02-27 09:39:31 UTC
Hrm, I had actually fixed this as well, but apparently forgot to push it. I've pushed my version of the patch now, since it seems simpler (KISS etc.):

 commit 64effe78e76ec434606962a83a250c3b1ab5d612
 Author: Tim-Philipp Müller <tim.muller@collabora.co.uk>
 Date:   Tue Feb 21 20:43:48 2012 +0000

    tests: make datetime test more reliably when comparing two almost identical nows
    
    Account for rounding errors in some places, and that two nows are
    not always entirely identical, so allow some leeway when comparing
    microseconds and seconds. Ran into this too often, esp. when the
    system is under load.

Hope it fixes the issue for you as well. If not, please re-open.
Comment 2 David Svensson Fors 2012-02-27 12:41:37 UTC
This solved my problem. Thanks!