cukeforker 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cukeforker.rb +1 -0
- data/lib/cukeforker/abstract_listener.rb +3 -0
- data/lib/cukeforker/logging_listener.rb +4 -0
- data/lib/cukeforker/version.rb +1 -1
- data/lib/cukeforker/vnc_listener.rb +6 -2
- data/lib/cukeforker/worker.rb +11 -5
- data/lib/cukeforker/worker_queue.rb +5 -0
- data/spec/cukeforker/logging_listener_spec.rb +4 -0
- data/spec/cukeforker/vnc_listener_spec.rb +13 -6
- data/spec/cukeforker/worker_queue_spec.rb +11 -0
- data/spec/cukeforker/worker_spec.rb +5 -4
- metadata +2 -2
data/lib/cukeforker.rb
CHANGED
@@ -16,6 +16,10 @@ module CukeForker
|
|
16
16
|
log.info "[ worker #{worker.id.to_s.ljust 3} ] starting: #{worker.feature}"
|
17
17
|
end
|
18
18
|
|
19
|
+
def on_worker_forked(worker)
|
20
|
+
log.info "[ worker #{worker.id.to_s.ljust 3} ] forked : #{worker.feature}"
|
21
|
+
end
|
22
|
+
|
19
23
|
def on_worker_finished(worker)
|
20
24
|
log.info "[ worker #{worker.id.to_s.ljust 3} ] #{status_string(worker.failed?).ljust(8)}: #{worker.feature}"
|
21
25
|
end
|
data/lib/cukeforker/version.rb
CHANGED
@@ -5,12 +5,16 @@ module CukeForker
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def on_worker_starting(worker)
|
8
|
-
worker.vnc = @pool.get
|
8
|
+
worker.data.vnc = @pool.get
|
9
9
|
end
|
10
10
|
|
11
11
|
def on_worker_finished(worker)
|
12
12
|
@pool.release worker.vnc
|
13
|
-
worker.vnc = nil
|
13
|
+
worker.data.vnc = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def on_worker_forked(worker)
|
17
|
+
ENV['DISPLAY'] = worker.data.vnc.display
|
14
18
|
end
|
15
19
|
|
16
20
|
def on_run_finished(failed)
|
data/lib/cukeforker/worker.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
module CukeForker
|
2
2
|
class Worker
|
3
|
+
include Observable
|
4
|
+
|
3
5
|
class << self
|
4
6
|
attr_writer :id
|
5
7
|
def id; @id ||= -1; end
|
6
8
|
end
|
7
9
|
|
8
|
-
attr_reader :status, :feature, :pid, :format, :out, :id
|
9
|
-
attr_accessor :vnc
|
10
|
+
attr_reader :status, :feature, :pid, :format, :out, :id, :data
|
10
11
|
|
11
12
|
def initialize(feature, format, out, extra_args = [])
|
12
13
|
@feature = feature
|
13
14
|
@format = format
|
14
15
|
@extra_args = extra_args
|
15
16
|
@out = out
|
16
|
-
@status
|
17
|
+
@status = nil
|
18
|
+
@data = OpenStruct.new
|
17
19
|
|
18
20
|
@id = self.class.id += 1
|
19
21
|
end
|
@@ -30,7 +32,11 @@ module CukeForker
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def start
|
33
|
-
@pid = Process.fork {
|
35
|
+
@pid = Process.fork {
|
36
|
+
changed
|
37
|
+
notify_observers :on_worker_forked, self
|
38
|
+
execute_cucumber
|
39
|
+
}
|
34
40
|
end
|
35
41
|
|
36
42
|
def args
|
@@ -47,7 +53,7 @@ module CukeForker
|
|
47
53
|
#{feature}
|
48
54
|
#{status.inspect}
|
49
55
|
#{out}
|
50
|
-
#{
|
56
|
+
#{data}
|
51
57
|
]"
|
52
58
|
end
|
53
59
|
|
@@ -18,7 +18,9 @@ module CukeForker
|
|
18
18
|
listener.on_display_starting mock_display
|
19
19
|
listener.on_display_fetched mock_display
|
20
20
|
listener.on_worker_starting mock_worker
|
21
|
+
listener.on_worker_forked mock_worker
|
21
22
|
listener.on_worker_starting mock_worker2
|
23
|
+
listener.on_worker_forked mock_worker2
|
22
24
|
listener.on_eta Time.now, 10, 255
|
23
25
|
listener.on_worker_finished mock_worker
|
24
26
|
listener.on_worker_finished mock_worker2
|
@@ -34,7 +36,9 @@ I, [#{timestamp}] INFO -- : [ run ] starting
|
|
34
36
|
I, [#{timestamp}] INFO -- : [ display ] starting
|
35
37
|
I, [#{timestamp}] INFO -- : [ display :5 ] fetched
|
36
38
|
I, [#{timestamp}] INFO -- : [ worker 1 ] starting: foo/bar
|
39
|
+
I, [#{timestamp}] INFO -- : [ worker 1 ] forked : foo/bar
|
37
40
|
I, [#{timestamp}] INFO -- : [ worker 15 ] starting: foo/baz
|
41
|
+
I, [#{timestamp}] INFO -- : [ worker 15 ] forked : foo/baz
|
38
42
|
I, [#{timestamp}] INFO -- : [ eta 10/255] #{Time.now.strftime "%Y-%m-%d %H:%M:%S"}
|
39
43
|
I, [#{timestamp}] INFO -- : [ worker 1 ] passed : foo/bar
|
40
44
|
I, [#{timestamp}] INFO -- : [ worker 15 ] failed : foo/baz
|
@@ -2,14 +2,14 @@ require File.expand_path("../../spec_helper", __FILE__)
|
|
2
2
|
|
3
3
|
module CukeForker
|
4
4
|
describe VncListener do
|
5
|
-
let(:server) { mock(VncServer)
|
6
|
-
let(:pool) { mock(VncServerPool)
|
7
|
-
let(:worker) { mock(Worker)
|
8
|
-
let(:listener) { VncListener.new pool
|
5
|
+
let(:server) { mock(VncServer, :display => ":15") }
|
6
|
+
let(:pool) { mock(VncServerPool) }
|
7
|
+
let(:worker) { mock(Worker, :data => OpenStruct.new) }
|
8
|
+
let(:listener) { VncListener.new pool }
|
9
9
|
|
10
10
|
it "fetches a display from the pool and assings it to the worker" do
|
11
11
|
pool.should_receive(:get).and_return(server)
|
12
|
-
worker.should_receive(:vnc=).with server
|
12
|
+
worker.data.should_receive(:vnc=).with server
|
13
13
|
|
14
14
|
listener.on_worker_starting worker
|
15
15
|
end
|
@@ -17,7 +17,7 @@ module CukeForker
|
|
17
17
|
it "releases the display and removes it from the worker" do
|
18
18
|
worker.should_receive(:vnc).and_return server
|
19
19
|
pool.should_receive(:release).with server
|
20
|
-
worker.should_receive(:vnc=).with(nil)
|
20
|
+
worker.data.should_receive(:vnc=).with(nil)
|
21
21
|
|
22
22
|
listener.on_worker_finished worker
|
23
23
|
end
|
@@ -28,5 +28,12 @@ module CukeForker
|
|
28
28
|
listener.on_run_finished(true)
|
29
29
|
end
|
30
30
|
|
31
|
+
it "sets DISPLAY after the worker is forked" do
|
32
|
+
worker.data.should_receive(:vnc).and_return(server)
|
33
|
+
ENV.should_receive(:[]=).with("DISPLAY", ":15")
|
34
|
+
|
35
|
+
listener.on_worker_forked worker
|
36
|
+
end
|
37
|
+
|
31
38
|
end # VncListenerServer
|
32
39
|
end # CukeForker
|
@@ -67,6 +67,17 @@ module CukeForker
|
|
67
67
|
queue.poll
|
68
68
|
end
|
69
69
|
|
70
|
+
it "adds observers to pending workers" do
|
71
|
+
listener = AbstractListener.new
|
72
|
+
|
73
|
+
workers.each { |w|
|
74
|
+
w.should_receive(:add_observer).with(listener)
|
75
|
+
queue.add w
|
76
|
+
}
|
77
|
+
|
78
|
+
queue.add_observer listener
|
79
|
+
end
|
80
|
+
|
70
81
|
it "knows if any of the workers failed" do
|
71
82
|
workers.each { |w| queue.add w }
|
72
83
|
|
@@ -50,8 +50,11 @@ module CukeForker
|
|
50
50
|
worker.start
|
51
51
|
end
|
52
52
|
|
53
|
-
it "
|
54
|
-
|
53
|
+
it "fires an event after forking" do
|
54
|
+
mock_listener = mock(AbstractListener)
|
55
|
+
mock_listener.should_receive(:update).with(:on_worker_forked, worker)
|
56
|
+
|
57
|
+
worker.add_observer mock_listener
|
55
58
|
|
56
59
|
Process.should_receive(:fork).and_yield.and_return(1234)
|
57
60
|
$stdout.should_receive(:reopen).with("some/path/some_feature.stdout")
|
@@ -59,8 +62,6 @@ module CukeForker
|
|
59
62
|
Cucumber::Cli::Main.should_receive(:execute).and_return(false)
|
60
63
|
worker.should_receive(:exit).with(0)
|
61
64
|
|
62
|
-
ENV.should_receive(:[]=).with("DISPLAY", ":5")
|
63
|
-
|
64
65
|
worker.start
|
65
66
|
end
|
66
67
|
|