gouda 0.1.3 → 0.1.5

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.
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "gouda/test_helper"
4
+
5
+ class GoudaWorkloadTest < ActiveSupport::TestCase
6
+ include AssertHelper
7
+
8
+ class TestJob < ActiveJob::Base
9
+ self.queue_adapter = Gouda::Adapter.new
10
+
11
+ def perform
12
+ end
13
+ end
14
+
15
+ test "#schedule_now!" do
16
+ freeze_time
17
+ create_enqueued_workload
18
+ create_enqueued_workload
19
+ workload = create_enqueued_workload
20
+ workload.schedule_now!
21
+ assert_equal 3, Gouda::Workload.enqueued.size
22
+ assert_equal Time.now.utc, workload.scheduled_at
23
+ end
24
+
25
+ test "#mark_finished!" do
26
+ freeze_time
27
+ create_enqueued_workload
28
+ create_enqueued_workload
29
+ workload = create_enqueued_workload
30
+ workload.mark_finished!
31
+ assert_equal 2, Gouda::Workload.enqueued.size
32
+ assert_equal 1, Gouda::Workload.finished.size
33
+ assert_equal 1, Gouda::Workload.errored.size
34
+ assert_equal Time.now.utc, workload.execution_finished_at
35
+ end
36
+
37
+ def create_enqueued_workload
38
+ now = Time.now.utc
39
+ test_job = TestJob.new
40
+
41
+ Gouda::Workload.create!(
42
+ scheduled_at: now + 1.hour,
43
+ active_job_id: test_job.job_id,
44
+ execution_started_at: nil,
45
+ last_execution_heartbeat_at: nil,
46
+ queue_name: "default",
47
+ active_job_class_name: "GoudaWorkloadTest::TestJob",
48
+ serialized_params: {
49
+ job_id: test_job.job_id,
50
+ locale: "en",
51
+ priority: nil,
52
+ timezone: "UTC",
53
+ arguments: [],
54
+ job_class: test_job.class.to_s,
55
+ executions: 0,
56
+ queue_name: "default",
57
+ enqueued_at: now - 1.hour,
58
+ exception_executions: {}
59
+ },
60
+ state: "enqueued",
61
+ execution_concurrency_key: nil,
62
+ enqueue_concurrency_key: nil,
63
+ executing_on: "unit test",
64
+ position_in_bulk: 0
65
+ )
66
+ end
67
+ end
@@ -0,0 +1,51 @@
1
+ module AssertHelper
2
+ # Same as "assert_changes" in Rails but for countable entities.
3
+ # @return [*] return value of the block
4
+ # @example
5
+ # assert_changes_by("Notification.count", exactly: 2) do
6
+ # cause_two_notifications_to_get_delivered
7
+ # end
8
+ def assert_changes_by(expression, message = nil, exactly: nil, at_least: nil, at_most: nil, &block)
9
+ # rubocop:disable Security/Eval
10
+ exp = expression.respond_to?(:call) ? expression : -> { eval(expression.to_s, block.binding) }
11
+ # rubocop:enable Security/Eval
12
+
13
+ raise "either exactly:, at_least: or at_most: must be specified" unless exactly || at_least || at_most
14
+ raise "exactly: is mutually exclusive with other options" if exactly && (at_least || at_most)
15
+ raise "at_most: must be larger than at_least:" if at_least && at_most && at_most < at_least
16
+
17
+ before = exp.call
18
+ retval = assert_nothing_raised(&block)
19
+
20
+ after = exp.call
21
+ delta = after - before
22
+
23
+ if exactly
24
+ at_most = exactly
25
+ at_least = exactly
26
+ end
27
+
28
+ # We do not make these an if/else since we allow both at_most and at_least
29
+ if at_most
30
+ error = "#{expression.inspect} changed by #{delta} which is more than #{at_most}"
31
+ error = "#{error}. It was #{before} and became #{after}"
32
+ error = "#{message.call}.\n" if message&.respond_to?(:call)
33
+ error = "#{message}.\n#{error}" if message && !message.respond_to?(:call)
34
+ assert delta <= at_most, error
35
+ end
36
+
37
+ if at_least
38
+ error = "#{expression.inspect} changed by #{delta} which is less than #{at_least}"
39
+ error = "#{error}. It was #{before} and became #{after}"
40
+ error = "#{message.call}.\n" if message&.respond_to?(:call)
41
+ error = "#{message}.\n#{error}" if message && !message.respond_to?(:call)
42
+ assert delta >= at_least, error
43
+ end
44
+
45
+ retval
46
+ end
47
+
48
+ def assert_same_set(exp, act, msg = nil)
49
+ assert_equal(exp.to_set, act.to_set, msg)
50
+ end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gouda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian van Hesteren
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-06-11 00:00:00.000000000 Z
12
+ date: 2024-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -157,13 +157,21 @@ files:
157
157
  - lib/gouda/version.rb
158
158
  - lib/gouda/worker.rb
159
159
  - lib/gouda/workload.rb
160
+ - test/gouda/concurrency_extension_test.rb
161
+ - test/gouda/gouda_test.rb
162
+ - test/gouda/scheduler_test.rb
163
+ - test/gouda/seconds_to_start_distribution.csv
164
+ - test/gouda/test_helper.rb
165
+ - test/gouda/worker_test.rb
166
+ - test/gouda/workload_test.rb
167
+ - test/support/assert_helper.rb
160
168
  - tmp/.keep
161
- homepage: https://rubygems.org/gems/gouda
169
+ homepage: https://github.com/cheddar-me/gouda
162
170
  licenses:
163
171
  - MIT
164
172
  metadata:
165
- homepage_uri: https://rubygems.org/gems/gouda
166
173
  source_code_uri: https://github.com/cheddar-me/gouda
174
+ homepage_uri: https://github.com/cheddar-me/gouda
167
175
  changelog_uri: https://github.com/cheddar-me/gouda/CHANGELOG.md
168
176
  post_install_message:
169
177
  rdoc_options: []
@@ -180,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
188
  - !ruby/object:Gem::Version
181
189
  version: '0'
182
190
  requirements: []
183
- rubygems_version: 3.5.9
191
+ rubygems_version: 3.5.11
184
192
  signing_key:
185
193
  specification_version: 4
186
194
  summary: Job Scheduler