[memcached] bradfitz, r346: improve flush_all test, including adding...

commits at code.sixapart.com commits at code.sixapart.com
Mon Sep 4 06:33:37 UTC 2006


improve flush_all test, including adding failing (skipped) tests for a known issue.

also, this patch fixes this:

+    /* make the time we started always be 1 second before we really
+       did, so time(0) - time.started is never zero.  if so, things
+       like 'settings.oldest_live' which act as booleans as well as
+       values are now false in boolean context... */
+    stats.started = time(0) - 1;

which maybe only matters for test suites, but still.... not sure.
could affect other things.




U   trunk/server/memcached.c
U   trunk/server/memcached.h
U   trunk/server/test/flush-all.t


Modified: trunk/server/memcached.c
===================================================================
--- trunk/server/memcached.c	2006-09-04 06:16:24 UTC (rev 345)
+++ trunk/server/memcached.c	2006-09-04 06:33:36 UTC (rev 346)
@@ -85,7 +85,12 @@
     stats.curr_items = stats.total_items = stats.curr_conns = stats.total_conns = stats.conn_structs = 0;
     stats.get_cmds = stats.set_cmds = stats.get_hits = stats.get_misses = 0;
     stats.curr_bytes = stats.bytes_read = stats.bytes_written = 0;
-    stats.started = time(0);
+
+    /* make the time we started always be 1 second before we really
+       did, so time(0) - time.started is never zero.  if so, things
+       like 'settings.oldest_live' which act as booleans as well as
+       values are now false in boolean context... */
+    stats.started = time(0) - 1;
 }
 void stats_reset(void) {
     stats.total_items = stats.total_conns = 0;
@@ -1137,6 +1142,7 @@
     if (strncmp(command, "flush_all", 9) == 0) {
         time_t exptime = 0;
         int res;
+        set_current_time();
 
         if (strcmp(command, "flush_all") == 0) {
             settings.oldest_live = current_time;
@@ -1801,6 +1807,11 @@
 volatile rel_time_t current_time;
 struct event clockevent;
 
+/* time-sensitive callers can call it by hand with this, outside the normal ever-1-second timer */
+void set_current_time () {
+    current_time = (rel_time_t) (time(0) - stats.started);
+}
+
 void clock_handler(int fd, short which, void *arg) {
     struct timeval t;
     static int initialized = 0;
@@ -1817,7 +1828,7 @@
     t.tv_usec = 0;
     evtimer_add(&clockevent, &t);
 
-    current_time = (rel_time_t) (time(0) - stats.started);
+    set_current_time();
 }
 
 struct event deleteevent;

Modified: trunk/server/memcached.h
===================================================================
--- trunk/server/memcached.h	2006-09-04 06:16:24 UTC (rev 345)
+++ trunk/server/memcached.h	2006-09-04 06:33:36 UTC (rev 346)
@@ -271,3 +271,8 @@
 char *item_cachedump(unsigned int slabs_clsid, unsigned int limit, unsigned int *bytes);
 char *item_stats_sizes(int *bytes);
 void item_stats(char *buffer, int buflen);
+
+/* time handling */
+void set_current_time ();  /* update the global variable holding
+                              global 32-bit seconds-since-start time
+                              (to avoid 64 bit time_t) */

Modified: trunk/server/test/flush-all.t
===================================================================
--- trunk/server/test/flush-all.t	2006-09-04 06:16:24 UTC (rev 345)
+++ trunk/server/test/flush-all.t	2006-09-04 06:33:36 UTC (rev 346)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 
 use strict;
-use Test::More tests => 8;
+use Test::More tests => 7;
 use FindBin qw($Bin);
 use lib "$Bin/lib";
 use MemcachedTest;
@@ -18,6 +18,14 @@
 is(scalar <$sock>, "OK\r\n", "did flush_all");
 
 mem_get_is($sock, "foo", undef);
-sleep 2;
+SKIP: {
+    skip "flush_all is still only second-granularity.  need atomic counter on flush_all.", 2 unless 0;
+
+    print $sock "set foo 0 1 3\r\nnew\r\n";
+    is(scalar <$sock>, "STORED\r\n", "stored foo = 'new'");
+    mem_get_is($sock, "foo", 'new');
+}
+
+sleep 1;
 mem_get_is($sock, "foo", undef);
 




More information about the memcached-commits mailing list