daleharvey/pouchdb — pull request #1366 by ig3 (2014-02-10 19:47:56+00:00)
Title: (#1356) Fix end of changes detection

Here is my scantly informed offering of a fix. Accept it with caution.

This assumes that update\_seq from db info is not the sequence number of the last document change, based on [COUCHDB-1367](https://issues.apache.org/jira/browse/COUCHDB-1367) and related discussions in the couchdb-dev mailing list. Therefore, all reference to update\_seq from db info has been removed from HttpPouch adapter's changes.

This also assumes that _changes returning a changes array with fewer than 'limit' changes only happens when the last change, as at the time the request was processed at source, has been returned. Therefore, the setting of var finished has been simplified.

Part of the removal to reference to update\_seq included removing an initial call to db.info for non-continuous changes, which broke test 'Changes reports errors' in test.changes.js. This test attempts to call changes against an uninitialized database on a server which accepts connections but never returns anything or closes the connection (at least that is my inference from the name (http://infiniterequest.com) and observed behaviour). With the initial call to db.info removed and no timeout on the request for \_changes, this resulted in the test itself timing out. To resolve this, I added opts.timeout to changes for the HttpPouch adapter, which defaults to 0 (no timeout - as it was before this change), and added option timeout: 10000 to the 'Changes reports errors' test so the test completes before the test timeout. With these changes, the test does return an error, as expected, although for rather different reasons. It isn't clear to me what fundamental behaviours of PouchDB this test is testing.

While this may not be an optimum or even a valid solution to the problem, it does pass all tests.