I am assuming that you are either deleting or adding data between test runs, which is why you are checking for consistency. It’s a good idea to immediately query the view after loading/changing data with either stale=update_after or stale=false. In that case you know that the index has been updated. You can create a callback after the view query to run the tests. I am not sure what the tests are testing, so I am guessing here.
Flushing between tests is one good way to be sure old data/indexed data is gone.
Stale=false is a good way to trigger the indexers to update, but used for every query isn’t the best practice as it constantly triggers the indexers. It also increases latency for returned results as it has to update the index first.
You can use stale=update_after to the same effect by querying the view immediately after loading data, that triggers the indexers to update. Then query the view after that, however there will be a time gap between querying the view the first time and the second time for the index to be updated. How long that gap is depends on many factors including CPU, how horizontal the cluster is scaled compared to data size (i.e. number of nodes), network and disk speed. Essentially that is the same time gap experienced with stale=false, except it’s more asynchronous.
The other could be by using Observe on the last keys being set/added/replaced, observe has a callback to let you know it has been persisted to disk and/or replicas. Then after observe comes back querying a view with stale=false will trigger the indexers.
Let me add, you were asking if there was a way to iterate through keys, it depends on the keys, if they have any random elements (ex: GUID/UUID), then you need to either use a View or Elastic Search.
The default map function of:
function (doc, meta) {
emit(meta.id, null)
}
is a primary index on keys. That’s what you should use for listing all keys. If you literally just want ALL the keys and don’t need to do any querying whatsoever, no range of keys, etc. then, since the key is always associated with the row itself as well, you can do:
function (doc, meta) {
emit(null, null)
}
and each row still has the key associated with it, but it literally stores no data except a reference to the key.