Sha256: 78fba44f3fd7dfe011109ac45985cf87c75142ae53e6b10b5cd8be405a4c1754

Contents?: true

Size: 985 Bytes

Versions: 22

Compression:

Stored size: 985 Bytes

Contents

require "helper"
require "flipper/adapters/sync/interval_synchronizer"

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

  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
    now = described_class.now
    subject.call
    events.clear

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

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
flipper-0.22.2 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.22.1 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.22.0 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.21.0 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.21.0.rc2 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.21.0.rc1 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.20.4 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.20.3 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.20.2 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.20.1 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.20.0 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.20.0.beta3 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.20.0.beta2 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.20.0.beta1 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.19.1 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.19.0 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.18.0 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.17.2 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.17.1 spec/flipper/adapters/sync/interval_synchronizer_spec.rb
flipper-0.16.2 spec/flipper/adapters/sync/interval_synchronizer_spec.rb