Sha256: 72431bd36a4e48d613615a5e1a9ffb2fea9f9de9377fde236488101f5321fd60
Contents?: true
Size: 1.51 KB
Versions: 4
Compression:
Stored size: 1.51 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' if @done while true client = connect_to_master('POP') 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? 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 def connect_to_master(cmd) sock = if @tcp_address TCPSocket.new(@tcp_address, @tcp_port) else UNIXSocket.new(@sock) end sock.puts(cmd) sock end include Enumerable def empty? false end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
test-queue-0.2.2 | lib/test_queue/iterator.rb |
test-queue-0.2.1 | lib/test_queue/iterator.rb |
test-queue-0.2.0 | lib/test_queue/iterator.rb |
test-queue-0.2.0.beta.1 | lib/test_queue/iterator.rb |