with_advisory_lock 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.travis.yml +46 -0
- data/README.md +5 -0
- data/ci/Gemfile.rails-3.0.x +5 -0
- data/ci/Gemfile.rails-3.1.x +4 -0
- data/ci/Gemfile.rails-3.2.x +4 -0
- data/ci/Gemfile.rails-4.0.x +5 -0
- data/lib/with_advisory_lock/mysql.rb +2 -2
- data/lib/with_advisory_lock/postgresql.rb +2 -2
- data/lib/with_advisory_lock/version.rb +1 -1
- data/test/database.yml +1 -1
- data/test/minitest_helper.rb +4 -5
- data/test/parallelism_test.rb +13 -11
- data/tests.sh +10 -9
- data/with_advisory_lock.gemspec +0 -1
- metadata +9 -47
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjRiZmQ3MDg3MTEwZDYwNzkzMDQ1YWFjNjc0Y2FmYmJlNTkyN2NjZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ODk2NDU3MzZkMjk1YTIyZmU0Y2UzYmM1OGQzYjJmMWNmNTkwZTg5Mw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTU4OGVjMDQyNzI4Njg5N2RhZmYzOTk5ZmNjMGRjZDg4M2MyZWJhYTJjNDcx
|
10
|
+
OTYzMGU4Nzc5Y2Y3NWMxMTk5ZTUzNjU5M2M5OWI4MGRmMjQ1OTJlNDY4YTQ4
|
11
|
+
NGY3MmI5ZjRhODZmYjM5NTMyZDRiZjFiZTE4ZDYwMzZiMDBjMmQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZWQ1NzY2N2QwM2JlNmRkMDg1N2NiZWVkOTU4MjUxMDA2NmQwZWRkZmQ0OWJj
|
14
|
+
ZDE4Yzg0ZDBkODQwYzI2M2JjZGQ0YmZhNzFlZGVhYWFiMDViNDA1ZjU0MGI4
|
15
|
+
Y2RkNTRlOWFiMDZmMzQ0N2RlOGE0ZWEyNjNmMjQ1ODg2N2IwNTY=
|
data/.travis.yml
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
+
- 2.0.0
|
4
5
|
- 1.8.7
|
5
6
|
- 1.9.3
|
6
7
|
|
8
|
+
gemfile:
|
9
|
+
# TODO: reenable once tests pass with 4.0
|
10
|
+
- ci/Gemfile.rails-4.0.x
|
11
|
+
- ci/Gemfile.rails-3.2.x
|
12
|
+
- ci/Gemfile.rails-3.1.x
|
13
|
+
- ci/Gemfile.rails-3.0.x
|
14
|
+
|
7
15
|
env:
|
8
16
|
- DB=sqlite
|
9
17
|
- DB=mysql
|
@@ -15,3 +23,41 @@ before_script:
|
|
15
23
|
- mysql -e 'create database with_advisory_lock_test'
|
16
24
|
- psql -c 'create database with_advisory_lock_test' -U postgres
|
17
25
|
|
26
|
+
matrix:
|
27
|
+
exclude:
|
28
|
+
- rvm: 1.8.7
|
29
|
+
gemfile: ci/Gemfile.rails-4.0.x
|
30
|
+
env: DB=sqlite
|
31
|
+
- rvm: 1.8.7
|
32
|
+
gemfile: ci/Gemfile.rails-4.0.x
|
33
|
+
env: DB=mysql
|
34
|
+
- rvm: 1.8.7
|
35
|
+
gemfile: ci/Gemfile.rails-4.0.x
|
36
|
+
env: DB=postgresql
|
37
|
+
- rvm: 2.0.0
|
38
|
+
gemfile: ci/Gemfile.rails-3.0.x
|
39
|
+
env: DB=sqlite
|
40
|
+
- rvm: 2.0.0
|
41
|
+
gemfile: ci/Gemfile.rails-3.0.x
|
42
|
+
env: DB=mysql
|
43
|
+
- rvm: 2.0.0
|
44
|
+
gemfile: ci/Gemfile.rails-3.0.x
|
45
|
+
env: DB=postgresql
|
46
|
+
- rvm: 2.0.0
|
47
|
+
gemfile: ci/Gemfile.rails-3.1.x
|
48
|
+
env: DB=sqlite
|
49
|
+
- rvm: 2.0.0
|
50
|
+
gemfile: ci/Gemfile.rails-3.1.x
|
51
|
+
env: DB=mysql
|
52
|
+
- rvm: 2.0.0
|
53
|
+
gemfile: ci/Gemfile.rails-3.1.x
|
54
|
+
env: DB=postgresql
|
55
|
+
- rvm: 2.0.0
|
56
|
+
gemfile: ci/Gemfile.rails-3.2.x
|
57
|
+
env: DB=sqlite
|
58
|
+
- rvm: 2.0.0
|
59
|
+
gemfile: ci/Gemfile.rails-3.2.x
|
60
|
+
env: DB=mysql
|
61
|
+
- rvm: 2.0.0
|
62
|
+
gemfile: ci/Gemfile.rails-3.2.x
|
63
|
+
env: DB=postgresql
|
data/README.md
CHANGED
@@ -91,6 +91,11 @@ aren't going to be commonly applicable, and they can be a source of
|
|
91
91
|
|
92
92
|
## Changelog
|
93
93
|
|
94
|
+
### 0.0.7
|
95
|
+
|
96
|
+
* Added Travis tests for Rails 3.0, 3.1, 3.2, and 4.0
|
97
|
+
* Fixed MySQL bug with select_value returning a string instead of an integer when using AR 3.0.x
|
98
|
+
|
94
99
|
### 0.0.6
|
95
100
|
|
96
101
|
* Only require ActiveRecord >= 3.0.x
|
@@ -14,7 +14,7 @@ module WithAdvisoryLock
|
|
14
14
|
# 0 if the attempt timed out (for example, because another client has
|
15
15
|
# previously locked the name), or NULL if an error occurred
|
16
16
|
# (such as running out of memory or the thread was killed with mysqladmin kill).
|
17
|
-
1 == connection.select_value("SELECT GET_LOCK(#{quoted_lock_name}, 0)")
|
17
|
+
1 == connection.select_value("SELECT GET_LOCK(#{quoted_lock_name}, 0)").to_i
|
18
18
|
end
|
19
19
|
|
20
20
|
def release_lock
|
@@ -22,7 +22,7 @@ module WithAdvisoryLock
|
|
22
22
|
# 0 if the lock was not established by this thread (
|
23
23
|
# in which case the lock is not released), and
|
24
24
|
# NULL if the named lock did not exist.
|
25
|
-
1 == connection.select_value("SELECT RELEASE_LOCK(#{quoted_lock_name})")
|
25
|
+
1 == connection.select_value("SELECT RELEASE_LOCK(#{quoted_lock_name})").to_i
|
26
26
|
end
|
27
27
|
|
28
28
|
def already_locked?
|
@@ -6,11 +6,11 @@ module WithAdvisoryLock
|
|
6
6
|
def try_lock
|
7
7
|
# pg_try_advisory_lock will either obtain the lock immediately
|
8
8
|
# and return true, or return false if the lock cannot be acquired immediately
|
9
|
-
"t" == connection.select_value("SELECT pg_try_advisory_lock(#{numeric_lock})")
|
9
|
+
"t" == connection.select_value("SELECT pg_try_advisory_lock(#{numeric_lock})").to_s
|
10
10
|
end
|
11
11
|
|
12
12
|
def release_lock
|
13
|
-
"t" == connection.select_value("SELECT pg_advisory_unlock(#{numeric_lock})")
|
13
|
+
"t" == connection.select_value("SELECT pg_advisory_unlock(#{numeric_lock})").to_s
|
14
14
|
end
|
15
15
|
|
16
16
|
def numeric_lock
|
data/test/database.yml
CHANGED
data/test/minitest_helper.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'active_record'
|
3
3
|
require 'with_advisory_lock'
|
4
|
-
require 'database_cleaner'
|
5
4
|
require 'tmpdir'
|
6
5
|
|
7
6
|
db_config = File.expand_path("database.yml", File.dirname(__FILE__))
|
8
7
|
ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(db_config)).result)
|
9
8
|
|
10
9
|
def env_db
|
11
|
-
ENV["DB"] || "
|
10
|
+
ENV["DB"] || "mysql"
|
12
11
|
end
|
13
12
|
|
14
13
|
ActiveRecord::Base.establish_connection(env_db)
|
@@ -21,14 +20,14 @@ require 'mocha/setup'
|
|
21
20
|
|
22
21
|
Thread.abort_on_exception = true
|
23
22
|
|
24
|
-
DatabaseCleaner.strategy = :deletion
|
25
23
|
class MiniTest::Spec
|
26
24
|
before do
|
27
25
|
ENV['FLOCK_DIR'] = Dir.mktmpdir
|
28
|
-
|
26
|
+
Tag.delete_all
|
27
|
+
TagAudit.delete_all
|
28
|
+
Label.delete_all
|
29
29
|
end
|
30
30
|
after do
|
31
|
-
DatabaseCleaner.clean
|
32
31
|
FileUtils.remove_entry_secure ENV['FLOCK_DIR']
|
33
32
|
end
|
34
33
|
end
|
data/test/parallelism_test.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
require 'minitest_helper'
|
2
2
|
|
3
|
+
parallelism_is_broken = begin
|
4
|
+
# Rails < 3.2 has known bugs with parallelism
|
5
|
+
(ActiveRecord::VERSION::MAJOR <= 3 && ActiveRecord::VERSION::MINOR < 2) ||
|
6
|
+
# SQLite doesn't support parallel writes
|
7
|
+
ENV["DB"] =~ /sqlite/
|
8
|
+
end
|
9
|
+
|
3
10
|
describe "parallelism" do
|
4
11
|
def find_or_create_at(run_at, with_advisory_lock)
|
5
12
|
ActiveRecord::Base.connection.reconnect!
|
@@ -15,13 +22,13 @@ describe "parallelism" do
|
|
15
22
|
else
|
16
23
|
task.call
|
17
24
|
end
|
18
|
-
ActiveRecord::Base.connection.close
|
25
|
+
ActiveRecord::Base.connection.close if ActiveRecord::Base.connection.respond_to?(:close)
|
19
26
|
end
|
20
27
|
|
21
28
|
def run_workers(with_advisory_lock)
|
22
29
|
skip if env_db == "sqlite"
|
23
30
|
@iterations.times do
|
24
|
-
time = (Time.now.to_i +
|
31
|
+
time = (Time.now.to_i + 4).to_f
|
25
32
|
threads = @workers.times.collect do
|
26
33
|
Thread.new do
|
27
34
|
find_or_create_at(time, with_advisory_lock)
|
@@ -39,14 +46,9 @@ describe "parallelism" do
|
|
39
46
|
|
40
47
|
it "parallel threads create multiple duplicate rows" do
|
41
48
|
run_workers(with_advisory_lock = false)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
oper = :> # Everything else should create duplicate rows.
|
46
|
-
end
|
47
|
-
Tag.all.size.must_be oper, @iterations # <- any duplicated rows will make me happy.
|
48
|
-
TagAudit.all.size.must_be oper, @iterations # <- any duplicated rows will make me happy.
|
49
|
-
Label.all.size.must_be oper, @iterations # <- any duplicated rows will make me happy.
|
49
|
+
Tag.all.size.must_be :>, @iterations # <- any duplicated rows will make me happy.
|
50
|
+
TagAudit.all.size.must_be :>, @iterations # <- any duplicated rows will make me happy.
|
51
|
+
Label.all.size.must_be :>, @iterations # <- any duplicated rows will make me happy.
|
50
52
|
end
|
51
53
|
|
52
54
|
it "parallel threads with_advisory_lock don't create multiple duplicate rows" do
|
@@ -92,4 +94,4 @@ describe "parallelism" do
|
|
92
94
|
t2_acquired_lock.must_be_false
|
93
95
|
t2_return_value.must_be_false
|
94
96
|
end
|
95
|
-
end
|
97
|
+
end unless parallelism_is_broken
|
data/tests.sh
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
#!/bin/sh -e
|
2
2
|
export BUNDLE_GEMFILE RMI DB
|
3
3
|
|
4
|
-
for RMI in 1.8.7-
|
5
|
-
do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
for RMI in ree-1.8.7-2011.03 1.9.3-p327 ; do
|
5
|
+
for BUNDLE_GEMFILE in ci/Gemfile.rails-3.0.x ci/Gemfile.rails-3.1.x ci/Gemfile.rails-3.2.x ; do
|
6
|
+
rbenv local $RMI
|
7
|
+
bundle --quiet
|
8
|
+
for DB in sqlite mysql postgresql
|
9
|
+
do
|
10
|
+
echo $DB $BUNDLE_GEMFILE `ruby -v`
|
11
|
+
bundle exec rake
|
12
|
+
done
|
12
13
|
done
|
13
|
-
done
|
14
|
+
done
|
data/with_advisory_lock.gemspec
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: with_advisory_lock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Matthew McEachen
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: yard
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: minitest
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ! '>='
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ! '>='
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -78,7 +69,6 @@ dependencies:
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: minitest-great_expectations
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ! '>='
|
84
74
|
- !ruby/object:Gem::Version
|
@@ -86,7 +76,6 @@ dependencies:
|
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - ! '>='
|
92
81
|
- !ruby/object:Gem::Version
|
@@ -94,7 +83,6 @@ dependencies:
|
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: mocha
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
87
|
- - ! '>='
|
100
88
|
- !ruby/object:Gem::Version
|
@@ -102,7 +90,6 @@ dependencies:
|
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
94
|
- - ! '>='
|
108
95
|
- !ruby/object:Gem::Version
|
@@ -110,7 +97,6 @@ dependencies:
|
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: mysql2
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
101
|
- - ! '>='
|
116
102
|
- !ruby/object:Gem::Version
|
@@ -118,7 +104,6 @@ dependencies:
|
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
108
|
- - ! '>='
|
124
109
|
- !ruby/object:Gem::Version
|
@@ -126,7 +111,6 @@ dependencies:
|
|
126
111
|
- !ruby/object:Gem::Dependency
|
127
112
|
name: pg
|
128
113
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
114
|
requirements:
|
131
115
|
- - ! '>='
|
132
116
|
- !ruby/object:Gem::Version
|
@@ -134,7 +118,6 @@ dependencies:
|
|
134
118
|
type: :development
|
135
119
|
prerelease: false
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
121
|
requirements:
|
139
122
|
- - ! '>='
|
140
123
|
- !ruby/object:Gem::Version
|
@@ -142,7 +125,6 @@ dependencies:
|
|
142
125
|
- !ruby/object:Gem::Dependency
|
143
126
|
name: sqlite3
|
144
127
|
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
128
|
requirements:
|
147
129
|
- - ! '>='
|
148
130
|
- !ruby/object:Gem::Version
|
@@ -150,23 +132,6 @@ dependencies:
|
|
150
132
|
type: :development
|
151
133
|
prerelease: false
|
152
134
|
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
|
-
requirements:
|
155
|
-
- - ! '>='
|
156
|
-
- !ruby/object:Gem::Version
|
157
|
-
version: '0'
|
158
|
-
- !ruby/object:Gem::Dependency
|
159
|
-
name: database_cleaner
|
160
|
-
requirement: !ruby/object:Gem::Requirement
|
161
|
-
none: false
|
162
|
-
requirements:
|
163
|
-
- - ! '>='
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
version: '0'
|
166
|
-
type: :development
|
167
|
-
prerelease: false
|
168
|
-
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
135
|
requirements:
|
171
136
|
- - ! '>='
|
172
137
|
- !ruby/object:Gem::Version
|
@@ -184,6 +149,10 @@ files:
|
|
184
149
|
- LICENSE.txt
|
185
150
|
- README.md
|
186
151
|
- Rakefile
|
152
|
+
- ci/Gemfile.rails-3.0.x
|
153
|
+
- ci/Gemfile.rails-3.1.x
|
154
|
+
- ci/Gemfile.rails-3.2.x
|
155
|
+
- ci/Gemfile.rails-4.0.x
|
187
156
|
- lib/with_advisory_lock.rb
|
188
157
|
- lib/with_advisory_lock/base.rb
|
189
158
|
- lib/with_advisory_lock/concern.rb
|
@@ -203,33 +172,26 @@ files:
|
|
203
172
|
- with_advisory_lock.gemspec
|
204
173
|
homepage: ''
|
205
174
|
licenses: []
|
175
|
+
metadata: {}
|
206
176
|
post_install_message:
|
207
177
|
rdoc_options: []
|
208
178
|
require_paths:
|
209
179
|
- lib
|
210
180
|
required_ruby_version: !ruby/object:Gem::Requirement
|
211
|
-
none: false
|
212
181
|
requirements:
|
213
182
|
- - ! '>='
|
214
183
|
- !ruby/object:Gem::Version
|
215
184
|
version: '0'
|
216
|
-
segments:
|
217
|
-
- 0
|
218
|
-
hash: -4256670677892025284
|
219
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
220
|
-
none: false
|
221
186
|
requirements:
|
222
187
|
- - ! '>='
|
223
188
|
- !ruby/object:Gem::Version
|
224
189
|
version: '0'
|
225
|
-
segments:
|
226
|
-
- 0
|
227
|
-
hash: -4256670677892025284
|
228
190
|
requirements: []
|
229
191
|
rubyforge_project:
|
230
|
-
rubygems_version:
|
192
|
+
rubygems_version: 2.0.3
|
231
193
|
signing_key:
|
232
|
-
specification_version:
|
194
|
+
specification_version: 4
|
233
195
|
summary: Advisory locking for ActiveRecord
|
234
196
|
test_files:
|
235
197
|
- test/concern_test.rb
|