Skip to content

Conversation

@jarhodes314
Copy link
Contributor

Proposed changes

Refactor tedge-flows to improve interval handling.

Previously, tedge-flows relied on an exact number of seconds passing to execute an interval, and this had two negative effects:

  • If tedge-flows was experiencing resource-pressure/needed to execute a moderately long-running javascript process, it could miss a tick entirely just by being a second late
  • If we wanted to test the intervals for real, the intervals used need to be multiple seconds long to definitively assert the interval is behaving, which is non-ideal for unit/integration tests

This PR fixes both of these issues, allowing arbitrary precision intervals that are guaranteed to execute once the interval has elapsed, regardless of how long it takes tedge-flows to inspect the pending tasks. Additionally, the new approach supports the tokio::time mocking API, so I have added some deterministic integration tests that don't require sleeping whatsoever.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue


Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s. You can activate automatic signing by running just prepare-dev once)
  • I ran just format as mentioned in CODING_GUIDELINES
  • I used just check as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@codecov
Copy link

codecov bot commented Oct 1, 2025

Codecov Report

❌ Patch coverage is 63.79310% with 21 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/extensions/tedge_flows/src/runtime.rs 52.94% 8 Missing ⚠️
crates/core/tedge/src/cli/flows/test.rs 0.00% 6 Missing ⚠️
crates/extensions/tedge_flows/src/js_script.rs 77.77% 3 Missing and 1 partial ⚠️
crates/extensions/tedge_flows/src/flow.rs 80.00% 1 Missing and 1 partial ⚠️
crates/extensions/tedge_flows/src/actor.rs 83.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2025

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
709 0 3 709 100 2h5m3.128178s

return false;
}

let now = Instant::now();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would pass now as an argument of the method. Having the time externalized makes things easier to test. Using tokio::time mocking helps for unit tests, but is useless for tedge flows test

/// Note: Caller should check should_execute_interval() before calling this
pub async fn on_interval(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see pros and cons to externalize or not the check if this call is timely. What are your motivation to move this check out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the functions the javascript module exports for tedge-flows to call, my expectation is that the methods on JsScript serve as a lightweight wrapper, doing minimal work beyond calling the function with the provided input. It also feels like a bit of a hack to pretend the function produced no output when it wasn't called at all (or if it entirely doesn't exist).


/// Check if this script should execute its interval function now
/// Returns true and updates next_execution if it's time to execute
pub fn should_execute_interval(&mut self) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay for this PR to have a should_execute_interval function inside the js_script module. However, this abstraction will also be useful for rust-based flow steps as well as for sources producing data at a regular pace.

Copy link
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. I appreciate the really nice unit test suite.

Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
@jarhodes314 jarhodes314 force-pushed the refactor/interval-handling branch from c8b4d1c to 5e68de8 Compare October 3, 2025 13:21
@jarhodes314 jarhodes314 temporarily deployed to Test Pull Request October 3, 2025 13:21 — with GitHub Actions Inactive
@jarhodes314 jarhodes314 enabled auto-merge October 3, 2025 13:21
@jarhodes314 jarhodes314 added this pull request to the merge queue Oct 3, 2025
Merged via the queue into thin-edge:main with commit f8a15db Oct 3, 2025
34 checks passed
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.

2 participants