Sha256: d2ae4e7bd97ccf66303dcc33946f74601b4cb8e8b937d7622aada348d4aa2bd6
Contents?: true
Size: 1.68 KB
Versions: 2
Compression:
Stored size: 1.68 KB
Contents
module TestQueue class Iterator attr_reader :stats, :sock 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 def each fail "already used this iterator. previous caller: #@done" 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 key = suite.respond_to?(:id) ? suite.id : suite.to_s @stats[key] = Time.now - start else break end end rescue Errno::ENOENT, Errno::ECONNRESET, Errno::ECONNREFUSED ensure @done = caller.first File.open("/tmp/test_queue_worker_#{$$}_stats", "wb") do |f| f.write Marshal.dump(@stats) end end 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 include Enumerable def empty? false end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
test-queue-split-0.3.2 | lib/test_queue/iterator.rb |
test-queue-split-0.3.1 | lib/test_queue/iterator.rb |