<commit_before>#!/usr/bin/env ruby

require 'thread'
require 'optparse'
require 'optparse/time'
require 'ostruct'

class UserAcceptanceTest
  def initialize()  
    @lock = Mutex.new  # For thread safety  
    @options = parse(ARGV)
    @server = @options.server.split(/,\s*/)
    @port = @options.port
    @concurrent = @options.concurrent
    @results = {}
    @total_examples = 0
    @total_fail = 0
    @uats = Dir.glob("spec/uat/#{@options.tests}.rb")
  end  

  def run()
    @threads = []
    @server.each do |s|
      1 .. @concurrent.to_i.times do |c|
        t = Thread.new {
          log = File.new("uat.#{s}-#{c}.#{@port}.out", "w")
          $stderr = log # redirect stderr to log file
          while (path = nextUAT()) do
            cmd  = "spec #{path}"
            puts "Launching #{s}-#{c}:#{@port} => #{cmd}"
            $stdout.flush
            log.write "#{cmd}\n"
            output = `export SEL_RC_SERVER=#{s}; export RC_PORT=#{@port}; #{cmd} 2>&1`
            if (output.match(/(\d+) examples?, (\d+) failures?/))
              @lock.synchronize {
                @results[path] = { "examples" => $1.to_i,
                                   "failures" => $2.to_i }
                @total_examples += $1.to_i
                @total_fail += $2.to_i
              }
            end
            log.write(output)
            log.flush
          end
        }
        @threads.push(t)
      end
    end

    # wait for threads to finish
    @threads.each do |t|
      t.join<commit_msg>- Removed stderr redirection to log as it may be confusing hudson.<commit_after>#!/usr/bin/env ruby

require 'thread'
require 'optparse'
require 'optparse/time'
require 'ostruct'

class UserAcceptanceTest
  def initialize()  
    @lock = Mutex.new  # For thread safety  
    @options = parse(ARGV)
    @server = @options.server.split(/,\s*/)
    @port = @options.port
    @concurrent = @options.concurrent
    @results = {}
    @total_examples = 0
    @total_fail = 0
    @uats = Dir.glob("spec/uat/#{@options.tests}.rb")
  end  

  def run()
    @threads = []
    @server.each do |s|
      1 .. @concurrent.to_i.times do |c|
        t = Thread.new {
          log = File.new("uat.#{s}-#{c}.#{@port}.out", "w")
          while (path = nextUAT()) do
            cmd  = "spec #{path}"
            puts "Launching #{s}-#{c}:#{@port} => #{cmd}"
            $stdout.flush
            log.write "#{cmd}\n"
            output = `export SEL_RC_SERVER=#{s}; export RC_PORT=#{@port}; #{cmd} 2>&1`
            if (output.match(/(\d+) examples?, (\d+) failures?/))
              @lock.synchronize {
                @results[path] = { "examples" => $1.to_i,
                                   "failures" => $2.to_i }
                @total_examples += $1.to_i
                @total_fail += $2.to_i
              }
            end
            log.write(output)
            log.flush
          end
        }
        @threads.push(t)
      end
    end

    # wait for threads to finish
    @threads.each do |t|
      t.join
{'fraction_non_alphanumeric': 0.15876698707325157, 'fraction_numerical': 0.005966191581040769, 'mean_word_length': 1.6874443455031167, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3202919', 'n_tokens_mistral': 1016, 'n_tokens_neox': 993, 'n_words': 221}