[libgdata] contacts: Use fuzzy time comparisons when testing contact insertions



commit b1de9375b8c652c89415c5cde43607ffb06edbc2
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Jul 3 21:53:35 2012 +0100

    contacts: Use fuzzy time comparisons when testing contact insertions
    
    Yes, having a contact which was last edited before it was created is a valid
    thing.
    
    Helps: https://bugzilla.gnome.org/show_bug.cgi?id=679072

 gdata/tests/common.h   |    5 +++++
 gdata/tests/contacts.c |    7 ++++---
 2 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/gdata/tests/common.h b/gdata/tests/common.h
index 1da65fa..ca8f439 100644
--- a/gdata/tests/common.h
+++ b/gdata/tests/common.h
@@ -39,6 +39,11 @@ G_BEGIN_DECLS
 #define PASSWORD "libgdata-gdata"
 #define INCORRECT_PASSWORD "bad-password"
 
+/* The amount of fuzziness (in seconds) used in comparisons between times which should (theoretically) be equal.
+ * Due to the weak consistency used in Google's servers, it's hard to guarantee that timestamps which should be equal,
+ * actually are. */
+#define TIME_FUZZINESS 5
+
 void gdata_test_init (int argc, char **argv);
 
 gboolean gdata_test_internet (void);
diff --git a/gdata/tests/contacts.c b/gdata/tests/contacts.c
index 9ce908f..390c3db 100644
--- a/gdata/tests/contacts.c
+++ b/gdata/tests/contacts.c
@@ -394,11 +394,12 @@ test_contact_insert (InsertData *data, gconstpointer service)
 	gdata_test_compare_kind (GDATA_ENTRY (new_contact), "http://schemas.google.com/contact/2008#contact";, NULL);
 	g_clear_error (&error);
 
-	/* Check its edited date */
+	/* Check its edited date. Yes, we have to allow the edited time to possibly precede the creation time because Google's
+	 * servers can allow this to happen. Somehow. */
 	edited = gdata_contacts_contact_get_edited (contact);
 	creation_time = gdata_contacts_contact_get_edited (new_contact);
-	g_assert_cmpint (creation_time + 5, >=, edited);
-	g_assert_cmpint (creation_time, <=, edited);
+	g_assert_cmpint (creation_time + TIME_FUZZINESS, >=, edited);
+	g_assert_cmpint (creation_time - TIME_FUZZINESS, <=, edited);
 
 	/* Various properties */
 	g_assert_cmpstr (gdata_contacts_contact_get_nickname (new_contact), ==, "Big J");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]