I built an API that works with couchbase, using node.js and express. I am having an issue when I run my tests. In my test script I start out with defining a test for a POST request, that adds a document to a bucket. Then I have a GET request test that retrieves all the documents in the bucket and another GET request test that retrieves a document by its id. The test for the GET request that retrieves a document by id passes, but the test which retrieves all the documents in the bucket fails.
The difference between these two requests is that the GET request that retrieves all the documents in a bucket uses an N1QL query while the GET request that retrieves documents by id does not.
The issue here is due timing. For example if I add a for loop that iterates over a million numbers, just to waste time, right before the test for getting all the documents in the bucket, the test will pass.
Initially I thought that maybe the document, which is sent by the POST request test, is not being added to the database in time, before the ‘GET all documents’ test is executed. But this is not the problem since the ‘GET document by id’ test is passing.
This makes me think that the issue is being caused by couchbases querying system and that the Query Node in couchbase server is taking too long to recognize that the new document has been added to the database.
I was wondering if anyone else has run into a similar issue before? If yes how did you solve it? Also, I was wondering if their might be a better way for retrieving all the documents from a bucket, without using an N1QL query?