Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
Quick development deploy support.
Browse files Browse the repository at this point in the history
  • Loading branch information
joakimk committed Dec 4, 2010
1 parent 73cd8b9 commit 9677ce1
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.deploy_config.yml
*.db *.db
pkg pkg
todo.txt todo.txt
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,3 +1,7 @@
0.4.1

Added support for quicker and more automated updates when developing testbot.

0.4.0 0.4.0


Fixed RSpec 2 compability issue. Fixed RSpec 2 compability issue.
Expand Down
2 changes: 1 addition & 1 deletion README.markdown
Expand Up @@ -68,7 +68,7 @@ Using testbot with Rails 3:


Using testbot with Rails 2: Using testbot with Rails 2:


ruby script/plugin install git://github.com/joakimk/testbot.git -r 'refs/tags/v0.4.0' ruby script/plugin install git://github.com/joakimk/testbot.git -r 'refs/tags/v0.4.1'
script/generate testbot --connect 192.168.0.100 script/generate testbot --connect 192.168.0.100


rake testbot:spec (or :test, :features) rake testbot:spec (or :test, :features)
Expand Down
12 changes: 12 additions & 0 deletions Rakefile
Expand Up @@ -14,6 +14,18 @@ task :test do
Dir["test/**/test_*.rb"].each { |test| require(File.expand_path(test)) } Dir["test/**/test_*.rb"].each { |test| require(File.expand_path(test)) }
end end


desc "Used for quickly deploying and testing updates without pusing to rubygems.org"
task :deploy do
ENV['TESTBOT_DEV_DEPLOY'] = '1'

gem_file = "testbot-#{Testbot.version}.gem"
config = YAML.load_file(".deploy_config.yml")
Rake::Task["build"].invoke

system(config["upload_gem"].gsub(/GEM_FILE/, gem_file)) || fail
system(config["update_and_restart_server"].gsub(/GEM_FILE/, gem_file)) || fail
end

Cucumber::Rake::Task.new(:features) do |t| Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "features --format progress" t.cucumber_opts = "features --format progress"
end end
Expand Down
2 changes: 1 addition & 1 deletion bin/testbot
Expand Up @@ -3,7 +3,7 @@
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/testbot.rb')) require File.expand_path(File.join(File.dirname(__FILE__), '../lib/testbot.rb'))


def show_help def show_help
puts "Testbot #{Testbot::VERSION}" puts "Testbot #{Testbot.version}"
puts puts
puts "Testbot is a test distribution tool that works with Rails, RSpec, Test::Unit and Cucumber." puts "Testbot is a test distribution tool that works with Rails, RSpec, Test::Unit and Cucumber."
puts puts
Expand Down
12 changes: 8 additions & 4 deletions lib/runner.rb
Expand Up @@ -189,10 +189,14 @@ def time_for_update?


def check_for_update def check_for_update
return unless @config.auto_update return unless @config.auto_update
version = Server.get('/version') rescue Testbot::VERSION version = Server.get('/version') rescue Testbot.version
return unless version != Testbot::VERSION return unless version != Testbot.version


successful_install = system "gem install testbot -v #{version}" if version.include?(".DEV.")
successful_install = system "gem install #{@config.dev_gem_root}/testbot-#{version}.gem"
else
successful_install = system "gem install testbot -v #{version}"
end


if successful_install if successful_install
File.open("/tmp/update_testbot.sh", "w") { |file| file.write("#!/bin/sh\nsleep 5\ntestbot #{ARGV.join(' ')}") } File.open("/tmp/update_testbot.sh", "w") { |file| file.write("#!/bin/sh\nsleep 5\ntestbot #{ARGV.join(' ')}") }
Expand All @@ -208,7 +212,7 @@ def ping_params
end end


def base_params def base_params
{ :version => Testbot::VERSION, :uid => @uid } { :version => Testbot.version, :uid => @uid }
end end


def max_instances_running? def max_instances_running?
Expand Down
4 changes: 2 additions & 2 deletions lib/server.rb
Expand Up @@ -18,7 +18,7 @@


class Server class Server
def self.valid_version?(runner_version) def self.valid_version?(runner_version)
Testbot::VERSION == runner_version Testbot.version == runner_version
end end
end end


Expand Down Expand Up @@ -68,5 +68,5 @@ def self.valid_version?(runner_version)
end end


get '/version' do get '/version' do
Testbot::VERSION Testbot.version
end end
4 changes: 2 additions & 2 deletions lib/server/runner.rb
Expand Up @@ -19,11 +19,11 @@ def self.timeout
end end


def self.find_all_outdated def self.find_all_outdated
DB[:runners].filter("version != ? OR version IS NULL", Testbot::VERSION) DB[:runners].filter("version != ? OR version IS NULL", Testbot.version)
end end


def self.find_all_available def self.find_all_available
DB[:runners].filter("version = ? AND last_seen_at > ?", Testbot::VERSION, Time.now - Runner.timeout) DB[:runners].filter("version = ? AND last_seen_at > ?", Testbot.version, Time.now - Runner.timeout)
end end


def self.available_instances def self.available_instances
Expand Down
9 changes: 7 additions & 2 deletions lib/testbot.rb
Expand Up @@ -8,7 +8,11 @@ module Testbot
require 'railtie' if defined?(Rails) require 'railtie' if defined?(Rails)


# Don't forget to update readme and changelog # Don't forget to update readme and changelog
VERSION = "0.4.0" def self.version
version = "0.4.1"
version += ".DEV.#{Time.now.to_i}" if ENV['TESTBOT_DEV_DEPLOY']
version
end


if ENV['INTEGRATION_TEST'] if ENV['INTEGRATION_TEST']
SERVER_PID = "/tmp/integration_test_testbot_server.pid" SERVER_PID = "/tmp/integration_test_testbot_server.pid"
Expand All @@ -34,7 +38,7 @@ def self.run(argv)
if opts[:help] if opts[:help]
return false return false
elsif opts[:version] elsif opts[:version]
puts "Testbot #{Testbot::VERSION}" puts "Testbot #{Testbot.version}"
elsif [ true, 'run', 'start' ].include?(opts[:server]) elsif [ true, 'run', 'start' ].include?(opts[:server])
start_server(opts[:server]) start_server(opts[:server])
elsif opts[:server] == 'stop' elsif opts[:server] == 'stop'
Expand Down Expand Up @@ -81,6 +85,7 @@ def self.start_runner(opts)
:auto_update => opts[:auto_update], :max_instances => opts[:cpus], :auto_update => opts[:auto_update], :max_instances => opts[:cpus],
:ssh_tunnel => opts[:ssh_tunnel], :server_user => opts[:user], :ssh_tunnel => opts[:ssh_tunnel], :server_user => opts[:user],
:max_jruby_instances => opts[:max_jruby_instances], :max_jruby_instances => opts[:max_jruby_instances],
:dev_gem_root => opts[:dev_gem_root],
:jruby_opts => opts[:jruby_opts]) :jruby_opts => opts[:jruby_opts])
runner.run! runner.run!
} }
Expand Down
74 changes: 37 additions & 37 deletions test/test_server.rb
Expand Up @@ -102,7 +102,7 @@ def app
should "be able to return a job and mark it as taken" do should "be able to return a job and mark it as taken" do
job1 = Job.create :files => 'spec/models/car_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "bb:bb:bb:bb:bb:bb", :project => 'things', :jruby => 1 job1 = Job.create :files => 'spec/models/car_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "bb:bb:bb:bb:bb:bb", :project => 'things', :jruby => 1


get '/jobs/next', :version => Testbot::VERSION get '/jobs/next', :version => Testbot.version
assert last_response.ok? assert last_response.ok?


assert_equal [ job1[:id], "bb:bb:bb:bb:bb:bb", "things", "server:/project", "spec", "jruby", "spec/models/car_spec.rb" ].join(','), last_response.body assert_equal [ job1[:id], "bb:bb:bb:bb:bb:bb", "things", "server:/project", "spec", "jruby", "spec/models/car_spec.rb" ].join(','), last_response.body
Expand All @@ -112,28 +112,28 @@ def app
should "not return a job that has already been taken" do should "not return a job that has already been taken" do
job1 = Job.create :files => 'spec/models/car_spec.rb', :taken_at => Time.now, :type => 'spec' job1 = Job.create :files => 'spec/models/car_spec.rb', :taken_at => Time.now, :type => 'spec'
job2 = Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "aa:aa:aa:aa:aa:aa", :project => 'things', :jruby => 0 job2 = Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "aa:aa:aa:aa:aa:aa", :project => 'things', :jruby => 0
get '/jobs/next', :version => Testbot::VERSION get '/jobs/next', :version => Testbot.version
assert last_response.ok? assert last_response.ok?
assert_equal [ job2[:id], "aa:aa:aa:aa:aa:aa", "things", "server:/project", "spec", "ruby", "spec/models/house_spec.rb" ].join(','), last_response.body assert_equal [ job2[:id], "aa:aa:aa:aa:aa:aa", "things", "server:/project", "spec", "ruby", "spec/models/house_spec.rb" ].join(','), last_response.body
assert job2.reload[:taken_at] != nil assert job2.reload[:taken_at] != nil
end end


should "not return a job if there isnt any" do should "not return a job if there isnt any" do
get '/jobs/next', :version => Testbot::VERSION get '/jobs/next', :version => Testbot.version
assert last_response.ok? assert last_response.ok?
assert_equal '', last_response.body assert_equal '', last_response.body
end end


should "save which runner takes a job" do should "save which runner takes a job" do
job = Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "aa:aa:aa:aa:aa:aa" job = Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "aa:aa:aa:aa:aa:aa"
get '/jobs/next', :version => Testbot::VERSION get '/jobs/next', :version => Testbot.version
assert_equal Runner.first.id, job.reload.taken_by_id assert_equal Runner.first.id, job.reload.taken_by_id
end end


should "save information about the runners" do should "save information about the runners" do
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini.local', :uid => "00:01:...", :idle_instances => 2, :max_instances => 4 get '/jobs/next', :version => Testbot.version, :hostname => 'macmini.local', :uid => "00:01:...", :idle_instances => 2, :max_instances => 4
runner = DB[:runners].first runner = DB[:runners].first
assert_equal Testbot::VERSION, runner[:version] assert_equal Testbot.version, runner[:version]
assert_equal '127.0.0.1', runner[:ip] assert_equal '127.0.0.1', runner[:ip]
assert_equal 'macmini.local', runner[:hostname] assert_equal 'macmini.local', runner[:hostname]
assert_equal '00:01:...', runner[:uid] assert_equal '00:01:...', runner[:uid]
Expand All @@ -144,8 +144,8 @@ def app
end end


should "only create one record for the same mac" do should "only create one record for the same mac" do
get '/jobs/next', :version => Testbot::VERSION, :uid => "00:01:..." get '/jobs/next', :version => Testbot.version, :uid => "00:01:..."
get '/jobs/next', :version => Testbot::VERSION, :uid => "00:01:..." get '/jobs/next', :version => Testbot.version, :uid => "00:01:..."
assert_equal 1, Runner.count assert_equal 1, Runner.count
end end


Expand All @@ -158,35 +158,35 @@ def app


should "only give jobs from the same source to a runner" do should "only give jobs from the same source to a runner" do
job1 = Job.create :files => 'spec/models/car_spec.rb', :type => 'spec', :requester_mac => "bb:bb:bb:bb:bb:bb" job1 = Job.create :files => 'spec/models/car_spec.rb', :type => 'spec', :requester_mac => "bb:bb:bb:bb:bb:bb"
get '/jobs/next', :version => Testbot::VERSION, :uid => "00:..." get '/jobs/next', :version => Testbot.version, :uid => "00:..."


# Creating the second job here because of the random lookup. # Creating the second job here because of the random lookup.
job2 = Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "aa:aa:aa:aa:aa:aa" job2 = Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "aa:aa:aa:aa:aa:aa"
get '/jobs/next', :version => Testbot::VERSION, :uid => "00:...", :requester_mac => "bb:bb:bb:bb:bb:bb" get '/jobs/next', :version => Testbot.version, :uid => "00:...", :requester_mac => "bb:bb:bb:bb:bb:bb"


assert last_response.ok? assert last_response.ok?
assert_equal '', last_response.body assert_equal '', last_response.body
end end


should "not give more jruby jobs to an instance that can't take more" do should "not give more jruby jobs to an instance that can't take more" do
job1 = Job.create :files => 'spec/models/car_spec.rb', :type => 'spec', :requester_mac => "bb:bb:bb:bb:bb:bb", :jruby => 1 job1 = Job.create :files => 'spec/models/car_spec.rb', :type => 'spec', :requester_mac => "bb:bb:bb:bb:bb:bb", :jruby => 1
get '/jobs/next', :version => Testbot::VERSION, :uid => "00:..." get '/jobs/next', :version => Testbot.version, :uid => "00:..."


# Creating the second job here because of the random lookup. # Creating the second job here because of the random lookup.
job2 = Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :jruby => 1 job2 = Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :jruby => 1
get '/jobs/next', :version => Testbot::VERSION, :uid => "00:...", :no_jruby => "true" get '/jobs/next', :version => Testbot.version, :uid => "00:...", :no_jruby => "true"


assert last_response.ok? assert last_response.ok?
assert_equal '', last_response.body assert_equal '', last_response.body
end end


should "still return other jobs when the runner cant take more jruby jobs" do should "still return other jobs when the runner cant take more jruby jobs" do
job1 = Job.create :files => 'spec/models/car_spec.rb', :type => 'spec', :requester_mac => "bb:bb:bb:bb:bb:bb", :jruby => 1 job1 = Job.create :files => 'spec/models/car_spec.rb', :type => 'spec', :requester_mac => "bb:bb:bb:bb:bb:bb", :jruby => 1
get '/jobs/next', :version => Testbot::VERSION, :uid => "00:..." get '/jobs/next', :version => Testbot.version, :uid => "00:..."


# Creating the second job here because of the random lookup. # Creating the second job here because of the random lookup.
job2 = Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :jruby => 0 job2 = Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :jruby => 0
get '/jobs/next', :version => Testbot::VERSION, :uid => "00:...", :no_jruby => "true" get '/jobs/next', :version => Testbot.version, :uid => "00:...", :no_jruby => "true"


assert last_response.ok? assert last_response.ok?
assert_equal job2.id.to_s, last_response.body.split(',')[0] assert_equal job2.id.to_s, last_response.body.split(',')[0]
Expand All @@ -198,7 +198,7 @@ def app
20.times { Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "aa:aa:aa:aa:aa:aa" } 20.times { Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "aa:aa:aa:aa:aa:aa" }


macs = (0...10).map { macs = (0...10).map {
get '/jobs/next', :version => Testbot::VERSION, :uid => "00:..." get '/jobs/next', :version => Testbot.version, :uid => "00:..."
last_response.body.split(',')[1] last_response.body.split(',')[1]
} }


Expand All @@ -212,7 +212,7 @@ def app
20.times { Job.create :files => 'spec/models/car_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "bb:bb:bb:bb:bb:bb" } 20.times { Job.create :files => 'spec/models/car_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "bb:bb:bb:bb:bb:bb" }


files = (0...10).map { files = (0...10).map {
get '/jobs/next', :version => Testbot::VERSION, :uid => "00:...", :requester_mac => "bb:bb:bb:bb:bb:bb" get '/jobs/next', :version => Testbot.version, :uid => "00:...", :requester_mac => "bb:bb:bb:bb:bb:bb"
last_response.body.split(',').last last_response.body.split(',').last
} }


Expand All @@ -225,7 +225,7 @@ def app
old_taken_job = Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "aa:aa:aa:aa:aa:aa", :taken_by_id => missing_runner.id, :taken_at => Time.now - 30, :project => 'things' old_taken_job = Job.create :files => 'spec/models/house_spec.rb', :root => 'server:/project', :type => 'spec', :requester_mac => "aa:aa:aa:aa:aa:aa", :taken_by_id => missing_runner.id, :taken_at => Time.now - 30, :project => 'things'


new_runner = Runner.create(:uid => "00:01") new_runner = Runner.create(:uid => "00:01")
get '/jobs/next', :version => Testbot::VERSION, :uid => "00:01" get '/jobs/next', :version => Testbot.version, :uid => "00:01"
assert_equal new_runner.id, old_taken_job.reload.taken_by_id assert_equal new_runner.id, old_taken_job.reload.taken_by_id


assert last_response.ok? assert last_response.ok?
Expand All @@ -240,7 +240,7 @@ def app
get '/jobs/next', :version => "1", :hostname => 'macmini1.local', :uid => "00:01" get '/jobs/next', :version => "1", :hostname => 'macmini1.local', :uid => "00:01"
get '/jobs/next', :version => "1", :hostname => 'macmini2.local', :uid => "00:02" get '/jobs/next', :version => "1", :hostname => 'macmini2.local', :uid => "00:02"
get '/jobs/next' get '/jobs/next'
get '/jobs/next', :version => Testbot::VERSION.to_s, :hostname => 'macmini3.local', :uid => "00:03" get '/jobs/next', :version => Testbot.version.to_s, :hostname => 'macmini3.local', :uid => "00:03"
assert_equal 4, Runner.count assert_equal 4, Runner.count
get '/runners/outdated' get '/runners/outdated'
assert last_response.ok? assert last_response.ok?
Expand All @@ -252,16 +252,16 @@ def app
context "GET /runners/available_runners" do context "GET /runners/available_runners" do


should "return a list of available runners" do should "return a list of available runners" do
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini1.local', :uid => "00:01", :idle_instances => 2, :username => 'user1' get '/jobs/next', :version => Testbot.version, :hostname => 'macmini1.local', :uid => "00:01", :idle_instances => 2, :username => 'user1'
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini2.local', :uid => "00:02", :idle_instances => 4, :username => 'user2' get '/jobs/next', :version => Testbot.version, :hostname => 'macmini2.local', :uid => "00:02", :idle_instances => 4, :username => 'user2'
get '/runners/available' get '/runners/available'
assert last_response.ok? assert last_response.ok?
assert_equal "127.0.0.1 macmini1.local 00:01 user1 2\n127.0.0.1 macmini2.local 00:02 user2 4", last_response.body assert_equal "127.0.0.1 macmini1.local 00:01 user1 2\n127.0.0.1 macmini2.local 00:02 user2 4", last_response.body
end end


should "not return runners as available when not seen the last 10 seconds" do should "not return runners as available when not seen the last 10 seconds" do
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini1.local', :uid => "00:01", :idle_instances => 2, :username => "user1" get '/jobs/next', :version => Testbot.version, :hostname => 'macmini1.local', :uid => "00:01", :idle_instances => 2, :username => "user1"
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini2.local', :uid => "00:02", :idle_instances => 4 get '/jobs/next', :version => Testbot.version, :hostname => 'macmini2.local', :uid => "00:02", :idle_instances => 4
Runner.find(:uid => "00:02").update(:last_seen_at => Time.now - 10) Runner.find(:uid => "00:02").update(:last_seen_at => Time.now - 10)
get '/runners/available' get '/runners/available'
assert_equal "127.0.0.1 macmini1.local 00:01 user1 2", last_response.body assert_equal "127.0.0.1 macmini1.local 00:01 user1 2", last_response.body
Expand All @@ -272,16 +272,16 @@ def app
context "GET /runners/available_instances" do context "GET /runners/available_instances" do


should "return the number of available runner instances" do should "return the number of available runner instances" do
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini1.local', :uid => "00:01", :idle_instances => 2 get '/jobs/next', :version => Testbot.version, :hostname => 'macmini1.local', :uid => "00:01", :idle_instances => 2
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini2.local', :uid => "00:02", :idle_instances => 4 get '/jobs/next', :version => Testbot.version, :hostname => 'macmini2.local', :uid => "00:02", :idle_instances => 4
get '/runners/available_instances' get '/runners/available_instances'
assert last_response.ok? assert last_response.ok?
assert_equal "6", last_response.body assert_equal "6", last_response.body
end end


should "not return instances as available when not seen the last 10 seconds" do should "not return instances as available when not seen the last 10 seconds" do
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini1.local', :uid => "00:01", :idle_instances => 2 get '/jobs/next', :version => Testbot.version, :hostname => 'macmini1.local', :uid => "00:01", :idle_instances => 2
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini2.local', :uid => "00:02", :idle_instances => 4 get '/jobs/next', :version => Testbot.version, :hostname => 'macmini2.local', :uid => "00:02", :idle_instances => 4
Runner.find(:uid => "00:02").update(:last_seen_at => Time.now - 10) Runner.find(:uid => "00:02").update(:last_seen_at => Time.now - 10)
get '/runners/available_instances' get '/runners/available_instances'
assert last_response.ok? assert last_response.ok?
Expand All @@ -293,16 +293,16 @@ def app
context "GET /runners/total_instances" do context "GET /runners/total_instances" do


should "return the number of available runner instances" do should "return the number of available runner instances" do
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini1.local', :uid => "00:01", :max_instances => 2 get '/jobs/next', :version => Testbot.version, :hostname => 'macmini1.local', :uid => "00:01", :max_instances => 2
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini2.local', :uid => "00:02", :max_instances => 4 get '/jobs/next', :version => Testbot.version, :hostname => 'macmini2.local', :uid => "00:02", :max_instances => 4
get '/runners/total_instances' get '/runners/total_instances'
assert last_response.ok? assert last_response.ok?
assert_equal "6", last_response.body assert_equal "6", last_response.body
end end


should "not return instances as available when not seen the last 10 seconds" do should "not return instances as available when not seen the last 10 seconds" do
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini1.local', :uid => "00:01", :max_instances => 2 get '/jobs/next', :version => Testbot.version, :hostname => 'macmini1.local', :uid => "00:01", :max_instances => 2
get '/jobs/next', :version => Testbot::VERSION, :hostname => 'macmini2.local', :uid => "00:02", :max_instances => 4 get '/jobs/next', :version => Testbot.version, :hostname => 'macmini2.local', :uid => "00:02", :max_instances => 4
Runner.find(:uid => "00:02").update(:last_seen_at => Time.now - 10) Runner.find(:uid => "00:02").update(:last_seen_at => Time.now - 10)
get '/runners/total_instances' get '/runners/total_instances'
assert last_response.ok? assert last_response.ok?
Expand All @@ -315,7 +315,7 @@ def app


should "update last_seen_at for the runner" do should "update last_seen_at for the runner" do
runner = Runner.create(:uid => 'aa:aa:aa:aa:aa:aa') runner = Runner.create(:uid => 'aa:aa:aa:aa:aa:aa')
get "/runners/ping", :uid => 'aa:aa:aa:aa:aa:aa', :version => Testbot::VERSION get "/runners/ping", :uid => 'aa:aa:aa:aa:aa:aa', :version => Testbot.version
runner.reload runner.reload
assert last_response.ok? assert last_response.ok?
assert (Time.now - 5) < runner[:last_seen_at] assert (Time.now - 5) < runner[:last_seen_at]
Expand All @@ -324,26 +324,26 @@ def app


should "update data on the runner" do should "update data on the runner" do
runner = Runner.create(:uid => 'aa:aa:..') runner = Runner.create(:uid => 'aa:aa:..')
get "/runners/ping", :uid => 'aa:aa:..', :max_instances => 4, :idle_instances => 2, :hostname => "hostname1", :version => Testbot::VERSION, :username => 'jocke' get "/runners/ping", :uid => 'aa:aa:..', :max_instances => 4, :idle_instances => 2, :hostname => "hostname1", :version => Testbot.version, :username => 'jocke'
runner.reload runner.reload
assert last_response.ok? assert last_response.ok?
assert_equal 'aa:aa:..', runner.uid assert_equal 'aa:aa:..', runner.uid
assert_equal 4, runner.max_instances assert_equal 4, runner.max_instances
assert_equal 2, runner.idle_instances assert_equal 2, runner.idle_instances
assert_equal 'hostname1', runner.hostname assert_equal 'hostname1', runner.hostname
assert_equal Testbot::VERSION, runner.version assert_equal Testbot.version, runner.version
assert_equal 'jocke', runner.username assert_equal 'jocke', runner.username
end end


should "do nothing if the version does not match" do should "do nothing if the version does not match" do
runner = Runner.create(:uid => 'aa:aa:..', :version => Testbot::VERSION) runner = Runner.create(:uid => 'aa:aa:..', :version => Testbot.version)
get "/runners/ping", :uid => 'aa:aa:..', :version => "OLD" get "/runners/ping", :uid => 'aa:aa:..', :version => "OLD"
assert last_response.ok? assert last_response.ok?
assert_equal Testbot::VERSION, runner.reload.version assert_equal Testbot.version, runner.reload.version
end end


should "do nothing if the runners isnt known yet found" do should "do nothing if the runners isnt known yet found" do
get "/runners/ping", :uid => 'aa:aa:aa:aa:aa:aa', :version => Testbot::VERSION get "/runners/ping", :uid => 'aa:aa:aa:aa:aa:aa', :version => Testbot.version
assert last_response.ok? assert last_response.ok?
end end


Expand Down Expand Up @@ -394,7 +394,7 @@ def app
should "return its version" do should "return its version" do
get '/version' get '/version'
assert last_response.ok? assert last_response.ok?
assert_equal Testbot::VERSION.to_s, last_response.body assert_equal Testbot.version.to_s, last_response.body
end end


end end
Expand Down
2 changes: 1 addition & 1 deletion test/test_testbot.rb
Expand Up @@ -38,7 +38,7 @@ class CLITest < Test::Unit::TestCase


context "with --version" do context "with --version" do
should "print version and return true" do should "print version and return true" do
flexmock(CLI).should_receive(:puts).once.with("Testbot #{Testbot::VERSION}") flexmock(CLI).should_receive(:puts).once.with("Testbot #{Testbot.version}")
assert_equal true, CLI.run([ '--version' ]) assert_equal true, CLI.run([ '--version' ])
end end
end end
Expand Down
2 changes: 1 addition & 1 deletion testbot.gemspec
Expand Up @@ -4,7 +4,7 @@ require File.expand_path("lib/testbot")


Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "testbot" s.name = "testbot"
s.version = Testbot::VERSION s.version = Testbot.version
s.authors = ["Joakim Kolsjö"] s.authors = ["Joakim Kolsjö"]
s.email = ["joakim.kolsjo@gmail.com"] s.email = ["joakim.kolsjo@gmail.com"]
s.homepage = "http://github.com/joakimk/testbot" s.homepage = "http://github.com/joakimk/testbot"
Expand Down

0 comments on commit 9677ce1

Please sign in to comment.