aruba 0.10.2 → 0.11.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +6 -5
- data/Gemfile +0 -4
- data/History.md +17 -1
- data/features/api/command/run.feature +101 -1
- data/features/api/command/send_signal.feature +53 -0
- data/features/api/command/stop.feature +79 -0
- data/features/api/text/replace_variables.feature +45 -0
- data/features/configuration/startup_wait_time.feature +48 -0
- data/features/step_definitions/hooks.rb +85 -6
- data/features/steps/{commands → command}/exit_statuses.feature +0 -0
- data/features/steps/{commands → command}/in_process.feature +174 -0
- data/features/steps/{commands → command}/run.feature +1 -0
- data/features/steps/command/send_signal.feature +104 -0
- data/features/steps/command/stop.feature +313 -0
- data/features/steps/overview.feature +60 -0
- data/lib/aruba/announcer.rb +2 -0
- data/lib/aruba/api/command.rb +24 -9
- data/lib/aruba/api/text.rb +9 -0
- data/lib/aruba/command.rb +4 -1
- data/lib/aruba/config.rb +2 -0
- data/lib/aruba/cucumber/command.rb +75 -0
- data/lib/aruba/cucumber/core.rb +0 -24
- data/lib/aruba/cucumber/hooks.rb +10 -0
- data/lib/aruba/errors.rb +3 -0
- data/lib/aruba/matchers/command/have_output.rb +1 -1
- data/lib/aruba/process_monitor.rb +25 -1
- data/lib/aruba/processes/basic_process.rb +22 -2
- data/lib/aruba/processes/debug_process.rb +7 -1
- data/lib/aruba/processes/in_process.rb +15 -1
- data/lib/aruba/processes/null_process.rb +26 -0
- data/lib/aruba/processes/spawn_process.rb +81 -48
- data/lib/aruba/rspec.rb +6 -0
- data/lib/aruba/version.rb +1 -1
- metadata +26 -11
@@ -2,7 +2,13 @@ require 'aruba/processes/spawn_process'
|
|
2
2
|
|
3
3
|
module Aruba
|
4
4
|
module Processes
|
5
|
-
#
|
5
|
+
# Run your command in `systemd()` to make debugging it easier
|
6
|
+
#
|
7
|
+
# `DebugProcess` is not meant for direct use - `InProcess.new` - by
|
8
|
+
# users. Only it's public methods are part of the public API of aruba, e.g.
|
9
|
+
# `#stdin`, `#stdout`.
|
10
|
+
#
|
11
|
+
# @private
|
6
12
|
class DebugProcess < BasicProcess
|
7
13
|
# Use only if mode is :debug
|
8
14
|
def self.match?(mode)
|
@@ -5,6 +5,13 @@ require 'aruba/platform'
|
|
5
5
|
|
6
6
|
module Aruba
|
7
7
|
module Processes
|
8
|
+
# Run command in your ruby process
|
9
|
+
#
|
10
|
+
# `InProcess` is not meant for direct use - `InProcess.new` - by
|
11
|
+
# users. Only it's public methods are part of the public API of aruba, e.g.
|
12
|
+
# `#stdin`, `#stdout`.
|
13
|
+
#
|
14
|
+
# @private
|
8
15
|
class InProcess < BasicProcess
|
9
16
|
# Use only if mode is in_process
|
10
17
|
def self.match?(mode)
|
@@ -33,7 +40,7 @@ module Aruba
|
|
33
40
|
# @private
|
34
41
|
attr_reader :main_class
|
35
42
|
|
36
|
-
def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil)
|
43
|
+
def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0)
|
37
44
|
@cmd = cmd
|
38
45
|
@argv = arguments
|
39
46
|
@stdin = StringIO.new
|
@@ -90,6 +97,13 @@ module Aruba
|
|
90
97
|
def terminate
|
91
98
|
stop
|
92
99
|
end
|
100
|
+
|
101
|
+
# Output pid of process
|
102
|
+
#
|
103
|
+
# This is the PID of the ruby process! So be careful
|
104
|
+
def pid
|
105
|
+
$PROCESS_ID
|
106
|
+
end
|
93
107
|
end
|
94
108
|
end
|
95
109
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'aruba/processes/basic_process'
|
2
|
+
|
3
|
+
module Aruba
|
4
|
+
module Processes
|
5
|
+
# Null Process
|
6
|
+
#
|
7
|
+
# `NullProcess` is not meant for direct use - `BasicProcess.new` - by users.
|
8
|
+
#
|
9
|
+
# @private
|
10
|
+
class NullProcess < BasicProcess
|
11
|
+
def self.match?(mode)
|
12
|
+
mode == :null
|
13
|
+
end
|
14
|
+
|
15
|
+
# Pid
|
16
|
+
def pid
|
17
|
+
0
|
18
|
+
end
|
19
|
+
|
20
|
+
# String representation
|
21
|
+
def to_s
|
22
|
+
''
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -8,6 +8,13 @@ require 'aruba/platform'
|
|
8
8
|
|
9
9
|
module Aruba
|
10
10
|
module Processes
|
11
|
+
# Spawn a process for command
|
12
|
+
#
|
13
|
+
# `SpawnProcess` is not meant for direct use - `SpawnProcess.new` - by
|
14
|
+
# users. Only it's public methods are part of the public API of aruba, e.g.
|
15
|
+
# `#stdin`, `#stdout`.
|
16
|
+
#
|
17
|
+
# @private
|
11
18
|
class SpawnProcess < BasicProcess
|
12
19
|
# Use as default launcher
|
13
20
|
def self.match?(mode)
|
@@ -27,12 +34,12 @@ module Aruba
|
|
27
34
|
#
|
28
35
|
# @params [String] working_directory
|
29
36
|
# The directory where the command will be executed
|
30
|
-
def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil)
|
37
|
+
def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0)
|
31
38
|
super
|
32
39
|
|
33
40
|
@process = nil
|
34
|
-
@stdout_cache
|
35
|
-
@stderr_cache
|
41
|
+
@stdout_cache = nil
|
42
|
+
@stderr_cache = nil
|
36
43
|
end
|
37
44
|
|
38
45
|
# Run the command
|
@@ -53,8 +60,8 @@ module Aruba
|
|
53
60
|
cmd = Aruba.platform.command_string.new(cmd)
|
54
61
|
|
55
62
|
@process = ChildProcess.build(*[cmd.to_a, arguments].flatten)
|
56
|
-
@stdout_file = Tempfile.new(
|
57
|
-
@stderr_file = Tempfile.new(
|
63
|
+
@stdout_file = Tempfile.new('aruba-stdout-')
|
64
|
+
@stderr_file = Tempfile.new('aruba-stderr-')
|
58
65
|
|
59
66
|
@stdout_file.sync = true
|
60
67
|
@stderr_file.sync = true
|
@@ -75,6 +82,7 @@ module Aruba
|
|
75
82
|
begin
|
76
83
|
Aruba.platform.with_environment(environment) do
|
77
84
|
@process.start
|
85
|
+
sleep startup_wait_time
|
78
86
|
end
|
79
87
|
rescue ChildProcess::LaunchError => e
|
80
88
|
raise LaunchError, "It tried to start #{cmd}. " + e.message
|
@@ -89,7 +97,7 @@ module Aruba
|
|
89
97
|
|
90
98
|
# Access to stdout of process
|
91
99
|
def stdin
|
92
|
-
return if @process.
|
100
|
+
return if @process.exited?
|
93
101
|
|
94
102
|
@process.io.stdin
|
95
103
|
end
|
@@ -105,11 +113,9 @@ module Aruba
|
|
105
113
|
# @return [String]
|
106
114
|
# The content of stdout
|
107
115
|
def stdout(opts = {})
|
108
|
-
return @stdout_cache if
|
116
|
+
return @stdout_cache if stopped?
|
109
117
|
|
110
|
-
wait_for_io
|
111
|
-
|
112
|
-
wait_for_io wait_for_io do
|
118
|
+
wait_for_io opts.fetch(:wait_for_io, @io_wait) do
|
113
119
|
@process.io.stdout.flush
|
114
120
|
open(@stdout_file.path).read
|
115
121
|
end
|
@@ -126,11 +132,9 @@ module Aruba
|
|
126
132
|
# @return [String]
|
127
133
|
# The content of stderr
|
128
134
|
def stderr(opts = {})
|
129
|
-
return @stderr_cache if
|
130
|
-
|
131
|
-
wait_for_io = opts.fetch(:wait_for_io, @io_wait)
|
135
|
+
return @stderr_cache if stopped?
|
132
136
|
|
133
|
-
wait_for_io wait_for_io do
|
137
|
+
wait_for_io opts.fetch(:wait_for_io, @io_wait) do
|
134
138
|
@process.io.stderr.flush
|
135
139
|
open(@stderr_file.path).read
|
136
140
|
end
|
@@ -145,7 +149,7 @@ module Aruba
|
|
145
149
|
end
|
146
150
|
|
147
151
|
def write(input)
|
148
|
-
return if
|
152
|
+
return if stopped?
|
149
153
|
|
150
154
|
@process.io.stdin.write(input)
|
151
155
|
@process.io.stdin.flush
|
@@ -154,7 +158,7 @@ module Aruba
|
|
154
158
|
end
|
155
159
|
|
156
160
|
def close_io(name)
|
157
|
-
return if
|
161
|
+
return if stopped?
|
158
162
|
|
159
163
|
if RUBY_VERSION < '1.9'
|
160
164
|
@process.io.send(name.to_sym).close
|
@@ -163,64 +167,93 @@ module Aruba
|
|
163
167
|
end
|
164
168
|
end
|
165
169
|
|
170
|
+
# rubocop:disable Metrics/MethodLength
|
166
171
|
def stop(reader)
|
167
|
-
@
|
168
|
-
|
169
|
-
return @exit_status unless @process
|
172
|
+
return @exit_status if stopped?
|
170
173
|
|
171
174
|
begin
|
172
|
-
@process.poll_for_exit(@exit_timeout)
|
175
|
+
@process.poll_for_exit(@exit_timeout)
|
173
176
|
rescue ChildProcess::TimeoutError
|
174
177
|
@timed_out = true
|
175
|
-
@process.stop
|
176
178
|
end
|
177
179
|
|
178
|
-
|
179
|
-
@process = nil
|
180
|
-
|
181
|
-
close_and_cache_out
|
182
|
-
close_and_cache_err
|
180
|
+
terminate
|
183
181
|
|
184
182
|
if reader
|
185
|
-
reader.announce :stdout,
|
186
|
-
reader.announce :stderr,
|
183
|
+
reader.announce :stdout, @stdout_cache
|
184
|
+
reader.announce :stderr, @stderr_cache
|
187
185
|
end
|
188
186
|
|
189
187
|
@exit_status
|
190
188
|
end
|
189
|
+
# rubocop:enable Metrics/MethodLength
|
191
190
|
|
191
|
+
# Wait for command to finish
|
192
|
+
def wait
|
193
|
+
@process.wait
|
194
|
+
end
|
195
|
+
|
196
|
+
# Terminate command
|
192
197
|
def terminate
|
193
|
-
return
|
198
|
+
return @exit_status if stopped?
|
199
|
+
|
200
|
+
unless @process.exited?
|
201
|
+
if @stop_signal
|
202
|
+
# send stop signal ...
|
203
|
+
send_signal @stop_signal
|
204
|
+
# ... and set the exit status
|
205
|
+
wait
|
206
|
+
else
|
207
|
+
@process.stop
|
208
|
+
end
|
209
|
+
end
|
194
210
|
|
195
|
-
@process.
|
196
|
-
stop nil
|
197
|
-
end
|
211
|
+
@exit_status = @process.exit_code
|
198
212
|
|
199
|
-
|
213
|
+
@stdout_cache = read_temporary_output_file @stdout_file
|
214
|
+
@stderr_cache = read_temporary_output_file @stderr_file
|
200
215
|
|
201
|
-
|
202
|
-
|
216
|
+
# @stdout_file = nil
|
217
|
+
# @stderr_file = nil
|
203
218
|
|
204
|
-
|
219
|
+
@stopped = true
|
205
220
|
|
206
|
-
|
221
|
+
@exit_status
|
207
222
|
end
|
208
223
|
|
209
|
-
|
210
|
-
|
211
|
-
|
224
|
+
# Output pid of process
|
225
|
+
#
|
226
|
+
# This is the PID of the spawned process.
|
227
|
+
def pid
|
228
|
+
@process.pid
|
212
229
|
end
|
213
230
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
231
|
+
# Send command a signal
|
232
|
+
#
|
233
|
+
# @param [String] signal
|
234
|
+
# The signal, i.e. 'TERM'
|
235
|
+
def send_signal(signal)
|
236
|
+
fail CommandAlreadyStoppedError, %(Command "#{commandline}" with PID "#{pid}" has already stopped.) if @process.exited?
|
237
|
+
|
238
|
+
Process.kill signal, pid
|
239
|
+
rescue Errno::ESRCH
|
240
|
+
raise CommandAlreadyStoppedError, %(Command "#{commandline}" with PID "#{pid}" has already stopped.)
|
218
241
|
end
|
219
242
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
243
|
+
private
|
244
|
+
|
245
|
+
def wait_for_io(time_to_wait, &block)
|
246
|
+
sleep time_to_wait.to_i
|
247
|
+
block.call
|
248
|
+
end
|
249
|
+
|
250
|
+
def read_temporary_output_file(file)
|
251
|
+
file.flush
|
252
|
+
file.rewind
|
253
|
+
data = file.read
|
254
|
+
file.close
|
255
|
+
|
256
|
+
data
|
224
257
|
end
|
225
258
|
end
|
226
259
|
end
|
data/lib/aruba/rspec.rb
CHANGED
@@ -53,6 +53,9 @@ RSpec.configure do |config|
|
|
53
53
|
announcer.activate(:directory) if example.metadata[:announce_directory]
|
54
54
|
announcer.activate(:stdout) if example.metadata[:announce_stdout]
|
55
55
|
announcer.activate(:stderr) if example.metadata[:announce_stderr]
|
56
|
+
announcer.activate(:timeout) if example.metadata[:announce_timeout]
|
57
|
+
announcer.activate(:wait_time) if example.metadata[:announce_wait_time]
|
58
|
+
announcer.activate(:stop_signal) if example.metadata[:announce_stop_signal]
|
56
59
|
|
57
60
|
if example.metadata[:announce_output]
|
58
61
|
announcer.activate(:stderr)
|
@@ -67,6 +70,9 @@ RSpec.configure do |config|
|
|
67
70
|
announcer.activate(:full_environment)
|
68
71
|
announcer.activate(:command)
|
69
72
|
announcer.activate(:directory)
|
73
|
+
announcer.activate(:stop_signal)
|
74
|
+
announcer.activate(:timeout)
|
75
|
+
announcer.activate(:wait_time)
|
70
76
|
end
|
71
77
|
end
|
72
78
|
|
data/lib/aruba/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aruba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aslak Hellesøy
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2015-11-
|
16
|
+
date: 2015-11-25 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: cucumber
|
@@ -144,6 +144,8 @@ files:
|
|
144
144
|
- features/.nav
|
145
145
|
- features/announce.feature
|
146
146
|
- features/api/command/run.feature
|
147
|
+
- features/api/command/send_signal.feature
|
148
|
+
- features/api/command/stop.feature
|
147
149
|
- features/api/command/stop_all_commands.feature
|
148
150
|
- features/api/command/terminate_all_commands.feature
|
149
151
|
- features/api/command/which.feature
|
@@ -162,6 +164,7 @@ files:
|
|
162
164
|
- features/api/filesystem/is_relative.feature
|
163
165
|
- features/api/filesystem/move.feature
|
164
166
|
- features/api/text/extract_text.feature
|
167
|
+
- features/api/text/replace_variables.feature
|
165
168
|
- features/api/text/sanitize_text.feature
|
166
169
|
- features/api/text/unescape_text.feature
|
167
170
|
- features/cli/console.feature
|
@@ -183,6 +186,7 @@ files:
|
|
183
186
|
- features/configuration/physical_block_size.feature
|
184
187
|
- features/configuration/remove_ansi_escape_sequences.feature
|
185
188
|
- features/configuration/root_directory.feature
|
189
|
+
- features/configuration/startup_wait_time.feature
|
186
190
|
- features/configuration/usage.feature
|
187
191
|
- features/configuration/working_directory.feature
|
188
192
|
- features/core/cleanup_aruba_directory.feature
|
@@ -206,9 +210,11 @@ files:
|
|
206
210
|
- features/output.feature
|
207
211
|
- features/step_definitions/aruba_dev_steps.rb
|
208
212
|
- features/step_definitions/hooks.rb
|
209
|
-
- features/steps/
|
210
|
-
- features/steps/
|
211
|
-
- features/steps/
|
213
|
+
- features/steps/command/exit_statuses.feature
|
214
|
+
- features/steps/command/in_process.feature
|
215
|
+
- features/steps/command/run.feature
|
216
|
+
- features/steps/command/send_signal.feature
|
217
|
+
- features/steps/command/stop.feature
|
212
218
|
- features/steps/environment/home_variable.feature
|
213
219
|
- features/steps/environment/set_environment_variable.feature
|
214
220
|
- features/steps/filesystem/copy.feature
|
@@ -218,6 +224,7 @@ files:
|
|
218
224
|
- features/steps/filesystem/move.feature
|
219
225
|
- features/steps/filesystem/overwrite_file.feature
|
220
226
|
- features/steps/filesystem/use_fixture.feature
|
227
|
+
- features/steps/overview.feature
|
221
228
|
- features/support/aruba.rb
|
222
229
|
- features/support/env.rb
|
223
230
|
- features/support/jruby.rb
|
@@ -345,6 +352,7 @@ files:
|
|
345
352
|
- lib/aruba/processes/basic_process.rb
|
346
353
|
- lib/aruba/processes/debug_process.rb
|
347
354
|
- lib/aruba/processes/in_process.rb
|
355
|
+
- lib/aruba/processes/null_process.rb
|
348
356
|
- lib/aruba/processes/spawn_process.rb
|
349
357
|
- lib/aruba/reporting.rb
|
350
358
|
- lib/aruba/rspec.rb
|
@@ -424,18 +432,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
424
432
|
version: 1.8.7
|
425
433
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
426
434
|
requirements:
|
427
|
-
- - "
|
435
|
+
- - ">"
|
428
436
|
- !ruby/object:Gem::Version
|
429
|
-
version:
|
437
|
+
version: 1.3.1
|
430
438
|
requirements: []
|
431
439
|
rubyforge_project:
|
432
440
|
rubygems_version: 2.4.5.1
|
433
441
|
signing_key:
|
434
442
|
specification_version: 4
|
435
|
-
summary: aruba-0.
|
443
|
+
summary: aruba-0.11.0.pre
|
436
444
|
test_files:
|
437
445
|
- features/announce.feature
|
438
446
|
- features/api/command/run.feature
|
447
|
+
- features/api/command/send_signal.feature
|
448
|
+
- features/api/command/stop.feature
|
439
449
|
- features/api/command/stop_all_commands.feature
|
440
450
|
- features/api/command/terminate_all_commands.feature
|
441
451
|
- features/api/command/which.feature
|
@@ -454,6 +464,7 @@ test_files:
|
|
454
464
|
- features/api/filesystem/is_relative.feature
|
455
465
|
- features/api/filesystem/move.feature
|
456
466
|
- features/api/text/extract_text.feature
|
467
|
+
- features/api/text/replace_variables.feature
|
457
468
|
- features/api/text/sanitize_text.feature
|
458
469
|
- features/api/text/unescape_text.feature
|
459
470
|
- features/cli/console.feature
|
@@ -475,6 +486,7 @@ test_files:
|
|
475
486
|
- features/configuration/physical_block_size.feature
|
476
487
|
- features/configuration/remove_ansi_escape_sequences.feature
|
477
488
|
- features/configuration/root_directory.feature
|
489
|
+
- features/configuration/startup_wait_time.feature
|
478
490
|
- features/configuration/usage.feature
|
479
491
|
- features/configuration/working_directory.feature
|
480
492
|
- features/core/cleanup_aruba_directory.feature
|
@@ -498,9 +510,11 @@ test_files:
|
|
498
510
|
- features/output.feature
|
499
511
|
- features/step_definitions/aruba_dev_steps.rb
|
500
512
|
- features/step_definitions/hooks.rb
|
501
|
-
- features/steps/
|
502
|
-
- features/steps/
|
503
|
-
- features/steps/
|
513
|
+
- features/steps/command/exit_statuses.feature
|
514
|
+
- features/steps/command/in_process.feature
|
515
|
+
- features/steps/command/run.feature
|
516
|
+
- features/steps/command/send_signal.feature
|
517
|
+
- features/steps/command/stop.feature
|
504
518
|
- features/steps/environment/home_variable.feature
|
505
519
|
- features/steps/environment/set_environment_variable.feature
|
506
520
|
- features/steps/filesystem/copy.feature
|
@@ -510,6 +524,7 @@ test_files:
|
|
510
524
|
- features/steps/filesystem/move.feature
|
511
525
|
- features/steps/filesystem/overwrite_file.feature
|
512
526
|
- features/steps/filesystem/use_fixture.feature
|
527
|
+
- features/steps/overview.feature
|
513
528
|
- features/support/aruba.rb
|
514
529
|
- features/support/env.rb
|
515
530
|
- features/support/jruby.rb
|