Skip to content

Commit

Permalink
finally implemented the NO_TIMEOUT configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
srushti committed Sep 30, 2011
1 parent e3917f1 commit fde154e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -91,7 +91,7 @@ Every project in Goldberg can have its own custom configuration by checking in a
config.ruby = '1.9.2' # Your server needs to have rvm installed for this setting to be considered
config.environment_variables = {"FOO" => "bar"}
config.after_build lambda { |build, project| `touch ~/Desktop/actually_built` }
config.timeout = 10.minutes
config.timeout = 10.minutes # Defaults to 10.minutes if not configured. Set it to Project::Configuration::NO_TIMEOUT if you don't want it to ever timeout
config.nice = 5 # Use this to reduce the scheduling priority (increase niceness) of CPU
# intensive builds that may otherwise leave the Goldberg web application
# unresponsive. Uses the UNIX `nice` command. Defaults to '0'.
Expand Down
2 changes: 1 addition & 1 deletion app/models/build.rb
Expand Up @@ -69,7 +69,7 @@ def execute_async(command)
end

def exceeded_timeout?(start_time)
DateTime.now > start_time + project.timeout
project.timeout != Project::Configuration::NO_TIMEOUT && DateTime.now > start_time + project.timeout
end

def before_build
Expand Down
24 changes: 24 additions & 0 deletions spec/models/build_spec.rb
Expand Up @@ -96,6 +96,30 @@
pending "Need to write spec to make sure all code is getting executed within Bundle.with_clean_env"
end

describe 'timeout' do
it "reports when the build hasn't exceeded the timeout" do
config = Project::Configuration.new.tap{|config| config.timeout = 3.minutes}
project.stub(:config).and_return(config)
now = DateTime.now
DateTime.stub(:now).and_return(now)
build.exceeded_timeout?(now - 179.seconds).should == false
end

it "reports when the build has exceeded the timeout" do
config = Project::Configuration.new.tap{|config| config.timeout = 3.minutes}
project.stub(:config).and_return(config)
now = DateTime.now
DateTime.stub(:now).and_return(now)
build.exceeded_timeout?(now - 181.seconds).should == true
end

it "doesn't timeout if it was configured as such" do
config = Project::Configuration.new.tap{|config| config.timeout = Project::Configuration::NO_TIMEOUT}
project.stub(:config).and_return(config)
build.exceeded_timeout?(DateTime.now - 2.days).should == false
end
end

it "performs prebuild setup before building the project" do
Bundler.stub(:with_clean_env)
build.should_receive(:before_build)
Expand Down

0 comments on commit fde154e

Please sign in to comment.