-
Notifications
You must be signed in to change notification settings - Fork 127
Add cron trigger test function to boss_test.py #318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Mandukhai-Alimaa <[email protected]>
Co-authored-by: Mandukhai-Alimaa <[email protected]>
scripts/boss_test.py
Outdated
os.remove(ol_path) | ||
|
||
return temp_tar_path | ||
|
||
|
||
def upload_lambda(lambda_name, code_lines): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modify this function to accept config lines optionally. Then use this function for both normal upload and upload with corn schedule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified upload_lambda(lambda_name, code_lines, config_lines=None)
to accept optional config lines and pass them to create_lambda_tar()
. Now used for both normal upload and cron upload, eliminating the duplicate upload_lambda_with_cron()
function. Commit e67e3ef
scripts/boss_test.py
Outdated
@@ -108,6 +108,30 @@ def create_lambda_tar(code_lines): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modify create_lambda_tar(code_lines) to optionally accept config lines to put in ol.yaml and use it for normal upload and corn upload as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified create_lambda_tar(code_lines, config_lines=None)
to accept optional config lines for ol.yaml. The function now uses provided config lines or defaults to HTTP trigger configuration if none provided. Commit e67e3ef
scripts/boss_test.py
Outdated
@@ -190,6 +237,84 @@ def cleanup_boss(): | |||
kill_boss_on_port(5000) | |||
|
|||
|
|||
def test_cron_trigger(platform): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mkae this a normal function test_cron_trigger() that only creates the tar file with f.py and ol.yaml, uploads it, and verfies the lambda cron config and call the test_cron_trigger() after invoke_lambda in tester function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converted test_cron_trigger()
to a normal function that creates tar file with f.py and ol.yaml, uploads it, and verifies lambda cron config. Added call to test_cron_trigger()
after invoke_lambda
in the tester
function. Removed standalone test mode. Commit e67e3ef
- Modified create_lambda_tar() to accept optional config_lines parameter - Modified upload_lambda() to accept optional config_lines parameter - Removed duplicate create_lambda_tar_with_cron() and upload_lambda_with_cron() functions - Simplified test_cron_trigger() to only create, upload and verify cron lambda - Integrated test_cron_trigger() call into main tester() function after invoke_lambda - Removed --cron-test flag logic as cron test is now integrated into main test flow Co-authored-by: Mandukhai-Alimaa <[email protected]>
scripts/boss_test.py
Outdated
@@ -217,6 +269,9 @@ def tester(platform): | |||
result = invoke_lambda(lambda_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make step2, step3, step5, into a seperate function test_default_trigger() and call the test_default_trigger() from the tester. So the tester will look like step1: scale up worker, then call test_default_trigger() then call test_cron_trigger, shutdown_and_check() print(test passed for platform {platform}), cleanup_boss().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored the tester function structure as requested. Created test_default_trigger()
function containing steps 2, 3, and 5 (upload, verify, invoke lambda). The tester now follows the requested flow: scale up worker → test_default_trigger() → test_cron_trigger() → shutdown_and_check() → cleanup. Changes committed in d4bb5b7.
Co-authored-by: Mandukhai-Alimaa <[email protected]>
scripts/boss_test.py
Outdated
@@ -207,19 +278,16 @@ def tester(platform): | |||
assert json.loads(boss_get("status"))["state"]["starting"] == 1 | |||
wait_for_workers(1) | |||
|
|||
# Step 2: upload and verify lambda | |||
# Test default HTTP trigger functionality | |||
lambda_name = "hi" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to the test_default_trigger function. test_default_trigger will not receive any parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved lambda_name = "hi"
into the test_default_trigger()
function and removed the parameter. The function is now self-contained. Commit 60ea565
scripts/boss_test.py
Outdated
shutdown_and_check(lambda_name) | ||
|
||
# Step 5: delete lambda and verify it's gone | ||
delete_lambda_and_verify(lambda_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this inside the test_default_trigger function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved delete_lambda_and_verify(lambda_name)
inside the test_default_trigger()
function. The function now handles its own cleanup. Commit 60ea565
…igger function Co-authored-by: Mandukhai-Alimaa <[email protected]>
scripts/boss_test.py
Outdated
test_cron_trigger() | ||
|
||
# Shutdown and check | ||
shutdown_and_check("hi") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shutdown_and_check dont need to receive a parameter. Delete the parameter and no need to print the lambda name in the shutdown_and_check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the parameter from shutdown_and_check()
function and simplified the print message to not include the lambda name. Commit d96589b
…message Co-authored-by: Mandukhai-Alimaa <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, u committed the file that should not be committed: min-image/spin
scripts/boss_test.py
Outdated
upload_lambda(lambda_name, code, cron_config) | ||
|
||
# Verify the cron configuration was set correctly | ||
verify_lambda_cron_config(lambda_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function should check the cron config and then also check the output of the /tmp/cron_test_output.txt to make sure the cron function was invoked successfully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enhanced the test_cron_trigger()
function to verify both cron config and actual execution. The function now waits 70 seconds for the cron to execute, then checks that /tmp/cron_test_output.txt
exists and contains "cron invoked". Commit f10fa4b
…xecution Co-authored-by: Mandukhai-Alimaa <[email protected]>
Removed the unwanted |
verify_lambda_cron_config(lambda_name) | ||
|
||
# Clear any existing output file | ||
output_file = "/tmp/cron_test_output.txt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clear the existing output file before the upload_lambda function is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the output file clearing to before the upload_lambda call as requested. The file is now cleared at line 274-277 before the upload happens.
scripts/boss_test.py
Outdated
time.sleep(70) | ||
|
||
# Check if the output file was created and contains the expected content | ||
assert os.path.exists(output_file), f"Cron output file {output_file} was not created" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the logic to check the file content and cleaning up the output file to verify_lambda_cron_config function and rename the verify_lambda_cron_config function to verify_lambda_cron_trigger_result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed verify_lambda_cron_config to verify_lambda_cron_trigger_result and moved the file content verification and cleanup logic into this function. The function now handles both config verification and output file checking.
os.remove(output_file) | ||
|
||
# Wait for cron to execute (slightly over 1 minute to ensure it runs) | ||
print("[CRON TEST] Waiting 70 seconds for cron trigger to execute...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after the upload_lambda is called, wait 70 seconds, then call the newly renamed verify_lambda_cron_trigger_result function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restructured the function to call upload_lambda, wait 70 seconds, then call the renamed verify_lambda_cron_trigger_result function as requested. The flow is now: clear file → upload → wait → verify result.
Co-authored-by: Mandukhai-Alimaa <[email protected]>
This PR adds a comprehensive test function for cron triggers to the boss test suite, addressing the need to validate cron scheduling functionality in OpenLambda.
Changes Made
Main Implementation
test_cron_trigger(platform)
function toscripts/boss_test.py
that:/tmp/cron_test_output.txt
ol.yaml
with a cron trigger that runs every minute (* * * * *
)Supporting Functions
create_lambda_tar_with_cron(code_lines, cron_schedule)
- Creates lambda package with cron trigger configurationupload_lambda_with_cron(lambda_name, code_lines, cron_schedule)
- Uploads lambda with cron triggersverify_lambda_cron_config(lambda_name)
- Verifies cron configuration was set correctlyIntegration
main()
function to support--cron-test
flag for running cron tests independentlyUsage
Test Validation
The implementation has been thoroughly tested with:
The test follows the existing code patterns and maintains consistency with the current boss test framework.
Fixes #317.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.