<commit_before>#!/usr/bin/ruby
#
# Test frame work for rq - tests submitting jobs to a queue,
# and the handling of them. Does not test NFS (yet).
#
# Copyright (C) 2011 <NAME> <<EMAIL>> 

require 'yaml'

print "rq integration test suite by <NAME> 2011\n"

src = File.join('..',File.dirname(__FILE__))
$rq = File.join(src,'bin','rq');
raise "Run from test folder!" if !File.executable?($rq)
$queue = './test_queue'

def rq_exec(args)
  cmd = $rq + ' ' + $queue + ' ' + args
  print cmd
  system(cmd)
end

def rq_status()
  cmd = $rq + ' ' + $queue + ' status'
  YAML.load(`#{cmd}`)
end

def error(line, msg)
  p rq_status()
  rq_exec('shutdown')
  print `rm -rf #{$queue}`
  $stderr.print(__FILE__," ",line,": ",msg)
  exit 1
end

def test_equal(line,s1,s2) 
  error(line,"#{s1} does not equal #{s2}") if s1 != s2
end

def kill_rq()
  pstab = `ps xau|grep rq`
  pstab.grep(/#{$rq}/) do | s |
    error(__LINE__,"Still running "+s)
  end
  pstab.grep(/rq_jobrunnerdaemon/) do | s |
    error(__LINE__,"Still running "+s)
  end
end


# Check dependencies
print "Running tests...\n"

# $:.unshift '/var/lib/gems/1.8/gems/sqlite-ruby-2.2.3/lib/'
# test_equal(__LINE__,SQLite::Version::STRING,"2.2.3")

gempath = '/var/lib/gems/1.8/gems/sqlite-1.3.1/lib'
error("Expect "+gempath) if !File.directory?(gempath)
$:.unshift gempath
require 'sqlite'

kill_rq()

# In the first step we set up the queue
print `rm -rf #{$queue}`
rq_exec("create")
p rq_status()

# get status
status = rq_status()
test_equal(__LINE__,status["exit_status"],{"failures"=>0, "ok"=>0, "successes"=>0})

# submit short job
rq_exec('submit "/bin/ls /etc"')

# first time is pending
test_equal(__LINE__,rq_status()['jobs']['pending'],1)

rq_exec('submit "/bin/ls /etc"')
p rq_status()
test_equal(__LINE__,rq_status()['jobs']['total'],2)

# fire up daemon
rq_exec("feed --daemon --log=rq.log --max_feed=1 --min_sleep 1 --max_sleep 1")
5
sleep(2)
test_equal(__LINE__,rq_status()['jobs']['total'],2)

# get status
status = rq_status()
p status
test_equal(__LINE__,status["jobs"]['total'],2)

# Now add longer jobs
rq_exec('submit "sleep 6"')
sleep(1)
status = rq_status()
test_equal(__LINE__,status['jobs']['pending']+status['jobs']['running'],1)
rq_exec('submit "sleep 6"')
p rq_status()
test_equal(__LINE__,rq_status()['jobs']['total'],4)

# Delete last job
rq_exec('delete 4')
sleep(2)
print "\n---\n"
print rq_exec('query state=pending')
p rq_status

# Kill rq
rq_exec('shutdown')
status = rq_status()
test_equal(__LINE__,status['jobs']['pending']+status['jobs']['running'],1)
sleep(2)
kill_rq()

print `rm -rf #{$queue}`

# Done!
print <<MSG

Congratulations, all tests passed!

This means rq accepts and executes jobs. Note, the tests 
are not exhaustive, but passing them is a good sign.

MSG


<commit_msg>Testing: timings for VM use<commit_after>#!/usr/bin/ruby
#
# Test frame work for rq - tests submitting jobs to a queue,
# and the handling of them. Does not test NFS (yet).
#
# Copyright (C) 2011 <NAME> <<EMAIL>> 

require 'yaml'

print "rq integration test suite by <NAME> 2011\n"

src = File.join('..',File.dirname(__FILE__))
$rq = File.join(src,'bin','rq');
raise "Run from test folder!" if !File.executable?($rq)
$queue = './test_queue'

def rq_exec(args)
  cmd = $rq + ' ' + $queue + ' ' + args
  print cmd
  system(cmd)
end

def rq_status()
  cmd = $rq + ' ' + $queue + ' status'
  YAML.load(`#{cmd}`)
end

def error(line, msg)
  p rq_status()
  rq_exec('shutdown')
  print `rm -rf #{$queue}`
  $stderr.print(__FILE__," ",line,": ",msg)
  exit 1
end

def test_equal(line,s1,s2) 
  error(line,"#{s1} does not equal #{s2}") if s1 != s2
end

def kill_rq()
  pstab = `ps xau|grep rq`
  pstab.grep(/#{$rq}/) do | s |
    error(__LINE__,"Still running "+s)
  end
  pstab.grep(/rq_jobrunnerdaemon/) do | s |
    error(__LINE__,"Still running "+s)
  end
end


# Check dependencies
print "Running tests...\n"

# $:.unshift '/var/lib/gems/1.8/gems/sqlite-ruby-2.2.3/lib/'
# test_equal(__LINE__,SQLite::Version::STRING,"2.2.3")

gempath = '/var/lib/gems/1.8/gems/sqlite-1.3.1/lib'
error("Expect "+gempath) if !File.directory?(gempath)
$:.unshift gempath
require 'sqlite'

kill_rq()

# In the first step we set up the queue
print `rm -rf #{$queue}`
rq_exec("create")
p rq_status()

# get status
status = rq_status()
test_equal(__LINE__,status["exit_status"],{"failures"=>0, "ok"=>0, "successes"=>0})

# submit short job
rq_exec('submit "/bin/ls /etc"')

# first time is pending
test_equal(__LINE__,rq_status()['jobs']['pending'],1)

rq_exec('submit "/bin/ls /etc"')
p rq_status()
test_equal(__LINE__,rq_status()['jobs']['total'],2)

# fire up daemon
rq_exec("feed --daemon --log=rq.log --max_feed=1 --min_sleep 1 --max_sleep 1")
5
sleep(2)
test_equal(__LINE__,rq_status()['jobs']['total'],2)

# get status
status = rq_status()
p status
test_equal(__LINE__,status["jobs"]['total'],2)

# Now add longer jobs
rq_exec('submit "sleep 15"')  # does not finish
sleep(1)
status = rq_status()
test_equal(__LINE__,status['jobs']['pending']+status['jobs']['running'],1)
rq_exec('submit "sleep 15"')   # will be removed
p rq_status()
test_equal(__LINE__,rq_status()['jobs']['total'],4)

# Delete last job
rq_exec('delete 4')
sleep(2)
print "\n---\n"
print rq_exec('query state=pending')
p rq_status

# Kill rq
rq_exec('shutdown')
status = rq_status()
test_equal(__LINE__,status['jobs']['pending']+status['jobs']['running'],1)
sleep(2)
kill_rq()

print `rm -rf #{$queue}`

# Done!
print <<MSG

Congratulations, all tests passed!

This means rq accepts and executes jobs. Note, the tests 
are not exhaustive, but passing them is a good sign.

MSG



{'fraction_non_alphanumeric': 0.18829198643583794, 'fraction_numerical': 0.017847581652686063, 'mean_word_length': 4.849686847599165, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '865926', 'n_tokens_mistral': 2233, 'n_tokens_neox': 2143, 'n_words': 542}