Skip to content

Commit

Permalink
Add retries to some flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Oct 19, 2024
1 parent 6deeca3 commit 7f1e741
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 84 deletions.
61 changes: 37 additions & 24 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ def test_methods(client):
"update_func", ["search_update_plugins", "search.update_plugins"]
)
def test_update_plugins(client, update_func):
client.func(update_func)()
check(
lambda: any(
entry.message.startswith("Updating plugin ")
or entry.message == "All plugins are already up to date."
or entry.message.endswith("content was not found at the server (404)")
for entry in reversed(client.log.main())
),
True,
)
@retry()
def do_test():
client.func(update_func)()
check(
lambda: any(
entry.message.startswith("Updating plugin ")
or entry.message == "All plugins are already up to date."
or entry.message.endswith("content was not found at the server (404)")
for entry in reversed(client.log.main())
),
True,
)

do_test()


@pytest.mark.skipif_after_api_version("2.1.1")
Expand Down Expand Up @@ -193,24 +197,33 @@ def test_categories_not_implemented(client, categories_func):
],
)
def test_search(client, start_func, status_func, results_func, stop_func, delete_stop):
job = client.func(start_func)(pattern="Ubuntu", plugins="enabled", category="all")
@retry()
def do_test():
job = client.func(start_func)(
pattern="Ubuntu", plugins="enabled", category="all"
)

statuses = client.func(status_func)(search_id=job["id"])
assert statuses[0]["status"] == "Running"
assert isinstance(job, SearchJobDictionary)
assert isinstance(statuses, SearchStatusesList)
statuses = client.func(status_func)(search_id=job["id"])
assert statuses[0]["status"] == "Running"
assert isinstance(job, SearchJobDictionary)
assert isinstance(statuses, SearchStatusesList)

results = client.func(results_func)(search_id=job["id"], limit=1)
assert isinstance(results, SearchResultsDictionary)
results = job.results()
assert isinstance(results, SearchResultsDictionary)
results = client.func(results_func)(search_id=job["id"], limit=1)
assert isinstance(results, SearchResultsDictionary)
results = job.results()
assert isinstance(results, SearchResultsDictionary)

client.func(stop_func)(search_id=job["id"])
check(
lambda: client.func(status_func)(search_id=job["id"])[0]["status"],
"Stopped",
)

client.func(stop_func)(search_id=job["id"])
check(lambda: client.func(status_func)(search_id=job["id"])[0]["status"], "Stopped")
client.func(delete_stop)(search_id=job["id"])
statuses = client.func(status_func)()
assert not statuses

client.func(delete_stop)(search_id=job["id"])
statuses = client.func(status_func)()
assert not statuses
do_test()


@pytest.mark.skipif_before_api_version("2.1.1")
Expand Down
127 changes: 67 additions & 60 deletions tests/test_torrents.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,72 +231,79 @@ def fake_open(*arg, **kwargs):
"content_layout", [None, "Original", "Subfolder", "NoSubfolder"]
)
def test_add_options(client, api_version, keep_root_folder, content_layout, tmp_path):
if v(api_version) >= v("2.3.0"):
client.torrents_create_tags("option-tag")
new_torrent = new_torrent_standalone(
client=client,
torrent_files=ROOT_FOLDER_TORRENT_FILE,
torrent_hash=ROOT_FOLDER_TORRENT_HASH,
save_path=mkpath(tmp_path, "test_download"),
category="test_category",
is_paused=True,
upload_limit=1024,
download_limit=2048,
is_sequential_download=True,
is_first_last_piece_priority=True,
is_root_folder=keep_root_folder,
rename="this is a new name for the torrent",
use_auto_torrent_management=False,
tags="option-tag",
content_layout=content_layout,
ratio_limit=2,
seeding_time_limit=120,
)

with new_torrent as torrent:
check(lambda: torrent.info.category, "test_category")
check(
lambda: torrent.info.state,
("pausedDL", "checkingResumeData"),
reverse=True,
any=True,
@retry(3)
def do_test():
if v(api_version) >= v("2.3.0"):
client.torrents_create_tags("option-tag")
new_torrent = new_torrent_standalone(
client=client,
torrent_files=ROOT_FOLDER_TORRENT_FILE,
torrent_hash=ROOT_FOLDER_TORRENT_HASH,
save_path=mkpath(tmp_path, "test_download"),
category="test_category",
is_paused=True,
upload_limit=1024,
download_limit=2048,
is_sequential_download=True,
is_first_last_piece_priority=True,
is_root_folder=keep_root_folder,
rename="this is a new name for the torrent",
use_auto_torrent_management=False,
tags="option-tag",
content_layout=content_layout,
ratio_limit=2,
seeding_time_limit=120,
)
check(lambda: mkpath(torrent.info.save_path), mkpath(tmp_path, "test_download"))
check(lambda: torrent.info.up_limit, 1024)
check(lambda: torrent.info.dl_limit, 2048)
check(lambda: torrent.info.seq_dl, True)
if v(api_version) >= v("2.0.1"):
check(lambda: torrent.info.f_l_piece_prio, True)
if content_layout is None:

with new_torrent as torrent:
check(lambda: torrent.info.category, "test_category")
check(
lambda: torrent.files[0]["name"].startswith("root_folder"),
keep_root_folder in {True, None},
lambda: torrent.info.state,
("pausedDL", "checkingResumeData"),
reverse=True,
any=True,
)
check(lambda: torrent.info.name, "this is a new name for the torrent")
check(lambda: torrent.info.auto_tmm, False)
if v(api_version) >= v("2.6.2"):
check(lambda: torrent.info.tags, "option-tag")

if v(api_version) >= v("2.7"):
# after web api v2.7...root dir is driven by content_layout
check(
lambda: mkpath(torrent.info.save_path),
mkpath(tmp_path, "test_download"),
)
check(lambda: torrent.info.up_limit, 1024)
check(lambda: torrent.info.dl_limit, 2048)
check(lambda: torrent.info.seq_dl, True)
if v(api_version) >= v("2.0.1"):
check(lambda: torrent.info.f_l_piece_prio, True)
if content_layout is None:
should_root_dir_exists = keep_root_folder in {None, True}
else:
should_root_dir_exists = content_layout in {"Original", "Subfolder"}
else:
# before web api v2.7...it is driven by is_root_folder
if content_layout is not None and keep_root_folder is None:
should_root_dir_exists = content_layout in {"Original", "Subfolder"}
check(
lambda: torrent.files[0]["name"].startswith("root_folder"),
keep_root_folder in {True, None},
)
check(lambda: torrent.info.name, "this is a new name for the torrent")
check(lambda: torrent.info.auto_tmm, False)
if v(api_version) >= v("2.6.2"):
check(lambda: torrent.info.tags, "option-tag")

if v(api_version) >= v("2.7"):
# after web api v2.7...root dir is driven by content_layout
if content_layout is None:
should_root_dir_exists = keep_root_folder in {None, True}
else:
should_root_dir_exists = content_layout in {"Original", "Subfolder"}
else:
should_root_dir_exists = keep_root_folder in {None, True}
check(
lambda: any(f["name"].startswith("root_folder") for f in torrent.files),
should_root_dir_exists,
)
# before web api v2.7...it is driven by is_root_folder
if content_layout is not None and keep_root_folder is None:
should_root_dir_exists = content_layout in {"Original", "Subfolder"}
else:
should_root_dir_exists = keep_root_folder in {None, True}
check(
lambda: any(f["name"].startswith("root_folder") for f in torrent.files),
should_root_dir_exists,
)

if v(api_version) >= v("2.8.1"):
check(lambda: torrent.info.ratio_limit, 2)
check(lambda: torrent.info.seeding_time_limit, 120)

if v(api_version) >= v("2.8.1"):
check(lambda: torrent.info.ratio_limit, 2)
check(lambda: torrent.info.seeding_time_limit, 120)
do_test()


@pytest.mark.skipif_before_api_version("2.8.4")
Expand Down

0 comments on commit 7f1e741

Please sign in to comment.