From 248e8efc770a04a2defc7351d7793f875daae65f Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Wed, 2 Dec 2026 20:27:49 -0800 Subject: [PATCH 1/2] Lose only answers to writes Drive carried out in the live tests The lost-answer tests replaced every matching answer with a lost connection, also a rate limit that said Drive had done nothing. Under load all tries of a write could be refused that way, and a test then found nothing on Drive. Refusals now reach the filesystem as they are. Co-Authored-By: Claude Opus 5.5 --- pydrive2/test/test_fs.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pydrive2/test/test_fs.py b/pydrive2/test/test_fs.py index 1e853a3a..042dca9e 100644 --- a/pydrive2/test/test_fs.py +++ b/pydrive2/test/test_fs.py @@ -549,6 +549,10 @@ def lose_answers(service_auth, monkeypatch): Drive has done what a request asked by then, as when a connection drops while the answer is on its way. One answer is lost unless `times` says more, after `skip` matching requests. + + Only answers to requests Drive carried out are lost and counted: a + success, or a 409 that says an earlier try did the work. A refusal, + such as a rate limit under load, reaches the filesystem as it is. """ def install(lost_method, path_end, skip=0, times=1): @@ -562,6 +566,7 @@ def request(uri, method="GET", **kwargs): if ( method == lost_method and urlsplit(uri).path.endswith(path_end) + and (answer[0].status < 400 or answer[0].status == 409) and skip <= next(matches) < skip + times ): lost.append(uri) @@ -729,8 +734,7 @@ def test_cp_file_of_a_shortcut_after_the_answer_was_lost_leaves_one_copy( fs, fs_factory, remote_dir, workspace_files, lose_answers ): fs.makedirs(remote_dir) - # Drive refuses the first copy, which carries an ID meant for files. - lost = lose_answers("POST", "/copy", skip=1) + lost = lose_answers("POST", "/copy") fs.cp_file(f"root/{workspace_files}-link", remote_dir + "/copy") assert len(lost) == 1 assert items_below(fs_factory()[0], remote_dir) == ["copy"] From 5c085ae9f43ac01ef456f3fbf01ffeb53dd5b333 Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Thu, 3 Dec 2026 11:02:50 -0800 Subject: [PATCH 2/2] Lose only successes and fileIdInUse replays; drop the unused skip Co-Authored-By: Claude Opus 5.5 --- pydrive2/test/test_fs.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pydrive2/test/test_fs.py b/pydrive2/test/test_fs.py index 042dca9e..7a9c281e 100644 --- a/pydrive2/test/test_fs.py +++ b/pydrive2/test/test_fs.py @@ -1,11 +1,11 @@ import errno +import json import os import posixpath import secrets import uuid from concurrent import futures from io import StringIO -from itertools import count from urllib.parse import parse_qsl, urlsplit import fsspec @@ -542,23 +542,32 @@ def test_get_file_callback(fs, tmpdir, remote_dir): assert callback.value == 40 +def carried_out(response, content): + if 200 <= response.status < 300: + return True + if response.status != 409: + return False + error = json.loads(content)["error"]["errors"][0] + return error["reason"] == "fileIdInUse" + + @pytest.fixture def lose_answers(service_auth, monkeypatch): """Send requests of this thread to Drive and lose their answers. Drive has done what a request asked by then, as when a connection drops while the answer is on its way. One answer is lost unless - `times` says more, after `skip` matching requests. + `times` says more. Only answers to requests Drive carried out are lost and counted: a - success, or a 409 that says an earlier try did the work. A refusal, - such as a rate limit under load, reaches the filesystem as it is. + success, or the 409 `fileIdInUse` that says an earlier try did the + work. Any other answer, such as a rate limit under load or a 308 that + asks for more of an upload, reaches the filesystem as it is. """ - def install(lost_method, path_end, skip=0, times=1): + def install(lost_method, path_end, times=1): http = service_auth.Get_Http_Object() send = http.request - matches = count() lost = [] def request(uri, method="GET", **kwargs): @@ -566,8 +575,8 @@ def request(uri, method="GET", **kwargs): if ( method == lost_method and urlsplit(uri).path.endswith(path_end) - and (answer[0].status < 400 or answer[0].status == 409) - and skip <= next(matches) < skip + times + and carried_out(*answer) + and len(lost) < times ): lost.append(uri) raise ConnectionResetError("the answer was lost")