refilling_queue 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Appraisals ADDED
@@ -0,0 +1,5 @@
1
+ ["2", "3"].each do |version|
2
+ appraise "redis#{version}" do
3
+ gem "redis", "~>#{version}.0"
4
+ end
5
+ end
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
1
  source :rubygems
2
2
  gemspec
3
3
 
4
+ gem 'appraisal'
5
+ gem 'bump'
4
6
  gem 'rake'
5
7
  gem 'rspec', '~>2'
6
- gem 'fakeredis'
8
+ gem 'redis'
data/Gemfile.lock CHANGED
@@ -1,14 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- refilling_queue (0.0.3)
4
+ refilling_queue (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
+ appraisal (0.5.1)
10
+ bundler
11
+ rake
12
+ bump (0.3.5)
9
13
  diff-lcs (1.1.3)
10
- fakeredis (0.4.0)
11
- redis (~> 3.0.0)
12
14
  rake (0.9.2)
13
15
  redis (3.0.1)
14
16
  rspec (2.6.0)
@@ -24,7 +26,9 @@ PLATFORMS
24
26
  ruby
25
27
 
26
28
  DEPENDENCIES
27
- fakeredis
29
+ appraisal
30
+ bump
28
31
  rake
32
+ redis
29
33
  refilling_queue!
30
34
  rspec (~> 2)
data/Rakefile CHANGED
@@ -1,22 +1,11 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'appraisal'
3
+ require 'bump/tasks'
2
4
 
3
- task :default do
5
+ task :spec do
4
6
  sh "rspec spec/"
5
7
  end
6
8
 
7
- # extracted from https://github.com/grosser/project_template
8
- rule /^version:bump:.*/ do |t|
9
- sh "git status | grep 'nothing to commit'" # ensure we are not dirty
10
- index = ['major', 'minor','patch'].index(t.name.split(':').last)
11
- file = 'lib/refilling_queue/version.rb'
12
-
13
- version_file = File.read(file)
14
- old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
15
- version_parts[index] = version_parts[index].to_i + 1
16
- version_parts[2] = 0 if index < 2 # remove patch for minor
17
- version_parts[1] = 0 if index < 1 # remove minor for major
18
- new_version = version_parts * '.'
19
- File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
20
-
21
- sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
9
+ task :default do
10
+ sh "bundle exec rake appraisal:install && bundle exec rake appraisal spec"
22
11
  end
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "appraisal"
6
+ gem "bump"
7
+ gem "rake"
8
+ gem "rspec", "~>2"
9
+ gem "redis", "~>2.0"
10
+
11
+ gemspec :path=>"../"
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: /Users/mgrosser/code/tools/refilling_queue
3
+ specs:
4
+ refilling_queue (0.0.3)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ appraisal (0.5.1)
10
+ bundler
11
+ rake
12
+ bump (0.3.5)
13
+ diff-lcs (1.1.3)
14
+ rake (10.0.2)
15
+ redis (2.2.2)
16
+ rspec (2.11.0)
17
+ rspec-core (~> 2.11.0)
18
+ rspec-expectations (~> 2.11.0)
19
+ rspec-mocks (~> 2.11.0)
20
+ rspec-core (2.11.1)
21
+ rspec-expectations (2.11.3)
22
+ diff-lcs (~> 1.1.3)
23
+ rspec-mocks (2.11.3)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ appraisal
30
+ bump
31
+ rake
32
+ redis (~> 2.0)
33
+ refilling_queue!
34
+ rspec (~> 2)
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "appraisal"
6
+ gem "bump"
7
+ gem "rake"
8
+ gem "rspec", "~>2"
9
+ gem "redis", "~>3.0"
10
+
11
+ gemspec :path=>"../"
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: /Users/mgrosser/code/tools/refilling_queue
3
+ specs:
4
+ refilling_queue (0.0.3)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ appraisal (0.5.1)
10
+ bundler
11
+ rake
12
+ bump (0.3.5)
13
+ diff-lcs (1.1.3)
14
+ rake (10.0.2)
15
+ redis (3.0.2)
16
+ rspec (2.11.0)
17
+ rspec-core (~> 2.11.0)
18
+ rspec-expectations (~> 2.11.0)
19
+ rspec-mocks (~> 2.11.0)
20
+ rspec-core (2.11.1)
21
+ rspec-expectations (2.11.3)
22
+ diff-lcs (~> 1.1.3)
23
+ rspec-mocks (2.11.3)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ appraisal
30
+ bump
31
+ rake
32
+ redis (~> 3.0)
33
+ refilling_queue!
34
+ rspec (~> 2)
@@ -1,3 +1,3 @@
1
1
  class RefillingQueue
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -53,7 +53,7 @@ class RefillingQueue
53
53
  @client.setnx lock, "1"
54
54
  @client.expire lock, @options[:lock_timeout]
55
55
  end
56
- raise RefillingQueue::Locked unless acquired
56
+ raise RefillingQueue::Locked unless [true, 1].include?(acquired)
57
57
 
58
58
  begin
59
59
  yield
@@ -1,15 +1,19 @@
1
1
  require 'spec_helper'
2
- require 'fakeredis'
3
2
 
4
3
  describe RefillingQueue do
5
4
  def kill_all_threads
6
5
  Thread.list.each {|thread| thread.exit unless thread == Thread.current }
7
6
  end
8
7
 
9
- let(:client){ FakeRedis::Redis.new }
8
+ let(:client){ Redis.new }
10
9
 
11
10
  before do
12
11
  kill_all_threads
12
+ client.flushdb
13
+ end
14
+
15
+ after :all do
16
+ `rm -f dump.rdb`
13
17
  end
14
18
 
15
19
  it "has a VERSION" do
@@ -27,9 +31,9 @@ describe RefillingQueue do
27
31
  context "#pop" do
28
32
  it "removes an element" do
29
33
  queue = RefillingQueue.new(client, "x"){ [1,2,3,4] }
30
- queue.pop.should == 1
31
- queue.pop.should == 2
32
- queue.pop.should == 3
34
+ queue.pop.should == "1"
35
+ queue.pop.should == "2"
36
+ queue.pop.should == "3"
33
37
  end
34
38
 
35
39
  it "only tries to refill once" do
@@ -41,23 +45,23 @@ describe RefillingQueue do
41
45
  it "refills itself if queue gets empty" do
42
46
  content = [1]
43
47
  queue = RefillingQueue.new(client, "x"){ content }
44
- queue.pop.should == 1
48
+ queue.pop.should == "1"
45
49
  content.replace [4,5]
46
- queue.pop.should == 4
47
- queue.pop.should == 5
48
- queue.pop.should == 4
50
+ queue.pop.should == "4"
51
+ queue.pop.should == "5"
52
+ queue.pop.should == "4"
49
53
  end
50
54
 
51
55
  it "refills itself when it expires" do
52
56
  content = [1,2,3]
53
- queue = RefillingQueue.new(client, "x", :refresh_every => 0.1){ content }
57
+ queue = RefillingQueue.new(client, "x", :refresh_every => 1){ content }
54
58
 
55
- queue.pop.should == 1
59
+ queue.pop.should == "1"
56
60
  content.replace [4,5]
57
- queue.pop.should == 2
58
- sleep 0.5
61
+ queue.pop.should == "2"
62
+ sleep 2
59
63
 
60
- queue.pop.should == 4
64
+ queue.pop.should == "4"
61
65
  end
62
66
  end
63
67
 
@@ -67,23 +71,22 @@ describe RefillingQueue do
67
71
 
68
72
  # lock-blocker
69
73
  Thread.new do
70
- RefillingQueue.new(client, "x"){ sleep 0.2; called << 1; [] }.pop
74
+ RefillingQueue.new(client, "x"){ called << 1; sleep 0.3; called << 2; [] }.pop
71
75
  end
72
76
  sleep 0.1
73
77
 
74
78
  # blocked
75
79
  locked = false
76
- Thread.new do
77
- queue = RefillingQueue.new(client, "x"){ sleep 0.2; called << 1; [] }
78
- begin
79
- queue.pop
80
- rescue RefillingQueue::Locked
81
- locked = true
82
- end
80
+ queue = RefillingQueue.new(client, "x"){ called << 3; [] }
81
+ begin
82
+ queue.pop
83
+ fail
84
+ rescue RefillingQueue::Locked
85
+ locked = true
83
86
  end
84
87
  sleep 0.3
85
88
 
86
- called.should == [1]
89
+ called.should == [1, 2]
87
90
  locked.should == true
88
91
  end
89
92
 
@@ -99,9 +102,9 @@ describe RefillingQueue do
99
102
  RefillingQueue.new(client, "x", :lock_timeout => 1){ called << 1; [1] }.pop
100
103
  Thread.new do
101
104
  # lock-blocker
102
- RefillingQueue.new(client, "x", :lock_timeout => 1){ sleep 2; called << 2; [1] }.pop
105
+ RefillingQueue.new(client, "x", :lock_timeout => 1){ sleep 3; called << 2; [1] }.pop
103
106
  end
104
- sleep 1.5
107
+ sleep 2
105
108
  RefillingQueue.new(client, "x", :lock_timeout => 1){ called << 3; [1] }.pop
106
109
  called.should == [1,3]
107
110
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,3 @@
1
- require "fakeredis"
2
-
3
1
  $LOAD_PATH.unshift 'lib'
4
2
  require 'refilling_queue'
3
+ require 'redis'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refilling_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-13 00:00:00.000000000 Z
12
+ date: 2012-11-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: michael@grosser.it
@@ -18,10 +18,15 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - .travis.yml
21
+ - Appraisals
21
22
  - Gemfile
22
23
  - Gemfile.lock
23
24
  - Rakefile
24
25
  - Readme.md
26
+ - gemfiles/redis2.gemfile
27
+ - gemfiles/redis2.gemfile.lock
28
+ - gemfiles/redis3.gemfile
29
+ - gemfiles/redis3.gemfile.lock
25
30
  - lib/refilling_queue.rb
26
31
  - lib/refilling_queue/version.rb
27
32
  - refilling_queue.gemspec
@@ -42,7 +47,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
42
47
  version: '0'
43
48
  segments:
44
49
  - 0
45
- hash: -2533570961055463155
50
+ hash: 949949052394646117
46
51
  required_rubygems_version: !ruby/object:Gem::Requirement
47
52
  none: false
48
53
  requirements:
@@ -51,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
56
  version: '0'
52
57
  segments:
53
58
  - 0
54
- hash: -2533570961055463155
59
+ hash: 949949052394646117
55
60
  requirements: []
56
61
  rubyforge_project:
57
62
  rubygems_version: 1.8.24