Reindex Search API indexes for Behat testing I tried to use index the newly created contents to be able to test a page, but the problem is most of the times the tests fails, because the indexing process not finished yet until the contents starts checking. (i.e. if I stop before pageload with a breakpoint the testing, then the next steps always pass)

Method 1:

$search_api_index = search_api_index_load('SEARCH_API_INDEX_ID');
search_api_index_items($search_api_index);


Method 2:

search_api_cron();


The question, how can I call the indexing to wait until it's fully indexed before it goes forward?
The ultimate solution is $search_api_index-&gt;server()-&gt;commit() which needed because, there's a commit delay which you can set inside the solrconfig.xml and this delay cause the problem. (Or you can just sleep(1) your code, but that's not flexible at all and ugly...)