From 8ad3f58c5c171221285e6dc42d8bf97b8831a7f0 Mon Sep 17 00:00:00 2001 From: "Caleb St. John" <30729806+yocalebo@users.noreply.github.com> Date: Wed, 4 Sep 2024 08:51:13 -0400 Subject: [PATCH] NAS-130986 / 25.04 / fix cronjob API test regressions (#14411) * fix cronjob API test regressions * no reason to sleep, just run the job --- tests/api2/test_cronjob.py | 50 +++++++++++++++----------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/tests/api2/test_cronjob.py b/tests/api2/test_cronjob.py index 89c145fad0543..683a829f41f2a 100644 --- a/tests/api2/test_cronjob.py +++ b/tests/api2/test_cronjob.py @@ -1,40 +1,28 @@ -from time import sleep - -import pytest - from middlewared.test.integration.utils import call, ssh -TESTFILE = '/tmp/.testFileCreatedViaCronjob' - - -def test_create_check_update_verify_cron_job(): - cronjob_dict = {} - - # create job - results = call("cronjob.create", { - 'user': 'root', - 'command': f'touch "{TESTFILE}"', - 'schedule': {'minute': '*/1'} - }) - cronjob_dict.update(results) +TESTFILE = '/mnt/cronjob_testfile' - # verify job creation - id = cronjob_dict['id'] - results = call('cronjob.query', [['id', '=', id]], {"get": True}) - assert results['enabled'] is True - # wait so job can run - sleep(65) +def test_cron_job(): + try: + id = call( + 'cronjob.create', + { + 'user': 'root', + 'enabled': True, + 'command': f'echo "yeah" > "{TESTFILE}"', + 'schedule': {'minute': '*/1'} + } + )['id'] + assert call('cronjob.query', [['id', '=', id]], {"get": True})['enabled'] is True + except Exception as e: + assert False, f'Unexpected failure: {str(e)}' - # disable job - id = cronjob_dict['id'] - call('cronjob.update', id, {'enabled': False}) + call('cronjob.run', id, job=True) + assert call('filesystem.statfs', TESTFILE)['blocksize'] - # remove test file results = ssh(f'rm "{TESTFILE}"', complete_response=True) assert results['result'] is True, results['output'] - # delete job - call('cronjob.delete', cronjob_dict['id']) - results = call('cronjob.query', [['id', '=', id]], {"get": True}) - assert results.json() == [] + call('cronjob.delete', id) + assert call('cronjob.query', [['id', '=', id]]) == []