/
test_base.rb
81 lines (69 loc) · 2.12 KB
/
test_base.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require "rubygems"
require "bundler/setup"
gem 'test-unit'
require 'test/unit'
require 'yaml'
begin
require File.join(File.dirname(__FILE__), '../lib/iron_worker')
rescue Exception => ex
puts "Could NOT load current iron_worker: " + ex.message
raise ex
end
IronWorker.logger.level = Logger::DEBUG
IronWorker.service=nil
IronWorker.config.merged_gems={}
require_relative "iw_test_worker"
require_relative "iw_test_worker_2"
require_relative "iw_test_worker_3"
class TestBase < Test::Unit::TestCase
def setup
if defined? $abt_config
@config = $abt_config
else
@config =YAML::load_file(File.expand_path(File.join("~", "Dropbox", "configs", "iron_worker_ruby", "test", "config.yml")))
end
# @config = YAML::load_file(File.join(File.dirname(__FILE__), "config.yml"))
puts "config: " + @config.inspect
@token = @config['iron_worker']['token']
@project_id = @config['iron_worker']['project_id']
# new style
IronWorker.configure do |config|
config.token = @token
config.project_id = @project_id
config.host = @config['iron_worker']['host'] if @config['iron_worker']['host']
config.port = @config['iron_worker']['port'] if @config['iron_worker']['port']
config.scheme = @config['iron_worker']['scheme'] if @config['iron_worker']['scheme']
config.global_attributes["db_user"] = "sa"
config.global_attributes["db_pass"] = "pass"
config.database = @config["database"]
config.force_upload = true
# config.skip_auto_dependencies = true
end
end
def puts_log(worker)
puts "LOG START:"
puts worker.get_log
puts ":LOG END"
end
def wait_for_task(params={})
tries = 0
status = nil
sleep 1
while tries < 60
status = status_for(params)
puts "status: #{status['status']} -- " + status.inspect
if status["status"] == "complete" || status["status"] == "error"
break
end
sleep 2
end
status
end
def status_for(ob)
if ob.is_a?(Hash)
ob[:schedule_id] ? WORKER.schedule_status(ob[:schedule_id]) : WORKER.status(ob[:task_id])
else
ob.status
end
end
end