File tree 2 files changed +13
-0
lines changed
2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ class PostgreSQL < Base
5
5
# See http://www.postgresql.org/docs/9.1/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS
6
6
def try_lock
7
7
pg_function = "pg_try_advisory#{ transaction ? '_xact' : '' } _lock#{ shared ? '_shared' : '' } "
8
+
9
+ raise "#{ pg_function } requires transaction" if transaction && !ActiveRecord ::Base . connection . transaction_open?
10
+
8
11
execute_successful? ( pg_function )
9
12
end
10
13
Original file line number Diff line number Diff line change @@ -69,5 +69,15 @@ def pg_lock_count
69
69
end
70
70
assert_equal ( 0 , pg_lock_count )
71
71
end
72
+
73
+ specify 'transaction level locks fail if not in transaction' do
74
+ exception = assert_raises do
75
+ Tag . with_advisory_lock 'test' , transaction : true do
76
+ raise 'should not get here'
77
+ end
78
+ end
79
+
80
+ assert_match ( /#{ Regexp . escape ( 'requires transaction' ) } / , exception . message )
81
+ end
72
82
end
73
83
end
You can’t perform that action at this time.
0 commit comments