2020-09-16 23:16:01 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import time
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
MAX_ATTEMPTS = 60
|
|
|
|
|
|
|
|
|
|
|
|
def wait_for_idle_server(server):
|
|
|
|
"""Wait for PMS activities to complete with a timeout."""
|
|
|
|
attempts = 0
|
|
|
|
while server.activities and attempts < MAX_ATTEMPTS:
|
2022-08-28 05:56:01 +00:00
|
|
|
print(f"Waiting for activities to finish: {server.activities}")
|
2020-09-16 23:16:01 +00:00
|
|
|
time.sleep(1)
|
|
|
|
attempts += 1
|
2022-08-28 05:56:01 +00:00
|
|
|
assert attempts < MAX_ATTEMPTS, f"Server still busy after {MAX_ATTEMPTS}s"
|
2020-09-16 23:16:01 +00:00
|
|
|
|
|
|
|
|
2020-09-21 21:06:14 +00:00
|
|
|
def wait_for_metadata_processing(server):
|
|
|
|
"""Wait for async metadata processing to complete."""
|
|
|
|
attempts = 0
|
|
|
|
|
|
|
|
while True:
|
|
|
|
busy = False
|
|
|
|
for section in server.library.sections():
|
|
|
|
tl = section.timeline()
|
|
|
|
if tl.updateQueueSize > 0:
|
|
|
|
busy = True
|
2022-08-28 05:56:01 +00:00
|
|
|
print(f"{section.title}: {tl.updateQueueSize} items left")
|
2020-09-21 21:06:14 +00:00
|
|
|
if not busy or attempts > MAX_ATTEMPTS:
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
|
|
|
attempts += 1
|
2022-08-28 05:56:01 +00:00
|
|
|
assert attempts < MAX_ATTEMPTS, f"Metadata still processing after {MAX_ATTEMPTS}s"
|
2020-09-21 21:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_ensure_activities_completed(plex):
|
2020-09-16 23:16:01 +00:00
|
|
|
wait_for_idle_server(plex)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.authenticated
|
2020-09-21 21:06:14 +00:00
|
|
|
def test_ensure_activities_completed_authenticated(plex):
|
2020-09-16 23:16:01 +00:00
|
|
|
wait_for_idle_server(plex)
|
2020-09-21 21:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_ensure_metadata_scans_completed(plex):
|
|
|
|
wait_for_metadata_processing(plex)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.authenticated
|
|
|
|
def test_ensure_metadata_scans_completed_authenticated(plex):
|
|
|
|
wait_for_metadata_processing(plex)
|