couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r819091 - in /couchdb/trunk: share/www/script/test/uuids.js src/couchdb/couch_httpd_misc_handlers.erl
Date Sat, 26 Sep 2009 02:46:41 GMT
Author: davisp
Date: Sat Sep 26 02:46:41 2009
New Revision: 819091

URL: http://svn.apache.org/viewvc?rev=819091&view=rev
Log:
Fix the UUID's test failures when clocks are out of sync.

Changes the tests for cache busting by using ETag's. Left the date tests commented out just
in case someone thinks I'm crazy and sees a better solution.


Modified:
    couchdb/trunk/share/www/script/test/uuids.js
    couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl

Modified: couchdb/trunk/share/www/script/test/uuids.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/uuids.js?rev=819091&r1=819090&r2=819091&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/uuids.js (original)
+++ couchdb/trunk/share/www/script/test/uuids.js Sat Sep 26 02:46:41 2009
@@ -11,16 +11,25 @@
 // the License.
 
 couchTests.uuids = function(debug) {
+  var etags = [];
   var testHashBustingHeaders = function(xhr) {
     T(xhr.getResponseHeader("Cache-Control").match(/no-cache/));
     T(xhr.getResponseHeader("Pragma") == "no-cache");
 
-    var currentTime = new Date();
-    var expiresHeader = Date.parse(xhr.getResponseHeader("Expires"));
-    var dateHeader = Date.parse(xhr.getResponseHeader("Date"));
+    var newetag = xhr.getResponseHeader("ETag");
+    T(etags.indexOf(newetag) < 0);
+    etags[etags.length] = newetag;
+    
+    // Removing the time based tests as they break easily when
+    // running CouchDB on a remote server in regards to the browser
+    // running the Futon test suite.
+    //
+    //var currentTime = new Date();
+    //var expiresHeader = Date.parse(xhr.getResponseHeader("Expires"));
+    //var dateHeader = Date.parse(xhr.getResponseHeader("Date"));
 
-    T(expiresHeader < currentTime);
-    T(currentTime - dateHeader < 3000);
+    //T(expiresHeader < currentTime);
+    //T(currentTime - dateHeader < 3000);
   };
 
   var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"});

Modified: couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl?rev=819091&r1=819090&r2=819091&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl Sat Sep 26 02:46:41 2009
@@ -106,13 +106,18 @@
 
 handle_uuids_req(#httpd{method='GET'}=Req) ->
     Count = list_to_integer(couch_httpd:qs_value(Req, "count", "1")),
-    CacheBustingHeaders = [{"Date", httpd_util:rfc1123_date()},
-                           {"Cache-Control", "no-cache"},
-                           % Past date, ON PURPOSE!
-                           {"Expires", "Fri, 01 Jan 1990 00:00:00 GMT"},
-                           {"Pragma", "no-cache"}],
     UUIDs = [couch_uuids:new() || _ <- lists:seq(1, Count)],
-    send_json(Req, 200, CacheBustingHeaders, {[{<<"uuids">>, UUIDs}]});
+    couch_httpd:etag_respond(Req, erlang:md5(UUIDs), fun() ->
+        CacheBustingHeaders = [
+            {"Date", httpd_util:rfc1123_date()},
+            {"Cache-Control", "no-cache"},
+            % Past date, ON PURPOSE!
+            {"Expires", "Fri, 01 Jan 1990 00:00:00 GMT"},
+            {"Pragma", "no-cache"},
+            {"ETag", erlang:md5(UUIDs)}
+        ],
+        send_json(Req, 200, CacheBustingHeaders, {[{<<"uuids">>, UUIDs}]})
+    end);
 handle_uuids_req(Req) ->
     send_method_not_allowed(Req, "GET").
 



Mime
View raw message