Skip to content

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 1, 2025

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

  • Added test_cron_trigger(platform) function to scripts/boss_test.py that:
    • Creates a lambda function that appends "cron invoked" to /tmp/cron_test_output.txt
    • Configures ol.yaml with a cron trigger that runs every minute (* * * * *)
    • Packages and uploads the lambda code to the lambda store
    • Waits 70 seconds for the cron trigger to execute
    • Verifies the output file exists and contains "cron invoked"
    • Includes proper cleanup and error handling

Supporting Functions

  • create_lambda_tar_with_cron(code_lines, cron_schedule) - Creates lambda package with cron trigger configuration
  • upload_lambda_with_cron(lambda_name, code_lines, cron_schedule) - Uploads lambda with cron triggers
  • verify_lambda_cron_config(lambda_name) - Verifies cron configuration was set correctly

Integration

  • Updated main() function to support --cron-test flag for running cron tests independently
  • Maintains backward compatibility with existing test functionality

Usage

# Run cron test for local platform
python3 scripts/boss_test.py local --cron-test

# Run regular tests (unchanged)
python3 scripts/boss_test.py local

Test Validation

The implementation has been thoroughly tested with:

  • ✅ Lambda code compilation and execution validation
  • ✅ YAML configuration format verification
  • ✅ Tar file structure and content validation
  • ✅ Function integration and error handling
  • ✅ All requirements from the issue specification

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.

@Copilot Copilot AI changed the title [WIP] Add cron tests. Add cron trigger test function to boss_test.py Jul 1, 2025
@Copilot Copilot AI requested a review from Mandukhai-Alimaa July 1, 2025 02:24
Copilot finished work on behalf of Mandukhai-Alimaa July 1, 2025 02:24
os.remove(ol_path)

return temp_tar_path


def upload_lambda(lambda_name, code_lines):
Copy link
Contributor

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.

Copy link
Author

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

@@ -108,6 +108,30 @@ def create_lambda_tar(code_lines):

Copy link
Contributor

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

Copy link
Author

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

@@ -190,6 +237,84 @@ def cleanup_boss():
kill_boss_on_port(5000)


def test_cron_trigger(platform):
Copy link
Contributor

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

Copy link
Author

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]>
@Copilot Copilot AI requested a review from Mandukhai-Alimaa July 1, 2025 03:04
Copilot finished work on behalf of Mandukhai-Alimaa July 1, 2025 03:04
@@ -217,6 +269,9 @@ def tester(platform):
result = invoke_lambda(lambda_name)
Copy link
Contributor

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().

Copy link
Author

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.

@Copilot Copilot AI requested a review from Mandukhai-Alimaa July 1, 2025 20:18
Copilot finished work on behalf of Mandukhai-Alimaa July 1, 2025 20:18
@@ -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"
Copy link
Contributor

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.

Copy link
Author

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

shutdown_and_check(lambda_name)

# Step 5: delete lambda and verify it's gone
delete_lambda_and_verify(lambda_name)
Copy link
Contributor

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.

Copy link
Author

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

Copilot finished work on behalf of Mandukhai-Alimaa July 1, 2025 20:30
@Copilot Copilot AI requested a review from Mandukhai-Alimaa July 1, 2025 20:30
test_cron_trigger()

# Shutdown and check
shutdown_and_check("hi")
Copy link
Contributor

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

Copy link
Author

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

@Copilot Copilot AI requested a review from Mandukhai-Alimaa July 1, 2025 20:41
Copilot finished work on behalf of Mandukhai-Alimaa July 1, 2025 20:41
Copy link
Contributor

@Mandukhai-Alimaa Mandukhai-Alimaa left a 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

upload_lambda(lambda_name, code, cron_config)

# Verify the cron configuration was set correctly
verify_lambda_cron_config(lambda_name)
Copy link
Contributor

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.

Copy link
Author

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

Copy link
Author

Copilot AI commented Jul 1, 2025

Also, u committed the file that should not be committed: min-image/spin

Removed the unwanted min-image/spin file from the repository. Commit f10fa4b

@Copilot Copilot AI requested a review from Mandukhai-Alimaa July 1, 2025 20:55
Copilot finished work on behalf of Mandukhai-Alimaa July 1, 2025 20:55
verify_lambda_cron_config(lambda_name)

# Clear any existing output file
output_file = "/tmp/cron_test_output.txt"
Copy link
Contributor

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.

Copy link
Author

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.

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"
Copy link
Contributor

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

Copy link
Author

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...")
Copy link
Contributor

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

Copy link
Author

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.

@Copilot Copilot AI requested a review from Mandukhai-Alimaa July 2, 2025 20:15
Copilot finished work on behalf of Mandukhai-Alimaa July 2, 2025 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add cron tests.
2 participants