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:
|
2020-09-28 13:41:18 +00:00
|
|
|
print("Waiting for activities to finish: {activities}".format(activities=server.activities))
|
2020-09-16 23:16:01 +00:00
|
|
|
time.sleep(1)
|
|
|
|
attempts += 1
|
2020-09-28 13:41:18 +00:00
|
|
|
assert attempts < MAX_ATTEMPTS, "Server still busy after {MAX_ATTEMPTS}s".format(MAX_ATTEMPTS=MAX_ATTEMPTS)
|
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
|
2020-09-28 13:41:18 +00:00
|
|
|
print("{title}: {updateQueueSize} items left".format(title=section.title, updateQueueSize=tl.updateQueueSize))
|
2020-09-21 21:06:14 +00:00
|
|
|
if not busy or attempts > MAX_ATTEMPTS:
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
|
|
|
attempts += 1
|
2020-09-28 13:41:18 +00:00
|
|
|
assert attempts < MAX_ATTEMPTS, "Metadata still processing after {MAX_ATTEMPTS}s".format(MAX_ATTEMPTS=MAX_ATTEMPTS)
|
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)
|