@@ -372,6 +372,63 @@ def response_callback(
372372 assert "http://example.com/api/v4/user/status" in error_message
373373
374374
375+ def test_http_request_on_409_resource_lock_retries (gl_retry ):
376+ url = "http://localhost/api/v4/user"
377+ retried = False
378+
379+ def response_callback (
380+ response : requests .models .Response ,
381+ ) -> requests .models .Response :
382+ """We need a callback that adds a resource lock reason only on first call"""
383+ nonlocal retried
384+
385+ if not retried :
386+ response .reason = "Resource lock"
387+
388+ retried = True
389+ return response
390+
391+ with responses .RequestsMock (response_callback = response_callback ) as rsps :
392+ rsps .add (
393+ method = responses .GET ,
394+ url = url ,
395+ status = 409 ,
396+ match = helpers .MATCH_EMPTY_QUERY_PARAMS ,
397+ )
398+ rsps .add (
399+ method = responses .GET ,
400+ url = url ,
401+ status = 200 ,
402+ match = helpers .MATCH_EMPTY_QUERY_PARAMS ,
403+ )
404+ response = gl_retry .http_request ("get" , "/user" )
405+
406+ assert response .status_code == 200
407+
408+
409+ def test_http_request_on_409_resource_lock_without_retry_raises (gl ):
410+ url = "http://localhost/api/v4/user"
411+
412+ def response_callback (
413+ response : requests .models .Response ,
414+ ) -> requests .models .Response :
415+ """Without retry, this will fail on the first call"""
416+ response .reason = "Resource lock"
417+ return response
418+
419+ with responses .RequestsMock (response_callback = response_callback ) as req_mock :
420+ req_mock .add (
421+ method = responses .GET ,
422+ url = url ,
423+ status = 409 ,
424+ match = helpers .MATCH_EMPTY_QUERY_PARAMS ,
425+ )
426+ with pytest .raises (GitlabHttpError ) as excinfo :
427+ gl .http_request ("get" , "/user" )
428+
429+ assert excinfo .value .response_code == 409
430+
431+
375432@responses .activate
376433def test_get_request (gl ):
377434 url = "http://localhost/api/v4/projects"
0 commit comments