Skip to content

Commit

Permalink
Added test Redis configuration file. Ignoring test/db/*. Added Rakefi…
Browse files Browse the repository at this point in the history
…le tasks for starting and stopping Redis.
  • Loading branch information
David Czarnecki committed Jan 4, 2011
1 parent c249b0b commit 7dbf0e1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -42,3 +42,4 @@ pkg
#*.swp

Gemfile.lock
test/db/*
37 changes: 35 additions & 2 deletions Rakefile
Expand Up @@ -40,8 +40,6 @@ Rcov::RcovTask.new do |test|
test.verbose = true
end

task :default => :test

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
Expand All @@ -51,3 +49,38 @@ Rake::RDocTask.new do |rdoc|
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end

REDIS_DIR = File.expand_path(File.join("..", "test"), __FILE__)
REDIS_CNF = File.join(REDIS_DIR, "test.conf")
REDIS_PID = File.join(REDIS_DIR, "db", "redis.pid")
REDIS_LOCATION = ENV['REDIS_LOCATION']

task :default => :run

desc "Run tests and manage server start/stop"
task :run => [:start, :test, :stop]

desc "Start the Redis server"
task :start do
redis_running = \
begin
File.exists?(REDIS_PID) && Process.kill(0, File.read(REDIS_PID).to_i)
rescue Errno::ESRCH
FileUtils.rm REDIS_PID
false
end

if REDIS_LOCATION
system "#{REDIS_LOCATION}/redis-server #{REDIS_CNF}" unless redis_running
else
system "redis-server #{REDIS_CNF}" unless redis_running
end
end

desc "Stop the Redis server"
task :stop do
if File.exists?(REDIS_PID)
Process.kill "INT", File.read(REDIS_PID).to_i
FileUtils.rm REDIS_PID
end
end

0 comments on commit 7dbf0e1

Please sign in to comment.