-
Notifications
You must be signed in to change notification settings - Fork 70
/
shell_spec.rb
97 lines (76 loc) · 3 KB
/
shell_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require 'rails_helper'
module Kuroko2::Command
describe Shell do
describe '#execute' do
subject { Shell.new(hostname: 'rspec', worker: worker).execute }
let(:job_definition) { create(:job_definition) }
let(:job_instance) { create(:job_instance, job_definition: job_definition) }
let(:token) { create(:token, job_instance: job_instance, job_definition: job_definition) }
let!(:execution) { create(:execution, shell: shell, context: { 'ENV' => { 'NAME' => "kuroko" } }, started_at: nil, finished_at: nil, token: token) }
let(:shell) { 'ruby -e "true"' }
context 'when available worker exists' do
let(:worker) { create(:worker) }
context 'successfully' do
let(:shell) { 'ruby -e "puts ENV[\'NAME\'] + \\"\\\x99\\""' }
it do
is_expected.to eq execution
expect(subject.started_at).not_to be_nil
expect(subject.finished_at).not_to be_nil
expect(subject).to be_success
end
end
context 'failure' do
let(:shell) { 'wrong_script' }
it do
is_expected.to eq execution
expect(subject.started_at).not_to be_nil
expect(subject.finished_at).not_to be_nil
expect(subject).not_to be_success
end
end
context 'with 4byte utf-8 charactor' do
let(:shell) { 'ruby -e "puts ENV[\'NAME\'] + \\"\xF0\x9F\x98\x81\\""' }
it do
is_expected.to eq execution
expect(subject.started_at).not_to be_nil
expect(subject.finished_at).not_to be_nil
expect(subject).to be_success
end
end
end
context 'when all workers are busy' do
let(:worker) { create(:worker, execution_id: execution.id) }
it 'skips execution' do
is_expected.to be_nil
execution.reload
expect(execution.started_at).to be_nil
end
end
context 'when all workers are suspended' do
let(:worker) { create(:worker, suspended: true) }
it 'skips execution' do
is_expected.to be_nil
execution.reload
expect(execution.started_at).to be_nil
end
end
describe 'memory expectancy calculation' do
let(:worker) { create(:worker) }
let(:memory_expectancy) { execution.job_definition.memory_expectancy }
context 'when memory consumption logs exist' do
before do
(1..10).each {|i| job_instance.create_memory_consumption_log!(value: i) }
end
it 'calculates memory expectancy of related job definition' do
expect { subject }.to change { memory_expectancy.reload.expected_value }
end
end
context 'when no memory consumption logs exist' do
it 'does not calculates memory expectancy of related job definition' do
expect { subject }.not_to change { memory_expectancy.reload.expected_value }
end
end
end
end
end
end