# Unit testing and ES

**URL:** <https://discuss.elastic.co/t/unit-testing-and-es/10537>\
**Category:** Elasticsearch\
**Created:** [January 29, 2013, 11:40am UTC](https://discuss.elastic.co/t/unit-testing-and-es/10537 "2013-01-29T11:40:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrea\_crotti](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@andrea\_crotti](https://discuss.elastic.co/u/andrea_crotti)\
**Post date:** [January 29, 2013, 11:40am UTC](https://discuss.elastic.co/t/unit-testing-and-es/10537/1 "2013-01-29T11:40:05Z")

</div>

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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [January 30, 2013, 8:05am UTC](https://discuss.elastic.co/t/unit-testing-and-es/10537/2 "2013-01-30T08:05:30Z")

</div>

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/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Tue, Jan 29, 2013 at 1:40 PM, andrea crotti [andrea.crotti.0@gmail.com](mailto:andrea.crotti.0@gmail.com)wrote:

> 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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:54am UTC](https://discuss.elastic.co/t/unit-testing-and-es/10537/3 "2017-07-06T02:54:04Z")

</div>


