@@ -81,6 +81,10 @@ def force_erase_lock_object
8181 expect ( lock ) . not_to be_owned_according_to_server
8282 end
8383
84+ it 'has no refresh error' do
85+ expect ( lock . last_refresh_error ) . to be_nil
86+ end
87+
8488 specify 'checking for health is not possible due to being unlocked' do
8589 expect { lock . healthy? } . to \
8690 raise_error ( DistributedLock ::GoogleCloudStorage ::NotLockedError )
@@ -113,6 +117,7 @@ def force_erase_lock_object
113117 expect ( @lock ) . to be_owned_according_to_internal_state
114118 expect ( @lock ) . to be_owned_according_to_server
115119 expect ( @lock ) . to be_healthy
120+ expect ( @lock . last_refresh_error ) . to be_nil
116121 expect { @lock . check_health! } . not_to raise_error
117122 end
118123
@@ -131,6 +136,7 @@ def force_erase_lock_object
131136 owned_according_to_internal_state : @lock2 . owned_according_to_internal_state? ,
132137 owned_according_to_server : @lock2 . owned_according_to_server? ,
133138 healthy : @lock2 . healthy? ,
139+ last_refresh_error : @lock2 . last_refresh_error ,
134140 }
135141 end
136142
@@ -155,6 +161,7 @@ def force_erase_lock_object
155161 expect ( result [ :owned_according_to_internal_state ] ) . to be_truthy
156162 expect ( result [ :owned_according_to_server ] ) . to be_truthy
157163 expect ( result [ :healthy ] ) . to be_truthy
164+ expect ( result [ :last_refresh_error ] ) . to be_nil
158165 end
159166
160167 it 'raises AlreadyLockedError if called twice by the same instance and thread' do
@@ -183,6 +190,7 @@ def force_erase_lock_object
183190 expect ( @lock ) . to be_owned_according_to_internal_state
184191 expect ( @lock ) . to be_owned_according_to_server
185192 expect ( @lock ) . to be_healthy
193+ expect ( @lock . last_refresh_error ) . to be_nil
186194 expect { @lock . check_health! } . not_to raise_error
187195 end
188196
@@ -209,6 +217,7 @@ def force_erase_lock_object
209217 expect ( @lock ) . to be_owned_according_to_internal_state
210218 expect ( @lock ) . to be_owned_according_to_server
211219 expect ( @lock ) . to be_healthy
220+ expect ( @lock . last_refresh_error ) . to be_nil
212221 expect { @lock . check_health! } . not_to raise_error
213222 end
214223
@@ -224,6 +233,7 @@ def force_erase_lock_object
224233 expect ( @lock ) . to be_owned_according_to_internal_state
225234 expect ( @lock ) . to be_owned_according_to_server
226235 expect ( @lock ) . to be_healthy
236+ expect ( @lock . last_refresh_error ) . to be_nil
227237 expect { @lock . check_health! } . not_to raise_error
228238 end
229239
@@ -238,20 +248,25 @@ def force_erase_lock_object
238248 expect ( @lock ) . to be_owned_according_to_internal_state
239249 expect ( @lock ) . to be_owned_according_to_server
240250 expect ( @lock ) . to be_healthy
251+ expect ( @lock . last_refresh_error ) . to be_nil
241252 expect { @lock . check_health! } . not_to raise_error
242253 end
243254 end
244255
245256
246257 describe '#unlock' do
247258 after :each do
248- @lock . abandon if @lock
259+ if @lock
260+ @lock . abandon
261+ raise @lock . last_refresh_error if exception_to_retry? ( @lock . last_refresh_error )
262+ end
249263 end
250264
251265 def lock_and_unlock
252266 @lock . lock ( timeout : 0 )
253267 deleted = nil
254- expect { deleted = @lock . unlock } . not_to raise_error
268+ e = catch_non_retryable_exception { deleted = @lock . unlock }
269+ expect ( e ) . to be_nil
255270 deleted
256271 end
257272
@@ -292,8 +307,11 @@ def lock_and_unlock
292307
293308 @lock . lock ( timeout : 0 )
294309 force_erase_lock_object
310+
295311 deleted = nil
296- expect { deleted = @lock . unlock } . not_to raise_error
312+ e = catch_non_retryable_exception { deleted = @lock . unlock }
313+
314+ expect ( e ) . to be_nil
297315 expect ( deleted ) . to be_falsey
298316 expect ( @lock ) . not_to be_locked_according_to_internal_state
299317 expect ( @lock ) . not_to be_locked_according_to_server
@@ -326,7 +344,10 @@ def lock_and_unlock
326344 end
327345
328346 after :each do
329- @lock . abandon if @lock
347+ if @lock
348+ @lock . abandon
349+ raise @lock . last_refresh_error if exception_to_retry? ( @lock . last_refresh_error )
350+ end
330351 end
331352
332353 it 'updates the update time' do
@@ -348,12 +369,13 @@ def lock_and_unlock
348369 f . metadata [ 'something' ] = '123'
349370 end
350371 expect ( file . metageneration ) . not_to eq ( orig_metageneration )
351- eventually ( timeout : 10 ) do
372+ eventually ( timeout : 30 ) do
352373 !@lock . healthy?
353374 end
354375 expect { @lock . check_health! } . to \
355376 raise_error ( DistributedLock ::GoogleCloudStorage ::LockUnhealthyError )
356377 expect ( log_output . string ) . to include ( 'Lock object has an unexpected metageneration number' )
378+ expect ( @lock . last_refresh_error ) . not_to be_nil
357379 end
358380
359381 it 'declares unhealthiness when the lock object is deleted' do
@@ -370,6 +392,7 @@ def lock_and_unlock
370392 expect { @lock . check_health! } . to \
371393 raise_error ( DistributedLock ::GoogleCloudStorage ::LockUnhealthyError )
372394 expect ( log_output . string ) . to include ( 'Lock object has been unexpectedly deleted' )
395+ expect ( @lock . last_refresh_error ) . not_to be_nil
373396 end
374397 end
375398end
0 commit comments