-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: start initialize field when process not alived
- Loading branch information
TamarinEA
committed
Aug 8, 2018
1 parent
8133182
commit aaf96b2
Showing
3 changed files
with
55 additions
and
1 deletion.
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,8 @@ | ||
FactoryGirl.define do | ||
factory 'denormalization/supervisor_status', class: 'Treasury::Models::SupervisorStatus' do | ||
active true | ||
need_terminate false | ||
state ::Treasury::Supervisor::STATE_RUNNING | ||
sequence(:pid) { |n| n } | ||
end | ||
end |
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,46 @@ | ||
require 'spec_helper' | ||
|
||
describe Treasury::Supervisor do | ||
let(:supervisor_status) { create :'denormalization/supervisor_status' } | ||
let(:supervisor) { described_class.new(supervisor_status) } | ||
|
||
describe '#run_initializers' do | ||
before { allow(supervisor).to receive(:process_is_alive?).and_return(false) } | ||
|
||
after { supervisor.send(:run_initializers) } | ||
|
||
context 'when all fields initialized' do | ||
before { create 'denormalization/field' } | ||
|
||
it { expect(supervisor).to_not receive(:run_initializer) } | ||
end | ||
|
||
context 'when exist not initialized field' do | ||
let!(:field) { create 'denormalization/field', state: ::Treasury::Fields::STATE_NEED_INITIALIZE } | ||
|
||
context 'when process not exist' do | ||
it { expect(supervisor).to receive(:run_initializer).with(field) } | ||
end | ||
|
||
context 'when initialize process exist' do | ||
before { allow(supervisor).to receive(:process_is_alive?).with(field.pid).and_return(true) } | ||
|
||
it { expect(supervisor).to receive(:run_initializer).with(field) } | ||
end | ||
end | ||
|
||
context 'when some field in initialize' do | ||
let!(:field) { create 'denormalization/field', state: ::Treasury::Fields::STATE_IN_INITIALIZE } | ||
|
||
context 'when process not exist' do | ||
it { expect(supervisor).to receive(:run_initializer).with(field) } | ||
end | ||
|
||
context 'when initialize process exist' do | ||
before { allow(supervisor).to receive(:process_is_alive?).with(field.pid).and_return(true) } | ||
|
||
it { expect(supervisor).to_not receive(:run_initializer) } | ||
end | ||
end | ||
end | ||
end |