activejob-locking 0.4.0 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,11 @@
1
- require_relative('./serialized_tests')
2
-
3
- class SerializedMemory < MiniTest::Test
4
- include SerializedTests
5
-
6
- def setup
7
- ActiveJob::Base.queue_adapter = :test
8
- ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
9
- ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::Memory
10
- end
1
+ require_relative('./serialized_tests')
2
+
3
+ class SerializedMemory < MiniTest::Test
4
+ include SerializedTests
5
+
6
+ def setup
7
+ ActiveJob::Base.queue_adapter = :test
8
+ ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
9
+ ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::Memory
10
+ end
11
11
  end
@@ -1,12 +1,12 @@
1
- require_relative('./serialized_tests')
2
-
3
- class UniqueRedisSemaphoreTest < MiniTest::Test
4
- include SerializedTests
5
-
6
- def setup
7
- redis_reset
8
- ActiveJob::Base.queue_adapter = :test
9
- ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
10
- ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::RedisSemaphore
11
- end
1
+ require_relative('./serialized_tests')
2
+
3
+ class UniqueRedisSemaphoreTest < MiniTest::Test
4
+ include SerializedTests
5
+
6
+ def setup
7
+ redis_reset
8
+ ActiveJob::Base.queue_adapter = :test
9
+ ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
10
+ ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::RedisSemaphore
11
+ end
12
12
  end
@@ -1,14 +1,14 @@
1
- require_relative('./serialized_tests')
2
-
3
- class SerializedRedlockTest < MiniTest::Test
4
- include SerializedTests
5
-
6
- def setup
7
- redis_reset
8
-
9
- ActiveJob::Base.queue_adapter = :test
10
- ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
11
- ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::Redlock
12
- ActiveJob::Locking.options.hosts = Redlock::Client::DEFAULT_REDIS_URLS
13
- end
1
+ require_relative('./serialized_tests')
2
+
3
+ class SerializedRedlockTest < MiniTest::Test
4
+ include SerializedTests
5
+
6
+ def setup
7
+ redis_reset
8
+
9
+ ActiveJob::Base.queue_adapter = :test
10
+ ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
11
+ ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::Redlock
12
+ ActiveJob::Locking.options.hosts = Redlock::Client::DEFAULT_REDIS_URLS
13
+ end
14
14
  end
@@ -1,12 +1,12 @@
1
- require_relative('./serialized_tests')
2
-
3
- class SerializedSuoRedisTest < MiniTest::Test
4
- include SerializedTests
5
-
6
- def setup
7
- redis_reset
8
- ActiveJob::Base.queue_adapter = :test
9
- ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
10
- ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::SuoRedis
11
- end
1
+ require_relative('./serialized_tests')
2
+
3
+ class SerializedSuoRedisTest < MiniTest::Test
4
+ include SerializedTests
5
+
6
+ def setup
7
+ redis_reset
8
+ ActiveJob::Base.queue_adapter = :test
9
+ ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
10
+ ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::SuoRedis
11
+ end
12
12
  end
@@ -1,12 +1,12 @@
1
- %w(
2
- test_serialized_memory
3
- test_serialized_redis_semaphore
4
- test_serialized_redlock
5
- test_serialized_suo_redis
6
- test_unique_memory
7
- test_unique_redis_semaphore
8
- test_unique_redlock
9
- test_unique_suo_redis
10
- ).each do |test|
11
- require File.expand_path("../#{test}", __FILE__)
12
- end
1
+ %w(
2
+ test_serialized_memory
3
+ test_serialized_redis_semaphore
4
+ test_serialized_redlock
5
+ test_serialized_suo_redis
6
+ test_unique_memory
7
+ test_unique_redis_semaphore
8
+ test_unique_redlock
9
+ test_unique_suo_redis
10
+ ).each do |test|
11
+ require File.expand_path("../#{test}", __FILE__)
12
+ end
@@ -1,12 +1,12 @@
1
- require_relative('./unique_tests')
2
-
3
- class UniqueMemoryTest < MiniTest::Test
4
- include UniqueTests
5
-
6
- def setup
7
- ActiveJob::Locking::Adapters::Memory.reset
8
- ActiveJob::Base.queue_adapter = :test
9
- ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
10
- ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::Memory
11
- end
12
- end
1
+ require_relative('./unique_tests')
2
+
3
+ class UniqueMemoryTest < MiniTest::Test
4
+ include UniqueTests
5
+
6
+ def setup
7
+ ActiveJob::Locking::Adapters::Memory.reset
8
+ ActiveJob::Base.queue_adapter = :test
9
+ ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
10
+ ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::Memory
11
+ end
12
+ end
@@ -1,12 +1,12 @@
1
- require_relative('./unique_tests')
2
-
3
- class UniqueRedisSemaphoreTest < MiniTest::Test
4
- include UniqueTests
5
-
6
- def setup
7
- redis_reset
8
- ActiveJob::Base.queue_adapter = :test
9
- ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
10
- ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::RedisSemaphore
11
- end
1
+ require_relative('./unique_tests')
2
+
3
+ class UniqueRedisSemaphoreTest < MiniTest::Test
4
+ include UniqueTests
5
+
6
+ def setup
7
+ redis_reset
8
+ ActiveJob::Base.queue_adapter = :test
9
+ ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
10
+ ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::RedisSemaphore
11
+ end
12
12
  end
@@ -1,14 +1,14 @@
1
- require_relative('./unique_tests')
2
-
3
- class UniqueRedlockTest < MiniTest::Test
4
- include UniqueTests
5
-
6
- def setup
7
- redis_reset
8
-
9
- ActiveJob::Base.queue_adapter = :test
10
- ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
11
- ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::Redlock
12
- ActiveJob::Locking.options.hosts = Redlock::Client::DEFAULT_REDIS_URLS
13
- end
1
+ require_relative('./unique_tests')
2
+
3
+ class UniqueRedlockTest < MiniTest::Test
4
+ include UniqueTests
5
+
6
+ def setup
7
+ redis_reset
8
+
9
+ ActiveJob::Base.queue_adapter = :test
10
+ ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
11
+ ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::Redlock
12
+ ActiveJob::Locking.options.hosts = Redlock::Client::DEFAULT_REDIS_URLS
13
+ end
14
14
  end
@@ -1,12 +1,12 @@
1
- require_relative('./unique_tests')
2
-
3
- class UniqueSuoRedisTest < MiniTest::Test
4
- include UniqueTests
5
-
6
- def setup
7
- redis_reset
8
- ActiveJob::Base.queue_adapter = :test
9
- ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
10
- ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::SuoRedis
11
- end
1
+ require_relative('./unique_tests')
2
+
3
+ class UniqueSuoRedisTest < MiniTest::Test
4
+ include UniqueTests
5
+
6
+ def setup
7
+ redis_reset
8
+ ActiveJob::Base.queue_adapter = :test
9
+ ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
10
+ ActiveJob::Locking.options.adapter = ActiveJob::Locking::Adapters::SuoRedis
11
+ end
12
12
  end
@@ -1,100 +1,100 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- module UniqueTests
4
- def test_none_performed
5
- ActiveJob::Base.queue_adapter.perform_enqueued_jobs = false
6
-
7
- assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
8
- assert_equal(0, ActiveJob::Base.queue_adapter.performed_jobs.count)
9
-
10
- sleep_time = UniqueJob.lock_acquire_time
11
- threads = 3.times.map do |i|
12
- Thread.new do
13
- UniqueJob.perform_later(i, sleep_time)
14
- end
15
- end
16
-
17
- threads.each {|thread| thread.join}
18
- assert_equal(1, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
19
- assert_equal(0, ActiveJob::Base.queue_adapter.performed_jobs.count)
20
- ensure
21
- ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
22
- ActiveJob::Base.queue_adapter.enqueued_jobs.clear
23
- end
24
-
25
- def test_one_performed
26
- assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
27
- assert_equal(0, ActiveJob::Base.queue_adapter.performed_jobs.count)
28
-
29
- sleep_time = UniqueJob.lock_acquire_time * 2
30
- threads = 3.times.map do |i|
31
- Thread.new do
32
- UniqueJob.perform_later(i, sleep_time)
33
- end
34
- end
35
-
36
- threads.each {|thread| thread.join}
37
- assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
38
- assert_equal(1, ActiveJob::Base.queue_adapter.performed_jobs.count)
39
- end
40
-
41
- def test_all_performed
42
- assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
43
- assert_equal(0, ActiveJob::Base.queue_adapter.performed_jobs.count)
44
-
45
- start_time = Time.now
46
- sleep_time = UniqueJob.lock_acquire_time / 4.0
47
- threads = 3.times.map do |i|
48
- Thread.new do
49
- UniqueJob.perform_later(i, sleep_time)
50
- end
51
- end
52
-
53
- threads.each {|thread| thread.join}
54
-
55
- assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
56
- assert_equal(threads.count, ActiveJob::Base.queue_adapter.performed_jobs.count)
57
- assert(Time.now - start_time > (threads.count * sleep_time))
58
- end
59
-
60
- def test_some_performed
61
- assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
62
- assert_equal(0, ActiveJob::Base.queue_adapter.performed_jobs.count)
63
-
64
- start_time = Time.now
65
- sleep_time = UniqueJob.lock_acquire_time / 2.0
66
- threads = 3.times.map do |i|
67
- Thread.new do
68
- UniqueJob.perform_later(i, sleep_time)
69
- end
70
- end
71
-
72
- threads.each {|thread| thread.join}
73
-
74
- assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
75
- assert_equal(threads.count - 1, ActiveJob::Base.queue_adapter.performed_jobs.count)
76
- assert(Time.now - start_time > ((threads.count - 1) * sleep_time))
77
- end
78
-
79
- def test_fail
80
- assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
81
- assert_equal(0, ActiveJob::Base.queue_adapter.performed_jobs.count)
82
-
83
- start_time = Time.now
84
- sleep_time = UniqueJob.lock_acquire_time
85
- threads = 3.times.map do |i|
86
- Thread.new do
87
- begin
88
- FailJob.perform_later(i, sleep_time)
89
- rescue => e
90
- # do nothing
91
- end
92
- end
93
- end
94
-
95
- threads.each {|thread| thread.join}
96
-
97
- assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
98
- assert_equal(threads.count, ActiveJob::Base.queue_adapter.performed_jobs.count)
99
- end
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ module UniqueTests
4
+ def test_none_performed
5
+ ActiveJob::Base.queue_adapter.perform_enqueued_jobs = false
6
+
7
+ assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
8
+ assert_equal(0, ActiveJob::Base.queue_adapter.performed_jobs.count)
9
+
10
+ sleep_time = UniqueJob.lock_acquire_time
11
+ threads = 3.times.map do |i|
12
+ Thread.new do
13
+ UniqueJob.perform_later(i, sleep_time)
14
+ end
15
+ end
16
+
17
+ threads.each {|thread| thread.join}
18
+ assert_equal(1, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
19
+ assert_equal(0, ActiveJob::Base.queue_adapter.performed_jobs.count)
20
+ ensure
21
+ ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
22
+ ActiveJob::Base.queue_adapter.enqueued_jobs.clear
23
+ end
24
+
25
+ def test_one_performed
26
+ assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
27
+ assert_equal(0, ActiveJob::Base.queue_adapter.performed_jobs.count)
28
+
29
+ sleep_time = UniqueJob.lock_acquire_time * 2
30
+ threads = 3.times.map do |i|
31
+ Thread.new do
32
+ UniqueJob.perform_later(i, sleep_time)
33
+ end
34
+ end
35
+
36
+ threads.each {|thread| thread.join}
37
+ assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
38
+ assert_equal(1, ActiveJob::Base.queue_adapter.performed_jobs.count)
39
+ end
40
+
41
+ def test_all_performed
42
+ assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
43
+ assert_equal(0, ActiveJob::Base.queue_adapter.performed_jobs.count)
44
+
45
+ start_time = Time.now
46
+ sleep_time = UniqueJob.lock_acquire_time / 4.0
47
+ threads = 3.times.map do |i|
48
+ Thread.new do
49
+ UniqueJob.perform_later(i, sleep_time)
50
+ end
51
+ end
52
+
53
+ threads.each {|thread| thread.join}
54
+
55
+ assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
56
+ assert_equal(threads.count, ActiveJob::Base.queue_adapter.performed_jobs.count)
57
+ assert(Time.now - start_time > (threads.count * sleep_time))
58
+ end
59
+
60
+ def test_some_performed
61
+ assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
62
+ assert_equal(0, ActiveJob::Base.queue_adapter.performed_jobs.count)
63
+
64
+ start_time = Time.now
65
+ sleep_time = UniqueJob.lock_acquire_time / 2.0
66
+ threads = 3.times.map do |i|
67
+ Thread.new do
68
+ UniqueJob.perform_later(i, sleep_time)
69
+ end
70
+ end
71
+
72
+ threads.each {|thread| thread.join}
73
+
74
+ assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
75
+ assert_equal(threads.count - 1, ActiveJob::Base.queue_adapter.performed_jobs.count)
76
+ assert(Time.now - start_time > ((threads.count - 1) * sleep_time))
77
+ end
78
+
79
+ def test_fail
80
+ assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
81
+ assert_equal(0, ActiveJob::Base.queue_adapter.performed_jobs.count)
82
+
83
+ start_time = Time.now
84
+ sleep_time = UniqueJob.lock_acquire_time
85
+ threads = 3.times.map do |i|
86
+ Thread.new do
87
+ begin
88
+ FailJob.perform_later(i, sleep_time)
89
+ rescue => e
90
+ # do nothing
91
+ end
92
+ end
93
+ end
94
+
95
+ threads.each {|thread| thread.join}
96
+
97
+ assert_equal(0, ActiveJob::Base.queue_adapter.enqueued_jobs.count)
98
+ assert_equal(threads.count, ActiveJob::Base.queue_adapter.performed_jobs.count)
99
+ end
100
100
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob-locking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Savage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-23 00:00:00.000000000 Z
11
+ date: 2020-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.1
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.1
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 5.10.0
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 5.10.0
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: redis-mutex
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -153,8 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0'
155
155
  requirements: []
156
- rubyforge_project:
157
- rubygems_version: 2.6.11
156
+ rubygems_version: 3.1.2
158
157
  signing_key:
159
158
  specification_version: 4
160
159
  summary: ActiveJob locking to control how jobs are enqueued and performed.