Permalink
Browse files

only auto start redis if not on CI

  • Loading branch information...
Matt Conway
Matt Conway committed Feb 2, 2012
1 parent d66ae57 commit 0010bd55a554cf15e4af11e7d09918b9c09ae454
Showing with 21 additions and 12 deletions.
  1. +1 −1 spec/redis-test.conf
  2. +20 −11 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
@@ -3,18 +3,27 @@
# 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
##

0 comments on commit 0010bd5

Please sign in to comment.