gouda 0.1.3 → 0.1.4

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: a8d5d39b730d429fe834fc88ecfe67e3a1bad397022715f6f52a1aa5e050df8b
4
- data.tar.gz: b6cb85e539a387f75e3e84ffe756d54a991755dbd3c4335d67b476d70770eb97
3
+ metadata.gz: cbebec9ae881152e66d8a8e763d74e2314c6694cc46a1b547323bb4fe01fd505
4
+ data.tar.gz: f9836ba9594cf2473485efbe6be8dd6b001e0e514315cb84170a62d525adbaf3
5
5
  SHA512:
6
- metadata.gz: 919a70fddf01f87880289e977b853aad5b01470e4f9b46ef1e8c5867ee50c4751f1ccd6ddc05146c40af83f8c82106d980feb93e022c4871114d7bb01361cee5
7
- data.tar.gz: 466fb4a016ff74b481b936445ea66ed85981520147831b4cb11ec08446b7e7f7962974041f153448248558190ff0b0afb427b37e21af8b915337885ceb37f250
6
+ metadata.gz: 2bf05ef7dcfe8cc682f54da18f8ad8a415f5db3f103928188ad04ab714f4a2799b4998b25c5d53432776d4f913e22fe0a761bd1fe11ea2eb17763f89201cb809
7
+ data.tar.gz: 636a2aa356b4fed48dece844dec2f26d46a430d6e4a0d956c56d5c5121d30f8d3fb8f87174b82e4d7ab6a58f3e0bcd99d3e07c18c631390cc6233b8cac2d48ba
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.3.1
1
+ 3.3.3
data/CHANGELOG.md CHANGED
@@ -15,3 +15,11 @@
15
15
  ## [0.1.3] - 2023-06-11
16
16
 
17
17
  - Allow the Rails app to boot even if there is no database yet
18
+
19
+ ## [0.1.4] - 2023-06-14
20
+
21
+ - Rescue NoDatabaseError at scheduler update.
22
+ - Include tests in gem, for sake of easier debugging.
23
+ - Reduce logging in local test runs.
24
+ - Bump local ruby version to 3.3.3
25
+
data/gouda.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.metadata["changelog_uri"] = "https://github.com/cheddar-me/gouda/CHANGELOG.md"
18
18
 
19
19
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
20
+ `git ls-files -z`.split("\x0")
21
21
  end
22
22
 
23
23
  spec.add_dependency "activerecord", "~> 7"
data/lib/gouda/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gouda
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
@@ -0,0 +1,160 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "gouda/test_helper"
4
+
5
+ class GoudaConcurrencyExtensionTest < ActiveSupport::TestCase
6
+ include AssertHelper
7
+ class TestJobWithoutConcurrency < ActiveJob::Base
8
+ self.queue_adapter = Gouda::Adapter.new
9
+ end
10
+
11
+ class TestJobWithPerformConcurrency < ActiveJob::Base
12
+ self.queue_adapter = Gouda::Adapter.new
13
+ include Gouda::ActiveJobExtensions::Concurrency
14
+ gouda_control_concurrency_with(perform_limit: 1)
15
+
16
+ def perform(*args)
17
+ end
18
+ end
19
+
20
+ setup do
21
+ @adapter ||= Gouda::Adapter.new
22
+ Gouda::Railtie.initializers.each(&:run)
23
+ end
24
+
25
+ test "gouda_control_concurrency_with with just perform_limit sets a perform concurrency key and no enqueue concurrency key" do
26
+ job = TestJobWithPerformConcurrency.new
27
+ assert_nil job.enqueue_concurrency_key
28
+ assert job.execution_concurrency_key
29
+ end
30
+
31
+ test "gouda_control_concurrency_with with just perform_limit makes the perform concurrency key dependent on job params" do
32
+ job1 = TestJobWithPerformConcurrency.new(1, 2, :something)
33
+ assert job1.execution_concurrency_key
34
+
35
+ job2 = TestJobWithPerformConcurrency.new(1, 2, :something)
36
+ assert_equal job2.execution_concurrency_key, job1.execution_concurrency_key
37
+
38
+ job3 = TestJobWithPerformConcurrency.new(1, 2, :something_else)
39
+ refute_equal job3.execution_concurrency_key, job1.execution_concurrency_key
40
+ end
41
+
42
+ class TestJobWithCommonConcurrency < ActiveJob::Base
43
+ self.queue_adapter = Gouda::Adapter.new
44
+ include Gouda::ActiveJobExtensions::Concurrency
45
+ gouda_control_concurrency_with(total_limit: 1)
46
+
47
+ def perform(*args)
48
+ end
49
+ end
50
+
51
+ test "gouda_control_concurrency_with with total_limit sets a perform concurrency key and an enqueue concurrency key" do
52
+ job = TestJobWithCommonConcurrency.new
53
+ assert job.enqueue_concurrency_key
54
+ assert job.execution_concurrency_key
55
+ end
56
+
57
+ test "gouda_control_concurrency_with with total_limit makes the perform concurrency key dependent on job params" do
58
+ job1 = TestJobWithCommonConcurrency.new(1, 2, :something)
59
+ assert job1.execution_concurrency_key
60
+
61
+ job2 = TestJobWithCommonConcurrency.new(1, 2, :something)
62
+ assert_equal job2.execution_concurrency_key, job1.execution_concurrency_key
63
+
64
+ job3 = TestJobWithCommonConcurrency.new(1, 2, :something_else)
65
+ refute_equal job3.execution_concurrency_key, job1.execution_concurrency_key
66
+ end
67
+
68
+ test "gouda_control_concurrency_with with total_limit makes the enqueue concurrency key dependent on job params" do
69
+ job1 = TestJobWithCommonConcurrency.new(1, 2, :something)
70
+ assert job1.enqueue_concurrency_key
71
+
72
+ job2 = TestJobWithCommonConcurrency.new(1, 2, :something)
73
+ assert_equal job2.enqueue_concurrency_key, job1.enqueue_concurrency_key
74
+
75
+ job3 = TestJobWithCommonConcurrency.new(1, 2, :something_else)
76
+ refute_equal job3.enqueue_concurrency_key, job1.enqueue_concurrency_key
77
+ end
78
+
79
+ class TestJobWithEnqueueConcurrency < ActiveJob::Base
80
+ self.queue_adapter = Gouda::Adapter.new
81
+ include Gouda::ActiveJobExtensions::Concurrency
82
+ gouda_control_concurrency_with(enqueue_limit: 1)
83
+
84
+ def perform(*args)
85
+ end
86
+ end
87
+
88
+ test "gouda_control_concurrency_with with enqueue_limit sets a perform concurrency key and an enqueue concurrency key" do
89
+ job = TestJobWithEnqueueConcurrency.new
90
+ assert job.enqueue_concurrency_key
91
+ assert_nil job.execution_concurrency_key
92
+ end
93
+
94
+ test "gouda_control_concurrency_with with enqueue_limit makes the enqueue concurrency key dependent on job params" do
95
+ job1 = TestJobWithEnqueueConcurrency.new(1, 2, :something)
96
+ assert job1.enqueue_concurrency_key
97
+
98
+ job2 = TestJobWithEnqueueConcurrency.new(1, 2, :something)
99
+ assert_equal job2.enqueue_concurrency_key, job1.enqueue_concurrency_key
100
+
101
+ job3 = TestJobWithEnqueueConcurrency.new(1, 2, :something_else)
102
+ refute_equal job3.enqueue_concurrency_key, job1.enqueue_concurrency_key
103
+ end
104
+
105
+ class TestJobWithCustomKey < ActiveJob::Base
106
+ self.queue_adapter = Gouda::Adapter.new
107
+ include Gouda::ActiveJobExtensions::Concurrency
108
+ gouda_control_concurrency_with total_limit: 1, key: "42"
109
+ end
110
+
111
+ test "can use an arbitrary string as the custom key" do
112
+ job = TestJobWithCustomKey.new
113
+ assert_equal "42", job.enqueue_concurrency_key
114
+ assert_equal "42", job.execution_concurrency_key
115
+ end
116
+
117
+ class TestJobWithCustomKeyProc < ActiveJob::Base
118
+ self.queue_adapter = Gouda::Adapter.new
119
+ include Gouda::ActiveJobExtensions::Concurrency
120
+ gouda_control_concurrency_with total_limit: 1, key: -> { @ivar }
121
+
122
+ def initialize(...)
123
+ super
124
+ @ivar = "123"
125
+ end
126
+ end
127
+
128
+ test "can use a proc that gets instance_exec'd as the custom key" do
129
+ job = TestJobWithCustomKeyProc.new
130
+ assert_equal "123", job.enqueue_concurrency_key
131
+ assert_equal "123", job.execution_concurrency_key
132
+ end
133
+
134
+ class TestJobWithWithUnconfiguredConcurrency < ActiveJob::Base
135
+ self.queue_adapter = Gouda::Adapter.new
136
+ include Gouda::ActiveJobExtensions::Concurrency
137
+ end
138
+
139
+ test "validates arguments" do
140
+ assert_raises ArgumentError do
141
+ TestJobWithWithUnconfiguredConcurrency.gouda_control_concurrency_with
142
+ end
143
+
144
+ assert_raises ArgumentError do
145
+ TestJobWithWithUnconfiguredConcurrency.gouda_control_concurrency_with total_limit: 2
146
+ end
147
+
148
+ assert_raises ArgumentError do
149
+ TestJobWithWithUnconfiguredConcurrency.gouda_control_concurrency_with perform_limit: 2
150
+ end
151
+
152
+ assert_raises ArgumentError do
153
+ TestJobWithWithUnconfiguredConcurrency.gouda_control_concurrency_with enqueue_limit: 2
154
+ end
155
+
156
+ assert_raises ArgumentError do
157
+ TestJobWithWithUnconfiguredConcurrency.gouda_control_concurrency_with total_limit: 2, bollocks: 4
158
+ end
159
+ end
160
+ end