Unit testing and ES

I have some tests that I need to run all the time to check if everything
works, and I also have some tests for ES, as for example this,
that checks if sorting on a python script works:

script = {
'script': "len(doc['ideas'])",
'lang': 'python',
'order': 'asc',
}

this only necessary to make sure we are using an updated version

CON.refresh()
sort = {'sort': {'_script': script}}
res = search(self.user_query, sort=sort)
res.total

FIXME: this only works sometimes, makes it work all the times

self.assertEqual(res[0]['name'], 'Joe Tester')

Now it's quite annoying because even with the refresh this test doesn't
always pass, but maybe half of the times only.
I suspect it's just a timing issue, but also adding sleeps here and there
doesn't seem to make a difference.
Is there some other way to tell to just force refreshing it somehow?
thanks

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hello,

If you use pyes, you might need to specify the index name when refreshing.
Something like:
CON.refresh(indices=["test-index"])

You can also put in a sleep there, if you're in for dirty hacks:
CON.refresh(indices=["test-index"], timesleep=1)

And depending on your version, you'll probably want to move to
CON.indices.refresh() instead of CON.refresh(), since the latter is
deprecated.

Best regards,
Radu

http://sematext.com/ -- ElasticSearch -- Solr -- Lucene

On Tue, Jan 29, 2013 at 1:40 PM, andrea crotti andrea.crotti.0@gmail.comwrote:

I have some tests that I need to run all the time to check if everything
works, and I also have some tests for ES, as for example this,
that checks if sorting on a python script works:

script = {
'script': "len(doc['ideas'])",
'lang': 'python',
'order': 'asc',
}

this only necessary to make sure we are using an updated version

CON.refresh()
sort = {'sort': {'_script': script}}
res = search(self.user_query, sort=sort)
res.total

FIXME: this only works sometimes, makes it work all the times

self.assertEqual(res[0]['name'], 'Joe Tester')

Now it's quite annoying because even with the refresh this test doesn't
always pass, but maybe half of the times only.
I suspect it's just a timing issue, but also adding sleeps here and there
doesn't seem to make a difference.
Is there some other way to tell to just force refreshing it somehow?
thanks

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.