Return-Path: X-Original-To: apmail-couchdb-dev-archive@www.apache.org Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 204517283 for ; Thu, 11 Aug 2011 08:17:36 +0000 (UTC) Received: (qmail 36692 invoked by uid 500); 11 Aug 2011 08:17:33 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 35587 invoked by uid 500); 11 Aug 2011 08:17:21 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 35341 invoked by uid 99); 11 Aug 2011 08:17:10 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2011 08:17:10 +0000 Received: from localhost (HELO mail-iy0-f174.google.com) (127.0.0.1) (smtp-auth username rnewson, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2011 08:17:08 +0000 Received: by iyf40 with SMTP id 40so863468iyf.5 for ; Thu, 11 Aug 2011 01:17:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.12.7 with SMTP id v7mr11150045ibv.51.1313050627638; Thu, 11 Aug 2011 01:17:07 -0700 (PDT) Received: by 10.231.155.129 with HTTP; Thu, 11 Aug 2011 01:17:07 -0700 (PDT) In-Reply-To: References: Date: Thu, 11 Aug 2011 09:17:07 +0100 Message-ID: Subject: Re: Futon Test Suite From: Robert Newson To: dev@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Well, there are some cases where we need to work around browser (I mean, IE) bugs. This mechanism would be generic, so folks stuck supporting antique browsers have a way to fix themselves. For example, caching /_session is apparently the cause of login problems on antediluvian browsers. B. On 11 August 2011 08:37, Paul Davis wrote: > Seems like that'd just end up eating its way into the code base > special casing all the various places we set headers. > > On the other hand if we had a command line test runner and could very > specifically set headers without the confounding effects of running in > a browser this wouldn't even be an issue. > > On Thu, Aug 11, 2011 at 2:29 AM, Robert Newson wrote= : >> I wonder if we should add a custom request header like >> X-CouchDB-NoCache which sets all the cachebusting headers (Expires in >> the paste, etc) rather than that hack. >> >> On 11 August 2011 02:15, Filipe David Manana wrote= : >>> On Wed, Aug 10, 2011 at 5:58 PM, Paul Davis wrote: >>>> >>>> Since no one seems to have believed me I decided to take a closer look >>> >>> I believe you, and in my machine, replication.js, takes about 120ms. >>> >>>> at replication.js tests. And as I pointed out it was just polling a >>>> URL in a tight loop for 3s at a time. On my machine, this patch drops >>>> replication.js from 93329ms to 41785ms >>> >>> That's awesome. If it doesn't make assertions fails for others, go ahea= d. >>> >>> One thing I noticed in the past is that the browser seems to cache the >>> results of db.info() call. A solution (that is employed somewhere >>> else, but for another request) is to add some random parameter to the >>> query string, like =A0/db?anticache=3DMath.random(1000000). >>> >>>>. I'll point out that that's >>>> more than twice as fast. And that was just an obvious optimization >>>> from watching the log scroll. There are plenty more simple things that >>>> could be done to speed these up. >>>> >>>> Also, this patch makes me think that a _replication/localid -> JSON >>>> status blob might be useful. Though I dunno how possible that is. I >>>> reckon if we had that these would be sped up even more. >>>> >>>> >>>> diff --git a/share/www/script/couch.js b/share/www/script/couch.js >>>> index 304c9c1..792e638 100644 >>>> --- a/share/www/script/couch.js >>>> +++ b/share/www/script/couch.js >>>> @@ -40,6 +40,8 @@ function CouchDB(name, httpHeaders) { >>>> =A0 =A0 if (this.last_req.status =3D=3D 404) { >>>> =A0 =A0 =A0 return false; >>>> =A0 =A0 } >>>> + =A0 =A0var t0 =3D new Date(); >>>> + =A0 =A0while(true) {if((new Date()) - t0 > 100) break;} >>>> =A0 =A0 CouchDB.maybeThrowError(this.last_req); >>>> =A0 =A0 return JSON.parse(this.last_req.responseText); >>>> =A0 }; >>>> diff --git a/share/www/script/test/replication.js >>>> b/share/www/script/test/replication.js >>>> index 65c5eaa..b82375a 100644 >>>> --- a/share/www/script/test/replication.js >>>> +++ b/share/www/script/test/replication.js >>>> @@ -149,24 +149,40 @@ couchTests.replication =3D function(debug) { >>>> =A0 } >>>> >>>> >>>> - =A0function waitForSeq(sourceDb, targetDb) { >>>> - =A0 =A0var targetSeq, >>>> - =A0 =A0 =A0 =A0sourceSeq =3D sourceDb.info().update_seq, >>>> + =A0function waitForSeq(sourceDb, targetDb, rep_id) { >>>> + =A0 =A0var seq =3D sourceDb.info().update_seq, >>>> + =A0 =A0 =A0 =A0ri =3D new RegExp(rep_id), >>>> + =A0 =A0 =A0 =A0tasks, >>>> =A0 =A0 =A0 =A0 t0 =3D new Date(), >>>> =A0 =A0 =A0 =A0 t1, >>>> =A0 =A0 =A0 =A0 ms =3D 3000; >>>> >>>> =A0 =A0 do { >>>> - =A0 =A0 =A0targetSeq =3D targetDb.info().update_seq; >>>> + =A0 =A0 =A0tasks =3D JSON.parse(CouchDB.request("GET", >>>> "/_active_tasks").responseText); >>>> + =A0 =A0 =A0for(var i =3D 0; i < tasks.length; i++) { >>>> + =A0 =A0 =A0 =A0if(!ri.test(tasks[i].task)) continue; >>>> + =A0 =A0 =A0 =A0var captured =3D /Processed (\d+)/.exec(tasks[i].stat= us); >>>> + =A0 =A0 =A0 =A0if(parseInt(captured[1]) >=3D seq) return; >>>> + =A0 =A0 =A0 =A0break; >>>> + =A0 =A0 =A0} >>>> =A0 =A0 =A0 t1 =3D new Date(); >>>> - =A0 =A0} while (((t1 - t0) <=3D ms) && targetSeq < sourceSeq); >>>> + =A0 =A0} while ((t1 - t0) <=3D ms); >>>> =A0 } >>>> >>>> + =A0function waitForRepEnd(rep_id) { >>>> + =A0 =A0var ri =3D new RegExp(rep_id), >>>> + =A0 =A0 =A0 =A0tasks, >>>> + =A0 =A0 =A0 =A0t0 =3D new Date(), >>>> + =A0 =A0 =A0 =A0t1, >>>> + =A0 =A0 =A0 =A0ms =3D 3000; >>>> >>>> - =A0function wait(ms) { >>>> - =A0 =A0var t0 =3D new Date(), t1; >>>> =A0 =A0 do { >>>> - =A0 =A0 =A0CouchDB.request("GET", "/"); >>>> + =A0 =A0 =A0tasks =3D JSON.parse(CouchDB.request("GET", >>>> "/_active_tasks").responseText); >>>> + =A0 =A0 =A0var found =3D false; >>>> + =A0 =A0 =A0for(var i =3D 0; i < tasks.length; i++) { >>>> + =A0 =A0 =A0 =A0if(!ri.test(tasks[i].task)) found =3D true; >>>> + =A0 =A0 =A0} >>>> + =A0 =A0 =A0if(!found) return; >>>> =A0 =A0 =A0 t1 =3D new Date(); >>>> =A0 =A0 } while ((t1 - t0) <=3D ms); >>>> =A0 } >>>> @@ -1143,7 +1159,7 @@ couchTests.replication =3D function(debug) { >>>> >>>> =A0 =A0 var rep_id =3D repResult._local_id; >>>> >>>> - =A0 =A0waitForSeq(sourceDb, targetDb); >>>> + =A0 =A0waitForSeq(sourceDb, targetDb, rep_id); >>>> >>>> =A0 =A0 for (j =3D 0; j < docs.length; j++) { >>>> =A0 =A0 =A0 doc =3D docs[j]; >>>> @@ -1181,7 +1197,7 @@ couchTests.replication =3D function(debug) { >>>> =A0 =A0 var ddoc =3D docs[docs.length - 1]; // design doc >>>> =A0 =A0 addAtt(sourceDb, ddoc, "readme.txt", att1_data, "text/plain"); >>>> >>>> - =A0 =A0waitForSeq(sourceDb, targetDb); >>>> + =A0 =A0waitForSeq(sourceDb, targetDb, rep_id); >>>> >>>> =A0 =A0 var modifDocs =3D docs.slice(10, 15).concat([ddoc]); >>>> =A0 =A0 for (j =3D 0; j < modifDocs.length; j++) { >>>> @@ -1226,7 +1242,7 @@ couchTests.replication =3D function(debug) { >>>> =A0 =A0 // add another attachment to the ddoc on source >>>> =A0 =A0 addAtt(sourceDb, ddoc, "data.dat", att2_data, "application/bin= ary"); >>>> >>>> - =A0 =A0waitForSeq(sourceDb, targetDb); >>>> + =A0 =A0waitForSeq(sourceDb, targetDb, rep_id); >>>> >>>> =A0 =A0 copy =3D targetDb.open(ddoc._id); >>>> =A0 =A0 var atts =3D copy._attachments; >>>> @@ -1263,7 +1279,7 @@ couchTests.replication =3D function(debug) { >>>> =A0 =A0 var newDocs =3D makeDocs(25, 35); >>>> =A0 =A0 populateDb(sourceDb, newDocs, true); >>>> >>>> - =A0 =A0waitForSeq(sourceDb, targetDb); >>>> + =A0 =A0waitForSeq(sourceDb, targetDb, rep_id); >>>> >>>> =A0 =A0 for (j =3D 0; j < newDocs.length; j++) { >>>> =A0 =A0 =A0 doc =3D newDocs[j]; >>>> @@ -1282,7 +1298,7 @@ couchTests.replication =3D function(debug) { >>>> =A0 =A0 TEquals(true, sourceDb.deleteDoc(newDocs[0]).ok); >>>> =A0 =A0 TEquals(true, sourceDb.deleteDoc(newDocs[6]).ok); >>>> >>>> - =A0 =A0waitForSeq(sourceDb, targetDb); >>>> + =A0 =A0waitForSeq(sourceDb, targetDb, rep_id); >>>> >>>> =A0 =A0 copy =3D targetDb.open(newDocs[0]._id); >>>> =A0 =A0 TEquals(null, copy); >>>> @@ -1317,7 +1333,7 @@ couchTests.replication =3D function(debug) { >>>> =A0 =A0 }; >>>> =A0 =A0 TEquals(true, sourceDb.save(doc).ok); >>>> >>>> - =A0 =A0wait(2000); >>>> + =A0 =A0waitForRepEnd(rep_id); >>>> =A0 =A0 copy =3D targetDb.open(doc._id); >>>> =A0 =A0 TEquals(null, copy); >>>> =A0 } >>>> @@ -1359,7 +1375,7 @@ couchTests.replication =3D function(debug) { >>>> >>>> =A0 var tasksAfter =3D JSON.parse(xhr.responseText); >>>> =A0 TEquals(tasks.length, tasksAfter.length); >>>> - =A0waitForSeq(sourceDb, targetDb); >>>> + =A0waitForSeq(sourceDb, targetDb, rep_id); >>>> =A0 T(sourceDb.open("30") !=3D=3D null); >>>> >>>> =A0 // cancel replication >>>> >>> >>> >>> >>> -- >>> Filipe David Manana, >>> fdmanana@gmail.com, fdmanana@apache.org >>> >>> "Reasonable men adapt themselves to the world. >>> =A0Unreasonable men adapt the world to themselves. >>> =A0That's why all progress depends on unreasonable men." >>> >> >