spec/cuboid/rpc/server/agent_spec.rb in cuboid-0.1.9.1 vs spec/cuboid/rpc/server/agent_spec.rb in cuboid-0.2
- old
+ new
@@ -8,11 +8,11 @@
Cuboid::Options.system.max_slots = slots
end
let(:instance_info_keys) { %w(token application pid url owner birthdate helpers now age) }
let(:slots) { 3 }
- let(:subject) { agent_spawn( application: "#{fixtures_path}/mock_app.rb" ) }
+ let(:subject) { agent_spawn( application: "#{fixtures_path}/mock_app.rb", daemonize: true ) }
describe '#alive?' do
it 'returns true' do
expect(subject.alive?).to eq(true)
end
@@ -21,21 +21,21 @@
describe '#preferred' do
context 'when the agent is a grid member' do
context 'and strategy is' do
context :horizontal do
it 'returns the URL of least burdened Agent' do
- agent_spawn( peer: subject.url ).spawn( strategy: :direct )
- agent_spawn( peer: subject.url ).spawn( strategy: :direct )
+ agent_spawn( peer: subject.url, daemonize: true ).spawn( strategy: :direct )
+ agent_spawn( peer: subject.url, daemonize: true ).spawn( strategy: :direct )
expect(subject.preferred( :horizontal )).to eq(subject.url)
end
end
context :vertical do
it 'returns the URL of most burdened Agent' do
- agent_spawn( peer: subject.url ).spawn( strategy: :direct )
- d = agent_spawn( peer: subject.url )
+ agent_spawn( peer: subject.url, daemonize: true ).spawn( strategy: :direct )
+ d = agent_spawn( peer: subject.url, daemonize: true )
d.spawn( strategy: :direct )
d.spawn( strategy: :direct )
expect(subject.preferred( :vertical )).to eq(d.url)
end
@@ -45,21 +45,21 @@
it 'returns the URL of this Agent'
end
context 'default' do
it 'returns the URL of least burdened Agent' do
- agent_spawn( peer: subject.url ).spawn( strategy: :direct )
- agent_spawn( peer: subject.url ).spawn( strategy: :direct )
+ agent_spawn( peer: subject.url, daemonize: true ).spawn( strategy: :direct )
+ agent_spawn( peer: subject.url, daemonize: true ).spawn( strategy: :direct )
expect(subject.preferred).to eq(subject.url)
end
end
context 'other' do
it 'returns :error_unknown_strategy' do
- agent_spawn( peer: subject.url ).spawn( strategy: :direct )
- agent_spawn( peer: subject.url ).spawn( strategy: :direct )
+ agent_spawn( peer: subject.url, daemonize: true ).spawn( strategy: :direct )
+ agent_spawn( peer: subject.url, daemonize: true ).spawn( strategy: :direct )
expect(subject.preferred( :blah )).to eq('error_unknown_strategy')
end
end
end
@@ -70,12 +70,12 @@
end
let(:slots) { 1 }
it 'returns nil' do
- agent_spawn( peer: subject.url ).spawn( strategy: :direct )
- agent_spawn( peer: subject.url ).spawn( strategy: :direct )
+ agent_spawn( peer: subject.url, daemonize: true ).spawn( strategy: :direct )
+ agent_spawn( peer: subject.url, daemonize: true ).spawn( strategy: :direct )
expect(subject.preferred).to be_nil
end
end
end
@@ -198,31 +198,34 @@
context :horizontal do
it 'provides Instances from the least burdened Agent' do
d1 = agent_spawn(
address: '127.0.0.1',
- application: "#{fixtures_path}/mock_app.rb"
+ application: "#{fixtures_path}/mock_app.rb",
+ daemonize: true
)
3.times do
d1.spawn( strategy: :direct )
end
d2 = agent_spawn(
address: '127.0.0.2',
peer: d1.url,
- application: "#{fixtures_path}/mock_app.rb"
+ application: "#{fixtures_path}/mock_app.rb",
+ daemonize: true
)
2.times do
d2.spawn( strategy: :direct )
end
d3 = agent_spawn(
address: '127.0.0.3',
peer: d1.url,
- application: "#{fixtures_path}/mock_app.rb"
+ application: "#{fixtures_path}/mock_app.rb",
+ daemonize: true
)
d3.spawn( strategy: :direct )
preferred = d3.url.split( ':' ).first
expect(d3.spawn(strategy: :horizontal )['url'].split( ':' ).first).to eq(preferred)
@@ -236,31 +239,34 @@
context :vertical do
it 'provides Instances from the most burdened Agent' do
d1 = agent_spawn(
address: '127.0.0.1',
- application: "#{fixtures_path}/mock_app.rb"
+ application: "#{fixtures_path}/mock_app.rb",
+ daemonize: true
)
3.times do
d1.spawn( strategy: :direct )
end
d2 = agent_spawn(
address: '127.0.0.2',
peer: d1.url,
- application: "#{fixtures_path}/mock_app.rb"
+ application: "#{fixtures_path}/mock_app.rb",
+ daemonize: true
)
2.times do
d2.spawn( strategy: :direct )
end
d3 = agent_spawn(
address: '127.0.0.3',
peer: d1.url,
- application: "#{fixtures_path}/mock_app.rb"
+ application: "#{fixtures_path}/mock_app.rb",
+ daemonize: true
)
d3.spawn( strategy: :direct )
preferred = d1.url.split( ':' ).first
expect(d3.spawn( strategy: :vertical )['url'].split( ':' ).first).to eq(preferred)
@@ -269,31 +275,34 @@
context 'default' do
it 'provides Instances from the least burdened Agent' do
d1 = agent_spawn(
address: '127.0.0.1',
- application: "#{fixtures_path}/mock_app.rb"
+ application: "#{fixtures_path}/mock_app.rb",
+ daemonize: true
)
3.times do
d1.spawn( strategy: :direct )
end
d2 = agent_spawn(
address: '127.0.0.2',
peer: d1.url,
- application: "#{fixtures_path}/mock_app.rb"
+ application: "#{fixtures_path}/mock_app.rb",
+ daemonize: true
)
2.times do
d2.spawn( strategy: :direct )
end
d3 = agent_spawn(
address: '127.0.0.3',
peer: d1.url,
- application: "#{fixtures_path}/mock_app.rb"
+ application: "#{fixtures_path}/mock_app.rb",
+ daemonize: true
)
d3.spawn( strategy: :direct )
preferred = d3.url.split( ':' ).first
expect(d3.spawn['url'].split( ':' ).first).to eq(preferred)
@@ -305,35 +314,38 @@
end
end
context 'other' do
it 'returns :error_unknown_strategy' do
- expect(agent_spawn( peer: subject.url ).
+ expect(agent_spawn( peer: subject.url, daemonize: true ).
spawn( strategy: 'blah' )).to eq('error_unknown_strategy')
end
end
end
context 'when the load-balance option is set to false' do
it 'returns an Instance from the requested Agent' do
d1 = agent_spawn(
address: '127.0.0.1',
- application: "#{fixtures_path}/mock_app.rb"
+ application: "#{fixtures_path}/mock_app.rb",
+ daemonize: true
)
d1.spawn( strategy: :direct )
d2 = agent_spawn(
address: '127.0.0.2',
peer: d1.url,
- application: "#{fixtures_path}/mock_app.rb"
+ application: "#{fixtures_path}/mock_app.rb",
+ daemonize: true
)
d2.spawn( strategy: :direct )
d3 = agent_spawn(
address: '127.0.0.3',
peer: d1.url,
- application: "#{fixtures_path}/mock_app.rb"
+ application: "#{fixtures_path}/mock_app.rb",
+ daemonize: true
)
2.times do
d3.spawn( strategy: :direct )
end