with_advisory_lock 7.0.1 → 7.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f594bf1ed9b20028febee227bd33eddf70f2c3deb42ae7e8a4d83d794125281d
4
- data.tar.gz: 6882cea1e84d517bdf847b8f66b7dd6bb7b6c93de09c156b459019aab324ace0
3
+ metadata.gz: 7a82d92e5b44f2cf65a9af5ac2d00baacab6d47b3b47be9fc2db82bd5677e4c7
4
+ data.tar.gz: 4a9b77cd24fad228812b9eff2f65079e6be7b95130a8e8d628d71525045ef902
5
5
  SHA512:
6
- metadata.gz: a89eff2b9fccadd2f64ac7467c9daf19156fbac5196358b9ce7089c2d743c353e4fbb8b993d2c0440b0f253c78a56620a603cd9d41dd0e3f027e02b5f901f72c
7
- data.tar.gz: 02b5903b081175e8f7ce07450738fd88d8f0f92dfc52fbb6901e9738aa90312313c3313c70ccfcdab998aa799399a173215edf913145b72d56958042681fb4e6
6
+ metadata.gz: 77996aa445351903666828d916b8bd02ad4357496c2240ac847f937f7b3adff7af83993b10d6af8bcdb33825992dc6391cc211f97428c36b2bd102e65e5c26b2
7
+ data.tar.gz: 94ec70a26f7c336f9dba44a384bc16d9d680d7495e43cb0c9fc22fee2380317f5d5263f36d3998837ca21f3e05424c7fc0fdb37ed75daf441ce534f0b4d67339
@@ -1 +1 @@
1
- {".":"7.0.1"}
1
+ {".":"7.0.2"}
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.4.4
1
+ ruby 3.4.6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## Changelog
2
2
 
3
+ ## [7.0.2](https://github.com/ClosureTree/with_advisory_lock/compare/with_advisory_lock/v7.0.1...with_advisory_lock/v7.0.2) (2025-09-20)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * Replace connection.select_value with connection.query_value ([#131](https://github.com/ClosureTree/with_advisory_lock/issues/131)) ([dc01977](https://github.com/ClosureTree/with_advisory_lock/commit/dc01977e5e3a120843b19a5e6befd538c6e36516))
9
+
3
10
  ## [7.0.1](https://github.com/ClosureTree/with_advisory_lock/compare/with_advisory_lock/v7.0.0...with_advisory_lock/v7.0.1) (2025-07-21)
4
11
 
5
12
 
@@ -65,7 +65,7 @@ module WithAdvisoryLock
65
65
  private
66
66
 
67
67
  def execute_successful?(mysql_function)
68
- select_value("SELECT #{mysql_function}") == 1
68
+ query_value("SELECT #{mysql_function}") == 1
69
69
  end
70
70
  end
71
71
  end
@@ -71,7 +71,7 @@ module WithAdvisoryLock
71
71
  LIMIT 1
72
72
  SQL
73
73
 
74
- select_value(query).present?
74
+ query_value(query).present?
75
75
  rescue ActiveRecord::StatementInvalid
76
76
  # If pg_locks is not accessible, fall back to nil to indicate we should use the default method
77
77
  nil
@@ -96,7 +96,7 @@ module WithAdvisoryLock
96
96
  end
97
97
 
98
98
  def execute_advisory(function, lock_keys, lock_name)
99
- result = select_value(prepare_sql(function, lock_keys, lock_name))
99
+ result = query_value(prepare_sql(function, lock_keys, lock_name))
100
100
  LOCK_RESULT_VALUES.include?(result)
101
101
  end
102
102
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WithAdvisoryLock
4
- VERSION = Gem::Version.new('7.0.1')
4
+ VERSION = Gem::Version.new('7.0.2')
5
5
  end
@@ -133,6 +133,25 @@ module LockTestCases
133
133
  # After the block, current_advisory_lock should be nil regardless
134
134
  assert_nil model_class.current_advisory_lock
135
135
  end
136
+
137
+ test 'does not write and read lock queries from the query cache' do
138
+ model_class.connection.cache do
139
+ model_class.with_advisory_lock!("lock", timeout_seconds: 0) {}
140
+ assert_nil model_class.connection.query_cache["SELECT GET_LOCK('lock', 0)"]
141
+
142
+ # Blocker thread uses a different connection
143
+ blocker = Thread.new do
144
+ model_class.with_advisory_lock("lock", timeout_seconds: 0) { sleep 1 }
145
+ end
146
+ # blocker should get the lock and not release it in time
147
+ sleep 0.5
148
+ lock_result = model_class.with_advisory_lock_result("lock", timeout_seconds: 0) do
149
+ raise "Successfully entered critical region while lock was held by other thread"
150
+ end
151
+ blocker.join
152
+ assert_not(lock_result.lock_was_acquired?)
153
+ end
154
+ end
136
155
  end
137
156
  end
138
157
 
@@ -177,7 +196,7 @@ class MySQLLockTest < GemTestCase
177
196
  # Hold a lock in another connection - need to use the same prefixed name as the gem
178
197
  other_conn = model_class.connection_pool.checkout
179
198
  lock_keys = other_conn.lock_keys_for(lock_name)
180
- other_conn.select_value("SELECT GET_LOCK(#{other_conn.quote(lock_keys.first)}, 0)")
199
+ other_conn.query_value("SELECT GET_LOCK(#{other_conn.quote(lock_keys.first)}, 0)")
181
200
 
182
201
  begin
183
202
  # Attempt to acquire with a short timeout - should fail quickly
@@ -190,7 +209,7 @@ class MySQLLockTest < GemTestCase
190
209
  assert_not result
191
210
  assert elapsed < 3.0, "Expected quick timeout, but took #{elapsed} seconds"
192
211
  ensure
193
- other_conn.select_value("SELECT RELEASE_LOCK(#{other_conn.quote(lock_keys.first)})")
212
+ other_conn.query_value("SELECT RELEASE_LOCK(#{other_conn.quote(lock_keys.first)})")
194
213
  model_class.connection_pool.checkin(other_conn)
195
214
  end
196
215
  end
@@ -69,7 +69,7 @@ class MySQLReleaseLockTest < GemTestCase
69
69
 
70
70
  # Acquire lock using SQL (ActiveRecord doesn't provide get_advisory_lock method)
71
71
  lock_keys = model_class.connection.lock_keys_for(lock_name)
72
- result = model_class.connection.select_value("SELECT GET_LOCK(#{model_class.connection.quote(lock_keys.first)}, 0)")
72
+ result = model_class.connection.query_value("SELECT GET_LOCK(#{model_class.connection.quote(lock_keys.first)}, 0)")
73
73
  assert_equal 1, result, 'Failed to acquire lock using SQL'
74
74
 
75
75
  # Release using ActiveRecord signature (positional argument, as Rails does)
@@ -78,11 +78,11 @@ class MySQLReleaseLockTest < GemTestCase
78
78
 
79
79
  # Verify lock is released
80
80
  lock_keys = model_class.connection.lock_keys_for(lock_name)
81
- result = model_class.connection.select_value("SELECT GET_LOCK(#{model_class.connection.quote(lock_keys.first)}, 0)")
81
+ result = model_class.connection.query_value("SELECT GET_LOCK(#{model_class.connection.quote(lock_keys.first)}, 0)")
82
82
  assert_equal 1, result, 'Lock was not properly released'
83
83
 
84
84
  # Clean up
85
- model_class.connection.select_value("SELECT RELEASE_LOCK(#{model_class.connection.quote(lock_keys.first)})")
85
+ model_class.connection.query_value("SELECT RELEASE_LOCK(#{model_class.connection.quote(lock_keys.first)})")
86
86
  end
87
87
 
88
88
  test 'release_advisory_lock handles connection errors gracefully' do
@@ -116,4 +116,3 @@ class MySQLReleaseLockTest < GemTestCase
116
116
  end
117
117
  end
118
118
  end
119
-
@@ -7,8 +7,8 @@ class PostgreSQLTransactionScopingTest < GemTestCase
7
7
 
8
8
  setup do
9
9
  @pg_lock_count = lambda do
10
- backend_pid = Tag.connection.select_value('SELECT pg_backend_pid()')
11
- Tag.connection.select_value("SELECT COUNT(*) FROM pg_locks WHERE locktype = 'advisory' AND pid = #{backend_pid};").to_i
10
+ backend_pid = Tag.connection.query_value('SELECT pg_backend_pid()')
11
+ Tag.connection.query_value("SELECT COUNT(*) FROM pg_locks WHERE locktype = 'advisory' AND pid = #{backend_pid};").to_i
12
12
  end
13
13
  end
14
14
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_advisory_lock
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.1
4
+ version: 7.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew McEachen