@@ -24,21 +24,25 @@ def change
24
24
25
25
it 'runs migrate up with timeout' do
26
26
migration = AddFoo . new
27
+ expect ( ActiveRecord ::Base . connection ) . to receive ( :execute ) .
28
+ with ( "CREATE TABLE \" foo\" (\" id\" serial primary key, \" created_at\" timestamp, \" updated_at\" timestamp) " )
27
29
expect ( ActiveRecord ::Base . connection ) . to receive ( :execute ) .
28
30
with ( "SET LOCAL lock_timeout = '5s'" )
29
31
migration . migrate ( :up )
30
32
end
31
33
32
34
it 'does not use timeout for down migration' do
33
35
migration = AddFoo . new
34
- expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute )
36
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
37
+ with ( "SET LOCAL lock_timeout = '5s'" )
35
38
migration . migrate ( :down )
36
39
end
37
40
38
41
it 'allows migration to run if no default timeout set' do
39
42
MigrationLockTimeout . config = nil
40
43
migration = AddFoo . new
41
- expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute )
44
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
45
+ with ( "SET LOCAL lock_timeout = '5s'" )
42
46
migration . migrate ( :up )
43
47
end
44
48
end
@@ -60,13 +64,111 @@ def down
60
64
it 'runs migrate up with timeout' do
61
65
migration = AddBar . new
62
66
expect ( ActiveRecord ::Base . connection ) . to receive ( :execute ) .
67
+ with ( "CREATE TABLE \" bar\" (\" id\" serial primary key, \" created_at\" timestamp, \" updated_at\" timestamp) " )
68
+ expect ( ActiveRecord ::Base . connection ) . to receive ( :execute ) .
69
+ with ( "SET LOCAL lock_timeout = '5s'" )
70
+ migration . migrate ( :up )
71
+ end
72
+
73
+ it 'does not use timeout for down migration' do
74
+ migration = AddBar . new
75
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
76
+ with ( "SET LOCAL lock_timeout = '5s'" )
77
+ migration . migrate ( :down )
78
+ end
79
+ end
80
+
81
+ describe 'disable lock timeout' do
82
+
83
+ class AddBaz < ActiveRecord ::Migration
84
+ disable_lock_timeout!
85
+ def up
86
+ create_table :baz do |t |
87
+ t . timestamps
88
+ end
89
+ end
90
+
91
+ def down
92
+ drop_table :baz
93
+ end
94
+ end
95
+
96
+ it 'runs migrate up without timeout' do
97
+ migration = AddBaz . new
98
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
99
+ with ( "SET LOCAL lock_timeout = '5s'" )
100
+ migration . migrate ( :up )
101
+ end
102
+
103
+ it 'does not use timeout for down migration' do
104
+ migration = AddBaz . new
105
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
106
+ with ( "SET LOCAL lock_timeout = '5s'" )
107
+ migration . migrate ( :down )
108
+ end
109
+ end
110
+
111
+
112
+ describe 'change lock timeout' do
113
+
114
+ class AddBurn < ActiveRecord ::Migration
115
+ set_lock_timeout 10
116
+ def up
117
+ create_table :burn do |t |
118
+ t . timestamps
119
+ end
120
+ end
121
+
122
+ def down
123
+ drop_table :burn
124
+ end
125
+ end
126
+
127
+ it 'runs migrate up without timeout' do
128
+ migration = AddBurn . new
129
+ expect ( ActiveRecord ::Base . connection ) . to receive ( :execute ) .
130
+ with ( "CREATE TABLE \" burn\" (\" id\" serial primary key, \" created_at\" timestamp, \" updated_at\" timestamp) " )
131
+ expect ( ActiveRecord ::Base . connection ) . to receive ( :execute ) .
132
+ with ( "SET LOCAL lock_timeout = '10s'" )
133
+ migration . migrate ( :up )
134
+ end
135
+
136
+ it 'does not use timeout for down migration' do
137
+ migration = AddBurn . new
138
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
139
+ with ( "SET LOCAL lock_timeout = '10s'" )
140
+ migration . migrate ( :down )
141
+ end
142
+ end
143
+
144
+ describe 'with disable_ddl_transaction' do
145
+
146
+ class AddMonkey < ActiveRecord ::Migration
147
+ disable_ddl_transaction!
148
+ def up
149
+ create_table :monkey do |t |
150
+ t . timestamps
151
+ end
152
+ end
153
+
154
+ def down
155
+ drop_table :monkey
156
+ end
157
+ end
158
+
159
+ it 'runs migrate up without timeout' do
160
+ migration = AddMonkey . new
161
+ expect ( ActiveRecord ::Base . connection ) . to receive ( :execute ) .
162
+ with ( "CREATE TABLE \" monkey\" (\" id\" serial primary key, \" created_at\" timestamp, \" updated_at\" timestamp) " )
163
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
63
164
with ( "SET LOCAL lock_timeout = '5s'" )
64
165
migration . migrate ( :up )
65
166
end
66
167
67
168
it 'does not use timeout for down migration' do
68
169
migration = AddBar . new
69
- expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute )
170
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
171
+ with ( "SET LOCAL lock_timeout = '5s'" )
70
172
migration . migrate ( :down )
71
173
end
72
174
end
@@ -88,13 +190,15 @@ def down
88
190
89
191
it 'runs migrate up without timeout' do
90
192
migration = AddBaz . new
91
- expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute )
193
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
194
+ with ( "SET LOCAL lock_timeout = '5s'" )
92
195
migration . migrate ( :up )
93
196
end
94
197
95
198
it 'does not use timeout for down migration' do
96
199
migration = AddBaz . new
97
- expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute )
200
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
201
+ with ( "SET LOCAL lock_timeout = '5s'" )
98
202
migration . migrate ( :down )
99
203
end
100
204
end
@@ -117,14 +221,17 @@ def down
117
221
118
222
it 'runs migrate up without timeout' do
119
223
migration = AddBurn . new
224
+ expect ( ActiveRecord ::Base . connection ) . to receive ( :execute ) .
225
+ with ( "CREATE TABLE \" burn\" (\" id\" serial primary key, \" created_at\" timestamp, \" updated_at\" timestamp) " )
120
226
expect ( ActiveRecord ::Base . connection ) . to receive ( :execute ) .
121
227
with ( "SET LOCAL lock_timeout = '10s'" )
122
228
migration . migrate ( :up )
123
229
end
124
230
125
231
it 'does not use timeout for down migration' do
126
232
migration = AddBurn . new
127
- expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute )
233
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
234
+ with ( "SET LOCAL lock_timeout = '10s'" )
128
235
migration . migrate ( :down )
129
236
end
130
237
end
@@ -146,13 +253,17 @@ def down
146
253
147
254
it 'runs migrate up without timeout' do
148
255
migration = AddMonkey . new
149
- expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute )
256
+ expect ( ActiveRecord ::Base . connection ) . to receive ( :execute ) .
257
+ with ( "CREATE TABLE \" monkey\" (\" id\" serial primary key, \" created_at\" timestamp, \" updated_at\" timestamp) " )
258
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
259
+ with ( "SET LOCAL lock_timeout = '10s'" )
150
260
migration . migrate ( :up )
151
261
end
152
262
153
263
it 'does not use timeout for down migration' do
154
264
migration = AddMonkey . new
155
- expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute )
265
+ expect ( ActiveRecord ::Base . connection ) . not_to receive ( :execute ) .
266
+ with ( "SET LOCAL lock_timeout = '10s'" )
156
267
migration . migrate ( :down )
157
268
end
158
269
end
0 commit comments