nlf / riakdown

A riak-backed leveldown interface based on abstract-leveldown
MIT License
28 stars 2 forks source link

Get tests passing in PouchDB test suite #4

Closed nolanlawson closed 10 years ago

nolanlawson commented 10 years ago

I've recently started testing PouchDB Server with alternative backends, since PouchDB can can now use any *DOWN adapter as its data store. It'd be especially sweet if we could use PouchDB to replicate from Riak to CouchDB (or wherever), so of course I wanted to test out riakdown.

From tinkering with it, it seems to work great out of the box, but the PouchDB test suite is not passing. Truth be told, we have a pretty intense test suite, and IMO it often uncovers bugs that the abstract-leveldown tests don't. So hopefully presenting this information to you will be helpful.

To run the tests, you just do the following:

git clone -b riak https://github.com/pouchdb/pouchdb-server.git
cd pouchdb-server

Then the following steps are necessary because there's some stuff in pouchdb and node-levelup that hasn't been published yet:

npm install pouchdb@pouchdb/pouchdb#2362
cd node_modules/pouchdb
npm install levelup@rvagg/node-levelup
cd -

Then you start up the server (and this is seriously a command-line option I would like to support :smiley:)

npm install
node bin/pouchdb-server --port 6984 --riak riak://localhost:8087/

then in another shell run

cd node_modules/pouchdb
npm install
COUCH_HOST=http://localhost:6984 npm test

And you'll see the test output.

Probably the first thing you'll need to do is implement RiakDOWN.destroy(); I don't see it in the code base. In fact, it may turn out that's the only thing that's wrong, because in our test suite we're constantly destroying and re-creating databases between tests.

Hope that helps!

nlf commented 10 years ago

I've implemented RiakDOWN.destroy() in the 2i branch, but I'm still getting some test failures. Not entirely sure what the test is trying to do though, so I don't know how to proceed from here.

If you get a chance, give it a try and let me know what I still need to do. Thanks!

nolanlawson commented 10 years ago

I haven't looked at your specific failure, but I can give some pointers on how to debug with our test suite:

First, if you take off the --riak riak://localhost:8087/ part when you run pouchdb-server, it will use the default leveldown backend, which should pass all the tests. That way you can see the output from the server that we're expecting.

Second, when a particular test fails, instead of running COUCH_HOST=http://localhost:6984 npm test in the pouchdb/ folder you can run GREP=nameoftest COUCH_HOST=http://localhost:6984 npm test and it'll run just that one test.

Third, instead of running COUCH_HOST=http://localhost:6984 npm test, you can run COUCH_HOST=http://localhost:6984 npm run dev and it'll start a dev server so you can run the tests in the browser instead of in Node. (So instead of PouchDB over LevelDB on the client, it'll be PouchDB over IndexedDB in the browser as the client.) Then you can tick "async" in the Chrome dev tools if you're using the latest version of Chrome, and that's a really nice way to test given all our crazy promise chains. In the browser, you can append ?grep=foo to grep for a particular test.

However, YMMV with this method because I've occasionally noticed that race conditions that surface during the Node tests don't always surface in the browser tests.

Let me know if that helps! :)

nlf commented 10 years ago

Issues fixed, tests pass, published as version 1.0.0

nolanlawson commented 10 years ago

Awesome work. :)