#!/usr/bin/env ruby -w # encoding: UTF-8 # # = ruby-signal-bug.rb -- The TaskJuggler III Project Management Software # # Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011 # by Chris Schlaeger # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # require 'BatchProcessor' def test_fileIO # First parameter should be larger than the number of CPU cores. doRun(3, 2000) do fname = "test#{$$}.txt" f = File.new(fname, 'w') 0.upto(10000) do |i| f.puts "#{i} Hello, world! " end f.close File.delete(fname) # Allow some time for the OS to recycle file descriptors. sleep(0.05) end end def doRun(maxCPUs, jobs, &block) # Create a BatchProcessor bp = TaskJuggler::BatchProcessor.new(maxCPUs) # Queue jobs jobs.times do |i| bp.queue("job #{i}") { yield } end ok = error = 0 # Wait for them to finish bp.wait do |j| if j.retVal.signaled? error += 1 else ok += 1 end end puts "Ok: #{ok} Errors: #{error}" end test_fileIO