delayed 2.0.1 → 2.0.3

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.
@@ -33,35 +33,50 @@ describe Delayed::Helpers::Migration do
33
33
  migration.migration_start = Delayed::Job.db_time_now
34
34
  end
35
35
 
36
- describe '#with_retry_loop timeout tracking' do
36
+ describe '#upsert_index retry behavior' do
37
37
  it 'raises exception when wait_timeout is exceeded based on @migration_start' do
38
- # Simulate migration that started 6 minutes ago
39
38
  migration.migration_start = Delayed::Job.db_time_now - 6.minutes
40
39
 
40
+ allow(migration).to receive(:add_index).and_raise(ActiveRecord::LockWaitTimeout)
41
+ allow(migration.connection).to receive(:indexes).and_return([])
42
+
41
43
  expect {
42
- migration.with_retry_loop(wait_timeout: 5.minutes) do
43
- raise ActiveRecord::LockWaitTimeout
44
- end
44
+ migration.upsert_index(:delayed_jobs, :name, wait_timeout: 5.minutes)
45
45
  }.to raise_error(ActiveRecord::LockWaitTimeout)
46
46
  end
47
47
 
48
- it 'continues retrying while within the timeout window' do
49
- call_count = 0
48
+ it 're-checks for invalid index and drops it before retrying after timeout' do
49
+ add_index_calls = 0
50
+ remove_index_calls = 0
51
+ lookup_calls = 0
50
52
 
51
- # First retry is within timeout, second exceeds it
52
- allow(Delayed::Job).to receive(:db_time_now).and_return(
53
- migration.migration_start + 4.minutes, # Within timeout
54
- migration.migration_start + 6.minutes, # Exceeds timeout
53
+ invalid_opts = ActiveRecord.version >= Gem::Version.new('7.1.0') ? { valid?: false } : { unique: true }
54
+ invalid_index = instance_double(
55
+ ActiveRecord::ConnectionAdapters::IndexDefinition,
56
+ name: 'test_idx',
57
+ columns: ['name'],
58
+ **invalid_opts,
55
59
  )
56
60
 
57
- expect {
58
- migration.with_retry_loop(wait_timeout: 5.minutes) do
59
- call_count += 1
60
- raise ActiveRecord::LockWaitTimeout
61
- end
62
- }.to raise_error(ActiveRecord::LockWaitTimeout)
61
+ allow(migration.connection).to receive(:indexes) do
62
+ lookup_calls += 1
63
+ lookup_calls == 2 ? [invalid_index] : []
64
+ end
65
+
66
+ allow(migration).to receive(:add_index) do |*_args|
67
+ add_index_calls += 1
68
+ raise ActiveRecord::StatementTimeout, 'timeout' if add_index_calls == 1
69
+ end
70
+
71
+ allow(migration).to receive(:remove_index) do |*_args|
72
+ remove_index_calls += 1
73
+ end
74
+
75
+ migration.upsert_index(:delayed_jobs, :name, name: 'test_idx', wait_timeout: 5.minutes)
63
76
 
64
- expect(call_count).to eq(2)
77
+ expect(lookup_calls).to eq(3)
78
+ expect(remove_index_calls).to eq(1)
79
+ expect(add_index_calls).to eq(2)
65
80
  end
66
81
  end
67
82
  end
data/spec/helper.rb CHANGED
@@ -279,6 +279,8 @@ QueryUnderTest = Struct.new(:sql, :connection) do
279
279
  .gsub(/ (AND|OR) /) { "\n #{Regexp.last_match(1).strip} " }
280
280
  # normalize and truncate 'AS' names/aliases (changes across Rails versions)
281
281
  .gsub(/AS ("|`)?(\w+)("|`)?/) { "AS #{Regexp.last_match(2)[0...63]}" }
282
+ # remove quotes around column names in aggregate functions
283
+ .gsub(/(MIN|MAX|COUNT|SUM)\(("|`)(\w+)("|`)\)/) { "#{Regexp.last_match(1)}(#{Regexp.last_match(3)})" }
282
284
  end
283
285
 
284
286
  def explain
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Griffith
@@ -19,7 +19,7 @@ authors:
19
19
  autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
- date: 2026-01-05 00:00:00.000000000 Z
22
+ date: 2026-02-02 00:00:00.000000000 Z
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
25
  name: activerecord