with_advisory_lock 4.6.0 → 5.3.0

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci-mysql5.yml +61 -0
  3. data/.github/workflows/ci-mysql8.yml +62 -0
  4. data/.github/workflows/ci-postgresql.yml +64 -0
  5. data/.github/workflows/ci-sqlite3.yml +54 -0
  6. data/.github/workflows/release.yml +17 -0
  7. data/.gitignore +2 -0
  8. data/.release-please-manifest.json +1 -0
  9. data/.ruby-version +2 -0
  10. data/.tool-versions +1 -1
  11. data/Appraisals +34 -18
  12. data/CHANGELOG.md +50 -0
  13. data/Gemfile +0 -12
  14. data/LICENSE.txt +4 -4
  15. data/Makefile +14 -0
  16. data/README.md +17 -6
  17. data/docker-compose.yml +20 -0
  18. data/gemfiles/{activerecord_6.0.gemfile → activerecord_6.1.gemfile} +4 -2
  19. data/gemfiles/{activerecord_5.2.gemfile → activerecord_7.0.gemfile} +4 -2
  20. data/gemfiles/activerecord_7.1.gemfile +14 -0
  21. data/lib/with_advisory_lock/base.rb +18 -4
  22. data/lib/with_advisory_lock/concern.rb +17 -17
  23. data/lib/with_advisory_lock/database_adapter_support.rb +7 -47
  24. data/lib/with_advisory_lock/failed_to_acquire_lock.rb +9 -0
  25. data/lib/with_advisory_lock/flock.rb +4 -3
  26. data/lib/with_advisory_lock/mysql.rb +12 -7
  27. data/lib/with_advisory_lock/postgresql.rb +43 -18
  28. data/lib/with_advisory_lock/version.rb +3 -1
  29. data/lib/with_advisory_lock.rb +9 -10
  30. data/release-please-config.json +9 -0
  31. data/test/test_helper.rb +66 -0
  32. data/test/test_models.rb +16 -10
  33. data/test/with_advisory_lock/base_test.rb +9 -0
  34. data/test/with_advisory_lock/concern_test.rb +33 -0
  35. data/test/with_advisory_lock/lock_test.rb +111 -0
  36. data/test/with_advisory_lock/nesting_test.rb +28 -0
  37. data/test/with_advisory_lock/options_test.rb +66 -0
  38. data/test/with_advisory_lock/parallelism_test.rb +75 -0
  39. data/test/with_advisory_lock/shared_test.rb +134 -0
  40. data/test/with_advisory_lock/thread_test.rb +61 -0
  41. data/test/with_advisory_lock/transaction_test.rb +68 -0
  42. data/with_advisory_lock.gemspec +29 -23
  43. metadata +56 -47
  44. data/.travis.yml +0 -38
  45. data/gemfiles/activerecord_4.2.gemfile +0 -19
  46. data/gemfiles/activerecord_5.0.gemfile +0 -19
  47. data/gemfiles/activerecord_5.1.gemfile +0 -19
  48. data/lib/with_advisory_lock/mysql_no_nesting.rb +0 -20
  49. data/lib/with_advisory_lock/nested_advisory_lock_error.rb +0 -14
  50. data/test/concern_test.rb +0 -20
  51. data/test/database.yml +0 -17
  52. data/test/lock_test.rb +0 -47
  53. data/test/minitest_helper.rb +0 -40
  54. data/test/nesting_test.rb +0 -93
  55. data/test/options_test.rb +0 -64
  56. data/test/parallelism_test.rb +0 -77
  57. data/test/shared_test.rb +0 -131
  58. data/test/thread_test.rb +0 -60
  59. data/test/transaction_test.rb +0 -70
  60. data/tests.sh +0 -11
@@ -1,70 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe 'transaction scoping' do
4
- def supported?
5
- env_db == :postgresql
6
- end
7
-
8
- describe 'not supported' do
9
- before do
10
- skip if supported?
11
- end
12
-
13
- it 'raises an error when attempting to use transaction level locks' do
14
- Tag.transaction do
15
- exception = proc {
16
- Tag.with_advisory_lock 'test', transaction: true do
17
- raise 'should not get here'
18
- end
19
- }.must_raise ArgumentError
20
- exception.message.must_include 'not supported'
21
- end
22
- end
23
- end
24
-
25
- describe 'supported' do
26
- before do
27
- skip unless env_db == :postgresql
28
- end
29
-
30
- def pg_lock_count
31
- ActiveRecord::Base.connection.select_value("SELECT COUNT(*) FROM pg_locks WHERE locktype = 'advisory';").to_i
32
- end
33
-
34
- specify 'session locks release after the block executes' do
35
- Tag.transaction do
36
- pg_lock_count.must_equal 0
37
- Tag.with_advisory_lock 'test' do
38
- pg_lock_count.must_equal 1
39
- end
40
- pg_lock_count.must_equal 0
41
- end
42
- end
43
-
44
- specify 'session locks release when transaction fails inside block' do
45
- Tag.transaction do
46
- pg_lock_count.must_equal 0
47
-
48
- exception = proc {
49
- Tag.with_advisory_lock 'test' do
50
- Tag.connection.execute 'SELECT 1/0;'
51
- end
52
- }.must_raise ActiveRecord::StatementInvalid
53
- exception.message.must_include 'division by zero'
54
-
55
- pg_lock_count.must_equal 0
56
- end
57
- end
58
-
59
- specify 'transaction level locks hold until the transaction completes' do
60
- Tag.transaction do
61
- pg_lock_count.must_equal 0
62
- Tag.with_advisory_lock 'test', transaction: true do
63
- pg_lock_count.must_equal 1
64
- end
65
- pg_lock_count.must_equal 1
66
- end
67
- pg_lock_count.must_equal 0
68
- end
69
- end
70
- end
data/tests.sh DELETED
@@ -1,11 +0,0 @@
1
- #!/bin/bash -e
2
- export DB
3
-
4
- for RUBY in 2.4.0 jruby-1.7.13 ; do
5
- rbenv local $RUBY
6
- for DB in mysql postgresql sqlite ; do
7
- echo "$DB | $(ruby -v)"
8
- # appraisal bundle update
9
- appraisal rake test --verbose
10
- done
11
- done