Sha256: 671074db667f97a19503c6c47e6a35356a7c812e27b2b4c08998e947ceb97f64

Contents?: true

Size: 1.94 KB

Versions: 17

Compression:

Stored size: 1.94 KB

Contents

require "rake/testtask"

ENV["REDIS_BRANCH"] ||= "unstable"

REDIS_DIR = File.expand_path(File.join("..", "test"), __FILE__)
REDIS_CNF = File.join(REDIS_DIR, "test.conf")
REDIS_CNF_TEMPLATE = File.join(REDIS_DIR, "test.conf.erb")
REDIS_PID = File.join(REDIS_DIR, "db", "redis.pid")
REDIS_LOG = File.join(REDIS_DIR, "db", "redis.log")
REDIS_SOCKET = File.join(REDIS_DIR, "db", "redis.sock")
BINARY = "tmp/redis-#{ENV["REDIS_BRANCH"]}/src/redis-server"

task :default => :run

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

desc "Start the Redis server"
task :start => [BINARY, REDIS_CNF] do
  sh "#{BINARY} --version"

  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

  unless redis_running
    unless system("#{BINARY} #{REDIS_CNF}")
      abort "could not start redis-server"
    end
  end

  at_exit do
    Rake::Task["stop"].invoke
  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

desc "Clean up testing artifacts"
task :clean do
  FileUtils.rm_f(BINARY)
  FileUtils.rm_f(REDIS_CNF)
end

file BINARY do
  branch = ENV.fetch("REDIS_BRANCH")

  sh <<-SH
  mkdir -p tmp;
  cd tmp;
  rm -rf redis-#{branch};
  wget https://github.com/antirez/redis/archive/#{branch}.tar.gz -O #{branch}.tar.gz;
  tar xf #{branch}.tar.gz;
  cd redis-#{branch};
  make
  SH
end

file REDIS_CNF => [REDIS_CNF_TEMPLATE, __FILE__] do |t|
  require 'erb'

  erb = t.prerequisites[0]
  template = File.read(erb)

  File.open(REDIS_CNF, 'w') do |file|
    file.puts "\# This file was auto-generated at #{Time.now}",
              "\# from (#{erb})",
              "\#"
    conf = ERB.new(template).result
    file << conf
  end
end

Rake::TestTask.new do |t|
  t.options = "-v" if $VERBOSE
  t.test_files = FileList["test/*_test.rb"]
end

Version data entries

17 entries across 16 versions & 7 rubygems

Version Path
finsync_redis-3.3.5 Rakefile
redis-3.3.5 Rakefile
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/redis-3.3.3/Rakefile
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/Rakefile
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/Rakefile
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/Rakefile
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/redis-3.3.3/Rakefile
redis-3.3.3 Rakefile
abaci-0.3.0 vendor/bundle/gems/redis-3.3.1/Rakefile
abaci-0.3.0 vendor/bundle/gems/redis-3.3.2/Rakefile
redis-3.3.2 Rakefile
redis-3.3.1 Rakefile
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/Rakefile
redis-3.3.0 Rakefile
discourse-redis-3.2.2 Rakefile
redis-3.2.2 Rakefile
redis-3.2.1 Rakefile