-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent from running multiple same cron jobs (#846)
- Loading branch information
Showing
2 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
# frozen_string_literals: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe CronsController, type: :controller do | ||
describe 'GET #create' do | ||
before do | ||
@request.env['REMOTE_ADDR'] = '127.0.0.1' | ||
allow(IO).to receive(:popen) | ||
.with('ps ax') | ||
.and_yield( | ||
StringIO.new(<<~STRING) | ||
PID TTY TIME CMD | ||
1 ? S 0:00 bash ./dump_measurements | ||
STRING | ||
) | ||
allow(controller).to receive(:system) # Not to run cron jobs | ||
allow($?).to receive(:success?).and_return(true) # rubocop:disable Style/SpecialGlobalVars | ||
end | ||
|
||
describe 'when task exists' do | ||
before do | ||
allow(controller).to receive(:taskname).and_return('dump_clean') | ||
end | ||
|
||
it 'returns HTTP 200 OK' do | ||
get :create | ||
|
||
expect(response).to have_http_status(200) | ||
end | ||
end | ||
|
||
describe 'when task exists but try to run same job' do | ||
before do | ||
allow(controller).to receive(:taskname).and_return('dump_measurements') | ||
end | ||
|
||
it 'returns HTTP 403 Forbidden' do | ||
get :create | ||
|
||
expect(response).to have_http_status(403) | ||
end | ||
end | ||
end | ||
end |