cukeforker 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module CukeForker
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -70,6 +70,28 @@ module CukeForker
70
70
  @finished.any? { |w| w.failed? }
71
71
  end
72
72
 
73
+ def eta
74
+ pending = @pending.size
75
+ finished = @finished.size
76
+ running = @running.size
77
+
78
+ remaining = pending + running
79
+
80
+ if finished == 0
81
+ result = [Time.now, remaining, finished]
82
+ fire :on_eta, *result
83
+ else
84
+ seconds_per_child = (Time.now - start_time) / finished.to_f
85
+ eta = Time.now + (seconds_per_child * remaining)
86
+
87
+ result = [eta, remaining, finished]
88
+
89
+ fire :on_eta, *result
90
+ end
91
+
92
+ result
93
+ end
94
+
73
95
  private
74
96
 
75
97
  def start(worker)
@@ -86,18 +108,6 @@ module CukeForker
86
108
  fire :on_worker_finished, worker
87
109
  end
88
110
 
89
- def eta
90
- return Time.now if @finished.empty?
91
-
92
- pending = @pending.size
93
- finished = @finished.size
94
-
95
- seconds_per_child = (Time.now - start_time) / finished
96
- eta = Time.now + (seconds_per_child * pending)
97
-
98
- fire :on_eta, eta, pending + size, finished
99
- end
100
-
101
111
  def fire(*args)
102
112
  changed
103
113
  notify_observers(*args)
@@ -113,5 +113,23 @@ module CukeForker
113
113
 
114
114
  queue.wait_until_finished
115
115
  end
116
+
117
+ it "estimates the time left" do
118
+ now = Time.now
119
+ seconds_per_child = 60
120
+
121
+ queue.stub :start_time => now
122
+ Time.stub :now => now + seconds_per_child
123
+
124
+ workers[0..2].each { |w| queue.add w }
125
+
126
+ workers[0].stub(:start => nil, :finished? => true)
127
+ workers[1].stub(:start => nil, :finished? => false)
128
+ workers[2].stub(:start => nil, :finished? => false)
129
+
130
+ queue.fill
131
+ queue.poll
132
+ queue.eta.should == [Time.now + seconds_per_child*2, 2, 1]
133
+ end
116
134
  end # WorkerQueue
117
135
  end # CukeForker
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jari Bakken