Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 110 lines (80 sloc) 2.057 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
require 'rubygems'
require 'spec/autorun'
require 'mocha'

dir = File.dirname(__FILE__)
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
require 'resque-restriction'

#
# make sure we can run redis
#

if !system("which redis-server")
  puts '', "** can't find `redis-server` in your path"
  puts "** try running `sudo rake install`"
  abort ''
end


#
# start our own redis when the tests start,
# kill it when they end
#

at_exit do
  next if $!

  exit_code = Spec::Runner.run

  pid = `ps -e -o pid,command | grep [r]edis-test`.split(" ")[0]
  puts "Killing test redis server [#{pid}]..."
  `rm -f #{dir}/dump.rdb`
  Process.kill("KILL", pid.to_i)
  exit exit_code
end

puts "Starting redis for testing at localhost:9736..."
`redis-server #{dir}/redis-test.conf`
Resque.redis = 'localhost:9736'

##
# Helper to perform job classes
#
module PerformJob
  def perform_job(klass, *args)
    resque_job = Resque::Job.new(:testqueue, 'class' => klass, 'args' => args)
    resque_job.perform
  end
end

class OneDayRestrictionJob < Resque::Plugins::RestrictionJob
  restrict :per_day => 100

  @queue = 'normal'
  
  def self.perform(args)
  end
end

class OneHourRestrictionJob < Resque::Plugins::RestrictionJob
  restrict :per_hour => 10

  @queue = 'normal'

  def self.perform(args)
  end
end

class IdentifiedRestrictionJob < Resque::Plugins::RestrictionJob
  restrict :per_hour => 10

  @queue = 'normal'

  def self.restriction_identifier(*args)
    [self.to_s, args.first].join(":")
  end

  def self.perform(*args)
  end
end

class ConcurrentRestrictionJob < Resque::Plugins::RestrictionJob
  restrict :concurrent => 1

  @queue = 'normal'

  def self.perform(*args)
    sleep 0.2
  end
end

class MultipleRestrictionJob < Resque::Plugins::RestrictionJob
  restrict :per_hour => 10, :per_300 => 2

  @queue = 'normal'

  def self.perform(args)
  end
end

class MultiCallRestrictionJob < Resque::Plugins::RestrictionJob
  restrict :per_hour => 10
  restrict :per_300 => 2

  @queue = 'normal'

  def self.perform(args)
  end
end
Something went wrong with that request. Please try again.