Skip to content

Commit

Permalink
Remove sleeps and make cron expression more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
sambible committed May 23, 2024
1 parent 77d0790 commit f743db8
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions tests/foreman/ui/test_syncplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""

from datetime import datetime, timedelta
import time

from fauxfactory import gen_choice
import pytest
Expand Down Expand Up @@ -197,10 +196,10 @@ def test_positive_synchronize_custom_product_custom_cron_real_time(session, modu
# workaround: force session.browser to point to browser object on next line
session.contenthost.read_all('current_user')
start_date = session.browser.get_client_datetime()
next_sync = 3 * 60
# forming cron expression sync repo after 3 min
next_sync = 5 * 60
# forming cron expression sync repo after 5 min
expected_next_run_time = start_date + timedelta(seconds=next_sync)
cron_expression = f'{expected_next_run_time.minute} * * * *'
cron_expression = f'{expected_next_run_time.minute} {expected_next_run_time.hour} {expected_next_run_time.day} {expected_next_run_time.month} *'
session.syncplan.create(
{
'name': plan_name,
Expand All @@ -227,13 +226,13 @@ def test_positive_synchronize_custom_product_custom_cron_real_time(session, modu
assert 'No task was found using query' in str(context.value)
validate_repo_content(repo, ['erratum', 'rpm', 'package_group'], after_sync=False)
# Waiting part of delay that is left and check that product was synced
time.sleep(next_sync)
target_sat.wait_for_tasks(
search_query='Actions::Katello::Repository::Sync'
f' and organization_id = {module_org.id}'
f' and resource_id = {repo.id}'
' and resource_type = Katello::Repository',
search_rate=10,
max_tries=20,
)
validate_repo_content(repo, ['erratum', 'rpm', 'package_group'])
repo_values = session.repository.read(product.name, repo.name)
Expand Down Expand Up @@ -263,10 +262,10 @@ def test_positive_synchronize_custom_product_custom_cron_past_sync_date(
# workaround: force session.browser to point to browser object on next line
session.contenthost.read_all('current_user')
start_date = session.browser.get_client_datetime()
next_sync = 3 * 60
# forming cron expression sync repo after 3 min
next_sync = 5 * 60
# forming cron expression sync repo after 5 min
expected_next_run_time = start_date + timedelta(seconds=next_sync)
cron_expression = f'{expected_next_run_time.minute} * * * *'
cron_expression = f'{expected_next_run_time.minute} {expected_next_run_time.hour} {expected_next_run_time.day} {expected_next_run_time.month} *'
session.syncplan.create(
{
'name': plan_name,
Expand All @@ -293,13 +292,13 @@ def test_positive_synchronize_custom_product_custom_cron_past_sync_date(
assert 'No task was found using query' in str(context.value)
validate_repo_content(repo, ['erratum', 'rpm', 'package_group'], after_sync=False)
# Waiting part of delay that is left and check that product was synced
time.sleep(next_sync)
target_sat.wait_for_tasks(
search_query='Actions::Katello::Repository::Sync'
f' and organization_id = {module_org.id}'
f' and resource_id = {repo.id}'
' and resource_type = Katello::Repository',
search_rate=10,
max_tries=20,
)
validate_repo_content(repo, ['erratum', 'rpm', 'package_group'])
repo_values = session.repository.read(product.name, repo.name)
Expand Down

0 comments on commit f743db8

Please sign in to comment.