|  | 
|  | 1 | +# frozen_string_literal: true | 
|  | 2 | + | 
|  | 3 | +RSpec.describe MeiliSearch::Index do | 
|  | 4 | +  before(:all) do | 
|  | 5 | +    @documents = [ | 
|  | 6 | +      { objectId: 123,  title: 'Pride and Prejudice' }, | 
|  | 7 | +      { objectId: 456,  title: 'Le Petit Prince' }, | 
|  | 8 | +      { objectId: 1,    title: 'Alice In Wonderland' }, | 
|  | 9 | +      { objectId: 1344, title: 'The Hobbit' }, | 
|  | 10 | +      { objectId: 4,    title: 'Harry Potter and the Half-Blood Prince' }, | 
|  | 11 | +      { objectId: 42,   title: 'The Hitchhiker\'s Guide to the Galaxy' } | 
|  | 12 | +    ] | 
|  | 13 | +    client = MeiliSearch::Client.new($URL, $MASTER_KEY) | 
|  | 14 | +    clear_all_indexes(client) | 
|  | 15 | +    @index = client.create_index(uid: 'books', primaryKey: 'objectId') | 
|  | 16 | +  end | 
|  | 17 | + | 
|  | 18 | +  it 'waits for pending update with default values' do | 
|  | 19 | +    response = @index.add_documents(@documents) | 
|  | 20 | +    update_id = response['updateId'] | 
|  | 21 | +    status = @index.wait_for_pending_update(update_id) | 
|  | 22 | +    expect(status).to be_a(Hash) | 
|  | 23 | +    expect(status['status']).not_to eq('enqueued') | 
|  | 24 | +  end | 
|  | 25 | + | 
|  | 26 | +  it 'waits for pending update with default values after several updates' do | 
|  | 27 | +    @index.add_documents(@documents) | 
|  | 28 | +    @index.add_documents(@documents) | 
|  | 29 | +    @index.add_documents(@documents) | 
|  | 30 | +    @index.add_documents(@documents) | 
|  | 31 | +    @index.add_documents(@documents) | 
|  | 32 | +    response = @index.add_documents(@documents) | 
|  | 33 | +    update_id = response['updateId'] | 
|  | 34 | +    status = @index.wait_for_pending_update(update_id) | 
|  | 35 | +    expect(status).to be_a(Hash) | 
|  | 36 | +    expect(status['status']).not_to eq('enqueued') | 
|  | 37 | +  end | 
|  | 38 | + | 
|  | 39 | +  it 'waits for pending update with custom timeout_in_ms and raises error' do | 
|  | 40 | +    @index.add_documents(@documents) | 
|  | 41 | +    response = @index.add_documents(@documents) | 
|  | 42 | +    update_id = response['updateId'] | 
|  | 43 | +    lambda { | 
|  | 44 | +      @index.wait_for_pending_update(update_id, 1) | 
|  | 45 | +    }.should raise_error(Timeout::Error) | 
|  | 46 | +  end | 
|  | 47 | + | 
|  | 48 | +  it 'waits for pending update with custom interval_in_ms and raises error' do | 
|  | 49 | +    @index.add_documents(@documents) | 
|  | 50 | +    response = @index.add_documents(@documents) | 
|  | 51 | +    update_id = response['updateId'] | 
|  | 52 | +    lambda { | 
|  | 53 | +      Timeout.timeout(0.1) do | 
|  | 54 | +        @index.wait_for_pending_update(update_id, 5000, 200) | 
|  | 55 | +      end | 
|  | 56 | +    }.should raise_error(Timeout::Error) | 
|  | 57 | +  end | 
|  | 58 | +end | 
0 commit comments