|
3 | 3 | require 'test_helper'
|
4 | 4 |
|
5 | 5 | 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 | + |
6 | 51 | def test_retry_if_lock_timeout
|
7 | 52 | calls = calls_for_lock_timeout_migration
|
8 | 53 |
|
@@ -33,32 +78,6 @@ def test_statement_retry
|
33 | 78 | ], calls[7..9]
|
34 | 79 | end
|
35 | 80 |
|
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 |
| - |
62 | 81 | private
|
63 | 82 |
|
64 | 83 | def calls_for_lock_timeout_migration
|
|
0 commit comments