Skip to content

Commit 7a7f854

Browse files
Add tests
1 parent aeab5ae commit 7a7f854

File tree

1 file changed

+45
-26
lines changed

1 file changed

+45
-26
lines changed

test/statement_retrier_test.rb

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,51 @@
33
require 'test_helper'
44

55
class StatementRetrierTest < Minitest::Test
6+
7+
def test_lock_timeout_increase_on_retry
8+
SafePgMigrations.config.lock_timeout = 0.1.seconds
9+
SafePgMigrations.config.increase_lock_timeout_on_retry = true
10+
11+
calls = calls_for_lock_timeout_migration
12+
13+
assert_equal [
14+
' -> Retrying in 60 seconds...',
15+
' -> Increasing the lock timeout... Currently set to 0.1',
16+
' -> Lock timeout is now set to 0.325',
17+
' -> Retrying now.',
18+
' -> Retrying in 60 seconds...',
19+
' -> Increasing the lock timeout... Currently set to 0.325',
20+
' -> Lock timeout is now set to 0.55',
21+
' -> Retrying now.',
22+
' -> Retrying in 60 seconds...',
23+
' -> Increasing the lock timeout... Currently set to 0.55',
24+
' -> Lock timeout is now set to 0.775',
25+
' -> Retrying now.',
26+
' -> Retrying in 60 seconds...',
27+
' -> Increasing the lock timeout... Currently set to 0.775',
28+
' -> Lock timeout is now set to 1',
29+
' -> Retrying now.',
30+
], calls[1..-1].map(&:first)
31+
end
32+
33+
def test_no_lock_timeout_increase_on_retry_if_disabled
34+
SafePgMigrations.config.lock_timeout = 0.1.seconds
35+
SafePgMigrations.config.increase_lock_timeout_on_retry = false
36+
37+
calls = calls_for_lock_timeout_migration
38+
39+
assert_equal [
40+
' -> Retrying in 60 seconds...',
41+
' -> Retrying now.',
42+
' -> Retrying in 60 seconds...',
43+
' -> Retrying now.',
44+
' -> Retrying in 60 seconds...',
45+
' -> Retrying now.',
46+
' -> Retrying in 60 seconds...',
47+
' -> Retrying now.',
48+
], calls[1..-1].map(&:first)
49+
end
50+
651
def test_retry_if_lock_timeout
752
calls = calls_for_lock_timeout_migration
853

@@ -33,32 +78,6 @@ def test_statement_retry
3378
], calls[7..9]
3479
end
3580

36-
def test_lock_timout_increase_on_retry
37-
SafePgMigrations.config.lock_timeout = 0.1.seconds
38-
39-
calls = calls_for_lock_timeout_migration
40-
41-
assert_equal [
42-
' -> Retrying in 60 seconds...',
43-
' -> Increasing the lock timeout... Currently set to 0.1',
44-
' -> Lock timeout is now set to 0.325',
45-
' -> Retrying now.',
46-
' -> Retrying in 60 seconds...',
47-
' -> Increasing the lock timeout... Currently set to 0.325',
48-
' -> Lock timeout is now set to 0.55',
49-
' -> Retrying now.',
50-
' -> Retrying in 60 seconds...',
51-
' -> Increasing the lock timeout... Currently set to 0.55',
52-
' -> Lock timeout is now set to 0.775',
53-
' -> Retrying now.',
54-
' -> Retrying in 60 seconds...',
55-
' -> Increasing the lock timeout... Currently set to 0.775',
56-
' -> Lock timeout is now set to 1',
57-
' -> Retrying now.',
58-
], calls[1..-1].map(&:first)
59-
60-
end
61-
6281
private
6382

6483
def calls_for_lock_timeout_migration

0 commit comments

Comments
 (0)