Skip to content

Commit

Permalink
Merge branch 'master' into slash-names
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Jun 4, 2018
2 parents de10683 + f7bf21d commit 1acf979
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
13 changes: 7 additions & 6 deletions lib/flipper/adapters/sync/interval_synchronizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class IntervalSynchronizer
DEFAULT_INTERVAL = 10

# Private
def self.now_ms
Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
def self.now
Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
end

# Public: The Float or Integer number of seconds between invocations of
Expand All @@ -32,7 +32,7 @@ def initialize(synchronizer, interval: nil)
def call
return unless time_to_sync?

@last_sync_at = now_ms
@last_sync_at = now
@synchronizer.call

nil
Expand All @@ -41,11 +41,12 @@ def call
private

def time_to_sync?
((now_ms - @last_sync_at) / 1_000.0) >= @interval
seconds_since_last_sync = now - @last_sync_at
seconds_since_last_sync >= @interval
end

def now_ms
self.class.now_ms
def now
self.class.now
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/flipper/ui/views/feature.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</h4>
<div class="card-body">
<p>
<% if @feature.on? %>
<% if @feature.boolean_value %>
The feature is enabled for <strong>everyone</strong>. Disable this feature with one click.
<% else %>
Enable or disable this feature for <strong>everyone</strong> with one click.
Expand All @@ -24,7 +24,7 @@
<form action="<%= script_name %>/features/<%= @feature.key %>/boolean" method="post">
<%== csrf_input_tag %>
<% unless @feature.on? %>
<% unless @feature.boolean_value %>
<button type="submit" name="action" value="Enable" class="btn btn-danger" data-toggle="tooltip" title="Enable for everyone">Enable</button>
<% end %>

Expand Down
8 changes: 4 additions & 4 deletions spec/flipper/adapters/sync/interval_synchronizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

subject { described_class.new(synchronizer, interval: interval) }
Expand All @@ -15,19 +15,19 @@
end

it "only invokes wrapped synchronizer every interval seconds" do
now = described_class.now_ms
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_ms).and_return(now + (i * 1_000) - 1)
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_ms).and_return(now + (interval * 1_000))
allow(described_class).to receive(:now).and_return(now + interval)
subject.call
expect(events.size).to be(1)
end
Expand Down

0 comments on commit 1acf979

Please sign in to comment.