diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2017-12-18 13:08:51 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2017-12-18 13:08:51 +0000 |
commit | 924e00496c7d16887447b9384b66b555e5a9f911 (patch) | |
tree | ddf51b4cef3aa68eef7450a4c00eb28084f80eb9 /spec/lib | |
parent | 38dd7263e15e84c08b62c97028e943c759384b94 (diff) | |
parent | 4b0465f20de1bf58326c7daf6876b63438f00d84 (diff) | |
download | gitlab-ce-924e00496c7d16887447b9384b66b555e5a9f911.tar.gz |
Merge branch 'sh-add-schedule-pipeline-run-now' into 'master'
Add button to run scheduled pipeline immediately
Closes #38741
See merge request gitlab-org/gitlab-ce!15700
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/action_rate_limiter_spec.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/lib/gitlab/action_rate_limiter_spec.rb b/spec/lib/gitlab/action_rate_limiter_spec.rb new file mode 100644 index 00000000000..542fc03e555 --- /dev/null +++ b/spec/lib/gitlab/action_rate_limiter_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Gitlab::ActionRateLimiter do + let(:redis) { double('redis') } + let(:user) { create(:user) } + let(:project) { create(:project) } + let(:key) { [user, project] } + let(:cache_key) { "action_rate_limiter:test_action:user:#{user.id}:project:#{project.id}" } + + subject { described_class.new(action: :test_action, expiry_time: 100) } + + before do + allow(Gitlab::Redis::Cache).to receive(:with).and_yield(redis) + end + + it 'increases the throttle count and sets the expire time' do + expect(redis).to receive(:incr).with(cache_key).and_return(1) + expect(redis).to receive(:expire).with(cache_key, 100) + + expect(subject.throttled?(key, 1)).to be false + end + + it 'returns true if the key is throttled' do + expect(redis).to receive(:incr).with(cache_key).and_return(2) + expect(redis).not_to receive(:expire) + + expect(subject.throttled?(key, 1)).to be true + end +end |