Sha256: 8ef1a082ef4fe8bc4e053f27faf8037c0de792485c4c25c5a828d666329c7243

Contents?: true

Size: 1.49 KB

Versions: 16

Compression:

Stored size: 1.49 KB

Contents

require 'spec_helper'

class WaitForModel < Sample::Model
  identity :id

  attribute :name
end

class WaitForModels < Sample::Collection
  model WaitForModel

  def get(identity)
    self
  end
end

describe 'Cistern#wait_for' do
  it "should return false if timeout exceeded" do
    expect(Cistern.wait_for(0, 0) { false }).to be_falsey
  end
end

describe 'Cistern#wait_for!' do
  it "should raise if timeout exceeded" do
    expect { Cistern.wait_for!(0, 0) { false } }.to raise_exception(Cistern::Timeout)
  end
end

describe 'Cistern::Model#wait_for!' do
  let(:service) { Sample.new }
  let(:model)   { service.wait_for_models.new(identity: 1) }

  it "should raise if timeout exceeded" do
    expect { model.wait_for!(0, 0) { false } }.to raise_exception(Sample::Timeout)
  end
end


describe "WaitForModel#timeout" do
  let(:service) { Sample.new }
  let(:model)   { service.wait_for_models.new(identity: 1) }

  it "should use service-specific timeout in #wait_for" do
    service.class.timeout = 0.1
    service.class.poll_interval = 0

    elapsed = 0

    timeout(2) do
      expect do
        model.wait_for! { sleep(0.2); elapsed += 0.2; elapsed > 0.2 }
      end.to raise_exception(Sample::Timeout)
    end
  end

  it "should favor explicit timeout" do
    service.class.timeout = 1
    service.class.poll_interval = 0

    elapsed = 0

    timeout(2) do
      expect do
        model.wait_for!(0.1) { sleep(0.2); elapsed += 0.2; elapsed > 0.2 }
      end.to raise_exception(Sample::Timeout)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
cistern-2.2.3 spec/wait_for_spec.rb
cistern-2.2.1 spec/wait_for_spec.rb
cistern-2.1.0 spec/wait_for_spec.rb
cistern-2.0.5 spec/wait_for_spec.rb
cistern-2.0.4 spec/wait_for_spec.rb
cistern-2.0.3 spec/wait_for_spec.rb
cistern-2.0.2 spec/wait_for_spec.rb
cistern-2.0.1 spec/wait_for_spec.rb
cistern-1.0.1.pre6 spec/wait_for_spec.rb
cistern-1.0.1.pre5 spec/wait_for_spec.rb
cistern-1.0.1.pre4 spec/wait_for_spec.rb
cistern-1.0.1.pre3 spec/wait_for_spec.rb
cistern-1.0.1.pre2 spec/wait_for_spec.rb
cistern-1.0.1.pre1 spec/wait_for_spec.rb
cistern-1.0.0.pre spec/wait_for_spec.rb
cistern-0.11.2.pre2 spec/wait_for_spec.rb