[memcached] bradfitz, r384: potential race. wait for early half of ...

commits at code.sixapart.com commits at code.sixapart.com
Sat Sep 9 19:49:09 UTC 2006


potential race.  wait for early half of second.



U   branches/memcached-1.1.x/t/expirations.t


Modified: branches/memcached-1.1.x/t/expirations.t
===================================================================
--- branches/memcached-1.1.x/t/expirations.t	2006-09-09 19:28:51 UTC (rev 383)
+++ branches/memcached-1.1.x/t/expirations.t	2006-09-09 19:49:09 UTC (rev 384)
@@ -10,6 +10,20 @@
 my $sock = $server->sock;
 my $expire;
 
+sub wait_for_early_second {
+    use Time::HiRes ();
+    my $tsh = Time::HiRes::time();
+    my $ts = int($tsh);  # in case time was overloaded to be hires.
+    return if ($tsh - $ts) < 0.5;
+    while (1) {
+        my $t = int(time());
+        return if $t != $ts;
+        select undef, undef, undef, 0.10;  # 1/10th of a second sleeps until time changes.
+    }
+}
+
+wait_for_early_second();
+
 print $sock "set foo 0 1 6\r\nfooval\r\n";
 is(scalar <$sock>, "STORED\r\n", "stored foo");
 




More information about the memcached-commits mailing list