Class: TestQueue::Iterator
- Inherits:
-
Object
- Object
- TestQueue::Iterator
- Includes:
- Enumerable
- Defined in:
- lib/test_queue/iterator.rb
Instance Attribute Summary collapse
-
#sock ⇒ Object
readonly
Returns the value of attribute sock.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
- #connect_to_master(cmd) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(sock, suites, filter = nil) ⇒ Iterator
constructor
A new instance of Iterator.
Constructor Details
#initialize(sock, suites, filter = nil) ⇒ Iterator
Returns a new instance of Iterator.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/test_queue/iterator.rb', line 5 def initialize(sock, suites, filter=nil) @done = false @stats = {} @procline = $0 @sock = sock @suites = suites @filter = filter if @sock =~ /^(.+):(\d+)$/ @tcp_address = $1 @tcp_port = $2.to_i end end |
Instance Attribute Details
#sock ⇒ Object (readonly)
Returns the value of attribute sock.
3 4 5 |
# File 'lib/test_queue/iterator.rb', line 3 def sock @sock end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
3 4 5 |
# File 'lib/test_queue/iterator.rb', line 3 def stats @stats end |
Instance Method Details
#connect_to_master(cmd) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/test_queue/iterator.rb', line 53 def connect_to_master(cmd) sock = if @tcp_address TCPSocket.new(@tcp_address, @tcp_port) else UNIXSocket.new(@sock) end sock.puts(cmd) sock rescue Errno::EPIPE nil end |
#each ⇒ Object
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 |
# File 'lib/test_queue/iterator.rb', line 18 def each fail 'already used this iterator' if @done while true client = connect_to_master('POP') break if client.nil? r, w, e = IO.select([client], nil, [client], nil) break if !e.empty? if data = client.read(65536) client.close item = Marshal.load(data) break if item.nil? || item.empty? suite = @suites[item] $0 = "#{@procline} - #{suite.respond_to?(:description) ? suite.description : suite}" start = Time.now if @filter @filter.call(suite){ yield suite } else yield suite end @stats[suite.to_s] = Time.now - start else break end end rescue Errno::ENOENT, Errno::ECONNRESET, Errno::ECONNREFUSED ensure @done = true File.open("/tmp/test_queue_worker_#{$$}_stats", "wb") do |f| f.write Marshal.dump(@stats) end end |
#empty? ⇒ Boolean
68 69 70 |
# File 'lib/test_queue/iterator.rb', line 68 def empty? false end |