From fda591cf7d4db91222d1db988f570c6039182729 Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Thu, 1 May 2008 12:07:52 +0000 Subject: fix for compaction problem with attachments, and enhancements to JS shell, to make debugging tests easier. git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@652489 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/couch.js | 2 +- share/www/script/couch_tests.js | 20 ++++++++++++++++++++ share/www/script/shell.js | 22 ++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) (limited to 'share') diff --git a/share/www/script/couch.js b/share/www/script/couch.js index f1544893..5f42ac38 100644 --- a/share/www/script/couch.js +++ b/share/www/script/couch.js @@ -87,7 +87,7 @@ function CouchDB(name) { var result = JSON.parse(req.responseText); if (req.status != 201) throw result; - for(i in docs) { + for(var i in docs) { docs[i]._rev = result.new_revs[i].rev; } return result; diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 70879479..cf1a4865 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -849,6 +849,20 @@ var tests = { var docs = makeDocs(0, 10); var saveResult = db.bulkSave(docs); T(saveResult.ok); + + + var binAttDoc = { + _id:"bin_doc", + _attachments:{ + "foo.txt": { + "content-type":"text/plain", + "data": "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=" + } + } + } + + T(db.save(binAttDoc).ok); + var originalsize = db.info().disk_size; for(var i in docs) { @@ -862,6 +876,12 @@ var tests = { //compaction isn't instantaneous, loop until done while(db.info().compact_running) {}; + + + var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt"); + T(xhr.responseText == "This is a base64 encoded text") + T(xhr.getResponseHeader("content-type") == "text/plain") + var compactedsize = db.info().disk_size; T(deletesize > originalsize); diff --git a/share/www/script/shell.js b/share/www/script/shell.js index f4c6aff5..4b512dc1 100644 --- a/share/www/script/shell.js +++ b/share/www/script/shell.js @@ -698,3 +698,25 @@ function go(s) // Evaluate Shell.question using _win's eval (this is why eval isn't in the |with|, IIRC). _win.location.href = "javascript:try{ Shell.printAnswer(eval('with(Shell._scope) with(Shell.shellCommands) {' + Shell.question + String.fromCharCode(10) + '}')); } catch(er) { Shell.printError(er); }; setTimeout(Shell.refocus, 0); void 0"; } + +function T(Bool) { + if(!Bool) { + throw "Error!"; + } +} + + +function makeDocs(start, end, templateDoc) { + var templateDocSrc = templateDoc ? templateDoc.toSource() : "{}" + var docs = [] + for(var i=start; i