@@ -1399,6 +1399,8 @@ class SerializedDocument < ActiveRecord::Base
13991399end 
14001400
14011401describe  'Raise on failure'  do 
1402+   before  {  Vegetable . instance_variable_set ( '@ms_indexes' ,  nil )  } 
1403+ 
14021404  it  'raises on failure'  do 
14031405    expect  do 
14041406      Fruit . search ( '' ,  {  filter : 'title = Nightshift'  } ) 
@@ -1410,6 +1412,33 @@ class SerializedDocument < ActiveRecord::Base
14101412      Vegetable . search ( '' ,  {  filter : 'title = Kale'  } ) 
14111413    end . not_to  raise_error 
14121414  end 
1415+ 
1416+   context  'when Meilisearch server take too long to answer'  do 
1417+     let ( :index_instance )  {  instance_double ( MeiliSearch ::Index ,  settings : nil ,  update_settings : nil )  } 
1418+     let ( :slow_client )  {  instance_double ( MeiliSearch ::Client ,  index : index_instance )  } 
1419+ 
1420+     it  'does not raise error timeouts on reindex'  do 
1421+       allow ( index_instance ) . to  receive ( :add_documents ) . and_raise ( MeiliSearch ::TimeoutError ) 
1422+       allow ( slow_client ) . to  receive ( :create_index ) . and_return ( index_instance ) 
1423+ 
1424+       allow ( MeiliSearch ::Rails ) . to  receive ( :client ) . and_return ( slow_client ) 
1425+ 
1426+       expect  do 
1427+         Vegetable . create ( name : 'potato' ) 
1428+       end . not_to  raise_error 
1429+     end 
1430+ 
1431+     it  'does not raise error timeouts on data addition'  do 
1432+       allow ( slow_client ) . to  receive ( :create_index ) . and_raise ( MeiliSearch ::TimeoutError ) 
1433+       allow ( index_instance ) . to  receive ( :add_documents ) . and_return ( nil ) 
1434+ 
1435+       allow ( MeiliSearch ::Rails ) . to  receive ( :client ) . and_return ( slow_client ) 
1436+ 
1437+       expect  do 
1438+         Vegetable . ms_reindex! 
1439+       end . not_to  raise_error 
1440+     end 
1441+   end 
14131442end 
14141443
14151444context  "when have a internal class defined in the app's scope"  do 
0 commit comments