couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1135871 - in /couchdb/branches/1.0.x: ./ etc/default/couchdb share/www/script/test/design_docs.js
Date Wed, 15 Jun 2011 00:33:22 GMT
Author: davisp
Date: Wed Jun 15 00:33:21 2011
New Revision: 1135871

URL: http://svn.apache.org/viewvc?rev=1135871&view=rev
Log:
Backport of r1035447 from trunk.

Refactoring of the design_docs.js test: fixed indentation and improved readability.


Modified:
    couchdb/branches/1.0.x/   (props changed)
    couchdb/branches/1.0.x/etc/default/couchdb   (props changed)
    couchdb/branches/1.0.x/share/www/script/test/design_docs.js

Propchange: couchdb/branches/1.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun 15 00:33:21 2011
@@ -6,4 +6,4 @@
 /couchdb/branches/list-iterator:782292-784593
 /couchdb/branches/tail_header:775760-778477
 /couchdb/tags/0.10.0:825400
-/couchdb/trunk:984170,984178,984214,984228,984237,984241,984501,991073,1029025-1029026,1029030,1045203,1083714,1095557,1095581,1097300,1099479
+/couchdb/trunk:984170,984178,984214,984228,984237,984241,984501,991073,1029025-1029026,1029030,1035447,1045203,1083714,1095557,1095581,1097300,1099479

Propchange: couchdb/branches/1.0.x/etc/default/couchdb
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun 15 00:33:21 2011
@@ -6,5 +6,5 @@
 /couchdb/branches/list-iterator/etc/default/couchdb:782292-784593
 /couchdb/branches/tail_header/etc/default/couchdb:775760-778477
 /couchdb/tags/0.10.0/etc/default/couchdb:825400
-/couchdb/trunk/etc/default/couchdb:984170,984178,984214,984228,984237,984241,984501,991073,1029025-1029026,1029030,1045203,1083714,1095557,1095581,1097300,1099479
+/couchdb/trunk/etc/default/couchdb:984170,984178,984214,984228,984237,984241,984501,991073,1029025-1029026,1029030,1035447,1045203,1083714,1095557,1095581,1097300,1099479
 /incubator/couchdb/trunk/etc/default/couchdb:642419-694440

Modified: couchdb/branches/1.0.x/share/www/script/test/design_docs.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/share/www/script/test/design_docs.js?rev=1135871&r1=1135870&r2=1135871&view=diff
==============================================================================
--- couchdb/branches/1.0.x/share/www/script/test/design_docs.js (original)
+++ couchdb/branches/1.0.x/share/www/script/test/design_docs.js Wed Jun 15 00:33:21 2011
@@ -13,206 +13,305 @@
 couchTests.design_docs = function(debug) {
   var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"});
   var db2 = new CouchDB("test_suite_db_a", {"X-Couch-Full-Commit":"false"});
+
+  if (debug) debugger;
+
   db.deleteDb();
   db.createDb();
   db2.deleteDb();
   db2.createDb();
-  if (debug) debugger;
 
-  run_on_modified_server(
-    [{section: "query_server_config",
+  var server_config = [
+    {
+      section: "query_server_config",
       key: "reduce_limit",
-      value: "false"}],
-function() {
+      value: "false"
+    }
+  ];
 
-  var numDocs = 500;
+  var testFun = function() {
+    var numDocs = 500;
 
-  function makebigstring(power) {
-    var str = "a";
-    while(power-- > 0) {
-      str = str + str;
+    function makebigstring(power) {
+      var str = "a";
+      while(power-- > 0) {
+        str = str + str;
+      }
+      return str;
     }
-    return str;
-  }
 
-  var designDoc = {
-    _id:"_design/test", // turn off couch.js id escaping?
-    language: "javascript",
-    whatever : {
-      stringzone : "exports.string = 'plankton';",
-      commonjs : {
-        whynot : "exports.test = require('../stringzone'); exports.foo = require('whatever/stringzone');",
-        upper : "exports.testing = require('./whynot').test.string.toUpperCase()+module.id+require('./whynot').foo.string"
+    var designDoc = {
+      _id: "_design/test",
+      language: "javascript",
+      whatever : {
+        stringzone : "exports.string = 'plankton';",
+        commonjs : {
+          whynot : "exports.test = require('../stringzone'); " +
+            "exports.foo = require('whatever/stringzone');",
+          upper : "exports.testing = require('./whynot').test.string.toUpperCase()+" +
+            "module.id+require('./whynot').foo.string"
+        }
+      },
+      views: {
+        all_docs_twice: {
+          map:
+            (function(doc) {
+              emit(doc.integer, null);
+              emit(doc.integer, null);
+            }).toString()
+        },
+        no_docs: {
+          map:
+            (function(doc) {
+            }).toString()
+        },
+        single_doc: {
+          map:
+            (function(doc) {
+              if (doc._id === "1") {
+                emit(1, null);
+              }
+            }).toString()
+        },
+        summate: {
+          map:
+            (function(doc) {
+              emit(doc.integer, doc.integer);
+            }).toString(),
+          reduce:
+            (function(keys, values) {
+              return sum(values);
+            }).toString()
+        },
+        summate2: {
+          map:
+            (function(doc) {
+              emit(doc.integer, doc.integer);
+            }).toString(),
+          reduce:
+            (function(keys, values) {
+              return sum(values);
+            }).toString()
+        },
+        huge_src_and_results: {
+          map:
+            (function(doc) {
+              if (doc._id === "1") {
+                emit(makebigstring(16), null);
+              }
+            }).toString(),
+          reduce:
+            (function(keys, values) {
+              return makebigstring(16);
+            }).toString()
+        },
+        lib : {
+          baz : "exports.baz = 'bam';",
+          foo : {
+            foo : "exports.foo = 'bar';",
+            boom : "exports.boom = 'ok';",
+            zoom : "exports.zoom = 'yeah';"
+          }
+        },
+        commonjs : {
+          map :
+            (function(doc) {
+              emit(null, require('views/lib/foo/boom').boom);
+            }).toString()
+        }
+      },
+      shows: {
+        simple:
+          (function() {
+            return 'ok';
+          }).toString(),
+        requirey:
+          (function() {
+            var lib = require('whatever/commonjs/upper');
+            return lib.testing;
+          }).toString(),
+        circular:
+          (function() {
+            var lib = require('whatever/commonjs/upper');
+            return JSON.stringify(this);
+          }).toString()
       }
-    },
-    views: {
-      all_docs_twice: {map: "function(doc) { emit(doc.integer, null); emit(doc.integer, null)
}"},
-      no_docs: {map: "function(doc) {}"},
-      single_doc: {map: "function(doc) { if (doc._id == \"1\") { emit(1, null) }}"},
-      summate: {map:"function (doc) {emit(doc.integer, doc.integer)};",
-                reduce:"function (keys, values) { return sum(values); };"},
-      summate2: {map:"function (doc) {emit(doc.integer, doc.integer)};",
-                reduce:"function (keys, values) { return sum(values); };"},
-      huge_src_and_results: {map: "function(doc) { if (doc._id == \"1\") { emit(\"" + makebigstring(16)
+ "\", null) }}",
-                reduce:"function (keys, values) { return \"" + makebigstring(16) + "\"; };"}
-    },
-    shows: {
-      simple: "function() {return 'ok'};",
-      requirey : "function() { var lib = require('whatever/commonjs/upper'); return lib.testing;
};",
-      circular : "function() { var lib = require('whatever/commonjs/upper'); return JSON.stringify(this);
};"
-    }
-  }; 
+    }; // designDoc
 
-  var xhr = CouchDB.request("PUT", "/test_suite_db_a/_design/test", {body: JSON.stringify(designDoc)});
-  var resp = JSON.parse(xhr.responseText);
-  
-  TEquals(resp.rev, db.save(designDoc).rev);
-
-  // test that editing a show fun on the ddoc results in a change in output
-  var xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_show/simple");
-  T(xhr.status == 200);
-  TEquals(xhr.responseText, "ok");
-
-  designDoc.shows.simple = "function() { return 'ko'; }";
-  T(db.save(designDoc).ok);
-
-  var xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_show/simple");
-  T(xhr.status == 200);
-  TEquals(xhr.responseText, "ko");
-
-  var xhr = CouchDB.request("GET", "/test_suite_db_a/_design/test/_show/simple?cache=buster");
-  T(xhr.status == 200);
-  TEquals("ok", xhr.responseText, 'query server used wrong ddoc');
-
-  // test commonjs require
-  var xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_show/requirey");
-  T(xhr.status == 200);
-  TEquals("PLANKTONwhatever/commonjs/upperplankton", xhr.responseText);
-
-  var xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_show/circular");
-  T(xhr.status == 200);
-  TEquals("javascript", JSON.parse(xhr.responseText).language);
-
-  var prev_view_sig = db.designInfo("_design/test").view_index.signature;
-  var prev_view_size = db.designInfo("_design/test").view_index.disk_size;
-
-  db.bulkSave(makeDocs(1, numDocs + 1));
-  T(db.ensureFullCommit().ok);
-
-  // test that we get correct design doc info back,
-  // and also that GET /db/_design/test/_info
-  // hasn't triggered an update of the views
-  db.view("test/summate", {stale: "ok"}); // make sure view group's open
-  for (var loop = 0; loop < 2; loop++) {
-    var dinfo = db.designInfo("_design/test");
-    TEquals("test", dinfo.name);
-    var vinfo = dinfo.view_index;
-    TEquals(prev_view_size, vinfo.disk_size, "view group disk size didn't change");
-    TEquals(false, vinfo.compact_running);
-    TEquals(prev_view_sig, vinfo.signature, 'ddoc sig');
-    // wait some time (there were issues where an update
-    // of the views had been triggered in the background)
-    var start = new Date().getTime();
-    while (new Date().getTime() < start + 2000);
-    TEquals(0, db.view("test/all_docs_twice", {stale: "ok"}).total_rows, 'view info');
-    TEquals(0, db.view("test/single_doc", {stale: "ok"}).total_rows, 'view info');
-    TEquals(0, db.view("test/summate", {stale: "ok"}).rows.length, 'view info');
+    var xhr = CouchDB.request(
+      "PUT", "/test_suite_db_a/_design/test", {body: JSON.stringify(designDoc)}
+    );
+    var resp = JSON.parse(xhr.responseText);
+
+    TEquals(resp.rev, db.save(designDoc).rev);
+
+    // test that editing a show fun on the ddoc results in a change in output
+    xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_show/simple");
+    T(xhr.status == 200);
+    TEquals(xhr.responseText, "ok");
+
+    designDoc.shows.simple = (function() {
+      return 'ko';
+    }).toString();
+    T(db.save(designDoc).ok);
+
+    xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_show/simple");
+    T(xhr.status == 200);
+    TEquals(xhr.responseText, "ko");
+
+    xhr = CouchDB.request(
+      "GET", "/test_suite_db_a/_design/test/_show/simple?cache=buster"
+    );
+    T(xhr.status == 200);
+    TEquals("ok", xhr.responseText, 'query server used wrong ddoc');
+
+    // test commonjs require
+    xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_show/requirey");
+    T(xhr.status == 200);
+    TEquals("PLANKTONwhatever/commonjs/upperplankton", xhr.responseText);
+
+    xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_show/circular");
+    T(xhr.status == 200);
+    TEquals("javascript", JSON.parse(xhr.responseText).language);
+
+    var prev_view_sig = db.designInfo("_design/test").view_index.signature;
+    var prev_view_size = db.designInfo("_design/test").view_index.disk_size;
+
+    db.bulkSave(makeDocs(1, numDocs + 1));
     T(db.ensureFullCommit().ok);
-    restartServer();
-  };
 
-  db.bulkSave(makeDocs(numDocs + 1, numDocs * 2 + 1));
-  T(db.ensureFullCommit().ok);
+    // test that we get correct design doc info back,
+    // and also that GET /db/_design/test/_info
+    // hasn't triggered an update of the views
+    db.view("test/summate", {stale: "ok"}); // make sure view group's open
+    for (var i = 0; i < 2; i++) {
+      var dinfo = db.designInfo("_design/test");
+      TEquals("test", dinfo.name);
+      var vinfo = dinfo.view_index;
+      TEquals(prev_view_size, vinfo.disk_size, "view group disk size didn't change");
+      TEquals(false, vinfo.compact_running);
+      TEquals(prev_view_sig, vinfo.signature, 'ddoc sig');
+      // wait some time (there were issues where an update
+      // of the views had been triggered in the background)
+      var start = new Date().getTime();
+      while (new Date().getTime() < start + 2000);
+      TEquals(0, db.view("test/all_docs_twice", {stale: "ok"}).total_rows, 'view info');
+      TEquals(0, db.view("test/single_doc", {stale: "ok"}).total_rows, 'view info');
+      TEquals(0, db.view("test/summate", {stale: "ok"}).rows.length, 'view info');
+      T(db.ensureFullCommit().ok);
+      restartServer();
+    };
 
-  // open view group
-  db.view("test/summate", {stale: "ok"});
-  // wait so the views can get initialized
-  var start = new Date().getTime();
-  while (new Date().getTime() < start + 2000);
-
-  // test that POST /db/_view_cleanup
-  // doesn't trigger an update of the views
-  var len1 = db.view("test/all_docs_twice", {stale: "ok"}).total_rows;
-  var len2 = db.view("test/single_doc", {stale: "ok"}).total_rows;
-  var len3 = db.view("test/summate", {stale: "ok"}).rows.length;
-  for (var loop = 0; loop < 2; loop++) {
-    T(db.viewCleanup().ok);
-    // wait some time (there were issues where an update
-    // of the views had been triggered in the background)
+    db.bulkSave(makeDocs(numDocs + 1, numDocs * 2 + 1));
+    T(db.ensureFullCommit().ok);
+
+    // open view group
+    db.view("test/summate", {stale: "ok"});
+    // wait so the views can get initialized
     var start = new Date().getTime();
     while (new Date().getTime() < start + 2000);
-    TEquals(len1, db.view("test/all_docs_twice", {stale: "ok"}).total_rows, 'view cleanup');
-    TEquals(len2, db.view("test/single_doc", {stale: "ok"}).total_rows, 'view cleanup');
-    TEquals(len3, db.view("test/summate", {stale: "ok"}).rows.length, 'view cleanup');
-    T(db.ensureFullCommit().ok);
-    restartServer();
-    // we'll test whether the view group stays closed
-    // and the views stay uninitialized (they should!)
-    len1 = len2 = len3 = 0;
-  };
-
-  // test that the _all_docs view returns correctly with keys
-  var results = db.allDocs({startkey:"_design", endkey:"_design0"});
-  T(results.rows.length == 1);
-
-  for (var loop = 0; loop < 2; loop++) {
-    var rows = db.view("test/all_docs_twice").rows;
-    for (var i = 0; i < numDocs; i++) {
-      T(rows[2*i].key == i+1);
-      T(rows[(2*i)+1].key == i+1);
+
+    // test that POST /db/_view_cleanup
+    // doesn't trigger an update of the views
+    var len1 = db.view("test/all_docs_twice", {stale: "ok"}).total_rows;
+    var len2 = db.view("test/single_doc", {stale: "ok"}).total_rows;
+    var len3 = db.view("test/summate", {stale: "ok"}).rows.length;
+    for (i = 0; i < 2; i++) {
+      T(db.viewCleanup().ok);
+      // wait some time (there were issues where an update
+      // of the views had been triggered in the background)
+      start = new Date().getTime();
+      while (new Date().getTime() < start + 2000);
+      TEquals(len1, db.view("test/all_docs_twice", {stale: "ok"}).total_rows, 'view cleanup');
+      TEquals(len2, db.view("test/single_doc", {stale: "ok"}).total_rows, 'view cleanup');
+      TEquals(len3, db.view("test/summate", {stale: "ok"}).rows.length, 'view cleanup');
+      T(db.ensureFullCommit().ok);
+      restartServer();
+      // we'll test whether the view group stays closed
+      // and the views stay uninitialized (they should!)
+      len1 = len2 = len3 = 0;
     };
-    T(db.view("test/no_docs").total_rows == 0);
-    T(db.view("test/single_doc").total_rows == 1);
-    T(db.ensureFullCommit().ok);
-    restartServer();
-  };
 
-  // test when language not specified, Javascript is implied
-  var designDoc2 = {
-    _id:"_design/test2",
-    // language: "javascript",
-    views: {
-      single_doc: {map: "function(doc) { if (doc._id == \"1\") { emit(1, null) }}"}
-    }
-  };
+    // test commonjs in map functions
+    resp = db.view("test/commonjs", {limit:1});
+    T(resp.rows[0].value == 'ok');
+
+    // test that the _all_docs view returns correctly with keys
+    var results = db.allDocs({startkey:"_design", endkey:"_design0"});
+    T(results.rows.length == 1);
+
+    for (i = 0; i < 2; i++) {
+      var rows = db.view("test/all_docs_twice").rows;
+      for (var j = 0; j < numDocs; j++) {
+        T(rows[2 * j].key == (j + 1));
+        T(rows[(2 * j) + 1].key == (j + 1));
+      };
+      T(db.view("test/no_docs").total_rows == 0);
+      T(db.view("test/single_doc").total_rows == 1);
+      T(db.ensureFullCommit().ok);
+      restartServer();
+    };
 
-  T(db.save(designDoc2).ok);
-  T(db.view("test2/single_doc").total_rows == 1);
+    // test when language not specified, Javascript is implied
+    var designDoc2 = {
+      _id: "_design/test2",
+      // language: "javascript",
+      views: {
+        single_doc: {
+          map:
+            (function(doc) {
+              if (doc._id === "1") {
+                emit(1, null);
+              }
+            }).toString()
+        }
+      }
+    };
 
-  var summate = function(N) {return (N+1)*N/2;};
-  var result = db.view("test/summate");
-  T(result.rows[0].value == summate(numDocs*2));
+    T(db.save(designDoc2).ok);
+    T(db.view("test2/single_doc").total_rows == 1);
 
-  result = db.view("test/summate", {startkey:4,endkey:4});
-  T(result.rows[0].value == 4);
+    var summate = function(N) {
+      return (N + 1) * (N / 2);
+    };
+    var result = db.view("test/summate");
+    T(result.rows[0].value == summate(numDocs * 2));
 
-  result = db.view("test/summate", {startkey:4,endkey:5});
-  T(result.rows[0].value == 9);
+    result = db.view("test/summate", {startkey: 4, endkey: 4});
+    T(result.rows[0].value == 4);
 
-  result = db.view("test/summate", {startkey:4,endkey:6});
-  T(result.rows[0].value == 15);
+    result = db.view("test/summate", {startkey: 4, endkey: 5});
+    T(result.rows[0].value == 9);
 
-  // Verify that a shared index (view def is an exact copy of "summate")
-  // does not confuse the reduce stage
-  result = db.view("test/summate2", {startkey:4,endkey:6});
-  T(result.rows[0].value == 15);
+    result = db.view("test/summate", {startkey: 4, endkey: 6});
+    T(result.rows[0].value == 15);
+
+    // Verify that a shared index (view def is an exact copy of "summate")
+    // does not confuse the reduce stage
+    result = db.view("test/summate2", {startkey: 4, endkey: 6});
+    T(result.rows[0].value == 15);
+
+    for(i = 1; i < (numDocs / 2); i += 30) {
+      result = db.view("test/summate", {startkey: i, endkey: (numDocs - i)});
+      T(result.rows[0].value == summate(numDocs - i) - summate(i - 1));
+    }
 
-  for(var i=1; i<numDocs/2; i+=30) {
-    result = db.view("test/summate", {startkey:i,endkey:numDocs-i});
-    T(result.rows[0].value == summate(numDocs-i) - summate(i-1));
-  }
+    T(db.deleteDoc(designDoc).ok);
+    T(db.open(designDoc._id) == null);
+    T(db.view("test/no_docs") == null);
 
-  T(db.deleteDoc(designDoc).ok);
-  T(db.open(designDoc._id) == null);
-  T(db.view("test/no_docs") == null);
+    T(db.ensureFullCommit().ok);
+    restartServer();
+    T(db.open(designDoc._id) == null);
+    T(db.view("test/no_docs") == null);
 
-  T(db.ensureFullCommit().ok);
-  restartServer();
-  T(db.open(designDoc._id) == null);
-  T(db.view("test/no_docs") == null);
+    // trigger ddoc cleanup
+    T(db.viewCleanup().ok);
+  }; // enf of testFun
 
-  // trigger ddoc cleanup
-  T(db.viewCleanup().ok);
+  run_on_modified_server(server_config, testFun);
 
-});
+  // cleanup
+  db.deleteDb();
+  db2.deleteDb();
 };



Mime
View raw message