Skip to content

Commit

Permalink
only auto start/stop redis if not on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Conway committed Feb 2, 2012
1 parent 94407b4 commit 21ec8e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion spec/redis-test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ daemonize yes
pidfile ./redis.pid

# Accept connections on the specified port, default is 6379
port 9736
port 6379

# If you want you can bind a single interface, if the bind option is not
# specified all the interfaces will listen for incoming connections.
Expand Down
31 changes: 19 additions & 12 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@
# No need to start redis when running in Travis
unless ENV['CI']

spec_dir = File.dirname(File.expand_path(__FILE__))
REDIS_CMD = "redis-server #{spec_dir}/redis-test.conf"

puts "Starting redis for testing at localhost:9736..."
puts `cd #{spec_dir}; #{REDIS_CMD}`
Resque.redis = 'localhost:9736'

# Schedule the redis server for shutdown when tests are all finished.
at_exit do
pid = File.read("#{spec_dir}/redis.pid").to_i rescue nil
system ("kill #{pid}") if pid != 0
begin
Resque.queues
rescue Errno::ECONNREFUSED
spec_dir = File.dirname(File.expand_path(__FILE__))
REDIS_CMD = "redis-server #{spec_dir}/redis-test.conf"

puts "Starting redis for testing at localhost..."
puts `cd #{spec_dir}; #{REDIS_CMD}`

# Schedule the redis server for shutdown when tests are all finished.
at_exit do
puts 'Stopping redis'
pid = File.read("#{spec_dir}/redis.pid").to_i rescue nil
system ("kill -9 #{pid}") if pid.to_i != 0
File.delete("#{spec_dir}/redis.pid") rescue nil
File.delete("#{spec_dir}/redis-server.log") rescue nil
File.delete("#{spec_dir}/dump.rdb") rescue nil
end
end

end

class SomeJob
Expand Down

0 comments on commit 21ec8e0

Please sign in to comment.