Permalink
Browse files

only auto start/stop redis if not on CI

  • Loading branch information...
Matt Conway
Matt Conway committed Feb 2, 2012
1 parent 94407b4 commit 21ec8e06749d9b9bc40938064202e62640ffb1e6
Showing with 20 additions and 13 deletions.
  1. +1 −1 spec/redis-test.conf
  2. +19 −12 spec/spec_helper.rb
View
@@ -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.
View
@@ -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

0 comments on commit 21ec8e0

Please sign in to comment.