Sha256: fe21f5de7bcf29b96fbd98487d8e793be1405f7961528dc08f4bd057061777a1

Contents?: true

Size: 941 Bytes

Versions: 32

Compression:

Stored size: 941 Bytes

Contents

require "flipper/adapters/sync/interval_synchronizer"

RSpec.describe Flipper::Adapters::Sync::IntervalSynchronizer do
  let(:events) { [] }
  let(:synchronizer) { -> { events << now } }
  let(:interval) { 10 }
  let(:now) { subject.send(:now) }

  subject { described_class.new(synchronizer, interval: interval) }

  it 'synchronizes on first call' do
    expect(events.size).to be(0)
    subject.call
    expect(events.size).to be(1)
  end

  it "only invokes wrapped synchronizer every interval seconds" do
    subject.call
    events.clear

    # move time to one millisecond less than last sync + interval
    1.upto(interval) do |i|
      allow(subject).to receive(:now).and_return(now + i - 1)
      subject.call
    end
    expect(events.size).to be(0)

    # move time to last sync + interval in milliseconds
    allow(subject).to receive(:now).and_return(now + interval)
    subject.call
    expect(events.size).to be(1)
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
flipper-1.3.2 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-1.3.1 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-1.3.0 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-1.3.0.pre spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-1.2.2 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-1.2.1 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-1.2.0 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-1.1.2 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-1.1.1 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-1.1.0 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-1.0.0 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-1.0.0.pre spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.28.3 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.28.2 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.28.1 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.28.0 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.27.1 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.27.0 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.26.2 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.26.1 spec/flipper/adapters/sync/interval_synchronizer_spec.rb