Skip to content
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

fixing broken unit tests in cvat/app/events #8867

Merged
merged 20 commits into from
Dec 30, 2024

Conversation

archibald1418
Copy link
Contributor

@archibald1418 archibald1418 commented Dec 24, 2024

Includes and closes #8339, also closes #8349

This adressess issue #8349. Necessary changes proposed in #8339 are blocked by runtime failures in cvat/apps/events unit-testing suite. The tests rely on functionality that was made obsolete after changes made in #7958.

  • added __init__.py files as proposed in Add missing __init__.py files #8339
  • made constants from cvat/apps/events/handler.py::handle_client_events_push available to both the handler and the unit test, renamed some of them
  • refactored the test to rely on extracting working time information from send:working_time event instead of getting it from ClientEventsSerializer
  • refactored working time retrieval logic from handle_client_events_push to be checked and reused in unit tests
  • updated tests to calculate event working times cumulatively for each event and check the calculations against the already implemented assertions

Motivation and context

How has this been tested?

Unit tests on events were run both locally and inside CI

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
  • I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • New Features

    • Introduced new constants for time management: TIME_THRESHOLD (100 seconds) and WORKING_TIME_RESOLUTION (1 millisecond).
  • Bug Fixes

    • Updated event handling logic to improve working time calculations using the new constants.
  • Tests

    • Enhanced test cases to utilize the new constants for better clarity and maintainability. Updated method naming for improved readability.

Copy link
Contributor

coderabbitai bot commented Dec 24, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces two new time-related constants, TIME_THRESHOLD and WORKING_TIME_RESOLUTION, in the CVAT events module. These constants are defined in the const.py file and subsequently imported and used in handlers.py and tests/test_events.py. The changes aim to centralize time-related constants and improve code maintainability by replacing hardcoded values with well-defined constants representing a 100-second threshold and a 1-millisecond resolution.

Changes

File Change Summary
cvat/apps/events/const.py Added two new time-related constants: TIME_THRESHOLD (100 seconds) and WORKING_TIME_RESOLUTION (1 millisecond)
cvat/apps/events/handlers.py Imported and used the new constants in handle_client_events_push function, replacing previous hardcoded values
cvat/apps/events/tests/test_events.py Updated test case to use new constants, renamed _working_time method to _working_time_event

Poem

🕰️ Constants dance, time's gentle beat,
Milliseconds and seconds now complete
In CVAT's code, precision takes flight
With thresholds defined, oh so bright!
A rabbit's code-hop, clean and neat 🐰


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
cvat/apps/events/tests/test_events.py (1)

19-22: Clarify logic behind short vs. long gap thresholds.

It's a good practice to add inline documentation or a comment explaining that _SHORT_GAP is just a millisecond below the threshold, while _LONG_GAP matches the threshold exactly. This helps future maintainers quickly grasp the test scenario's purpose.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2fd48c8 and 51ddf8c.

📒 Files selected for processing (3)
  • cvat/apps/events/const.py (1 hunks)
  • cvat/apps/events/handlers.py (1 hunks)
  • cvat/apps/events/tests/test_events.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • cvat/apps/events/const.py
🔇 Additional comments (4)
cvat/apps/events/tests/test_events.py (3)

15-15: Use constants directly in tests to ensure consistent reference.

Importing TIME_THRESHOLD and WORKING_TIME_RESOLUTION from cvat.apps.events.const centralizes control over these time-related values. It helps keep the tests consistent with the production code. This is good practice and makes updating thresholds less error-prone.


37-37: Leverage integer arithmetic or explicit rounding for clarity.

When dividing by WORKING_TIME_RESOLUTION, ensure the resulting integer is correct for all potential durations. Consider an explicit rounding step to ensure the intended integer behavior is well-documented and unambiguous.


41-41: Rename usage references to match the updated function name _working_time_event.

Ensure that all references to the old _working_time method are updated throughout the test suite. Verify the rename does not break any existing method calls or test code.

cvat/apps/events/handlers.py (1)

34-34: Centralizing constants in const.py is a good improvement.

Importing TIME_THRESHOLD and WORKING_TIME_RESOLUTION from a dedicated constants file fosters better maintainability and consistency across modules. Good job!

@archibald1418 archibald1418 changed the title [WIP] Ov/events unit tests fail, issue8349 [WIP] ov/events unit tests fail, issue8349 Dec 24, 2024
@archibald1418 archibald1418 changed the title [WIP] ov/events unit tests fail, issue8349 [WIP] events unit tests fail Dec 24, 2024
@archibald1418 archibald1418 changed the title [WIP] events unit tests fail [WIP] fixing unit tests in events Dec 24, 2024
@archibald1418 archibald1418 changed the title [WIP] fixing unit tests in events [WIP] fixing broken unit tests in cvat/app/events Dec 24, 2024
@archibald1418 archibald1418 changed the title [WIP] fixing broken unit tests in cvat/app/events fixing broken unit tests in cvat/app/events Dec 26, 2024
@codecov-commenter
Copy link

codecov-commenter commented Dec 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.90%. Comparing base (9a25291) to head (782fb34).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8867      +/-   ##
===========================================
+ Coverage    73.89%   73.90%   +0.01%     
===========================================
  Files          408      411       +3     
  Lines        44131    44174      +43     
  Branches      3986     3993       +7     
===========================================
+ Hits         32611    32648      +37     
- Misses       11520    11526       +6     
Components Coverage Δ
cvat-ui 78.37% <76.78%> (-0.03%) ⬇️
cvat-server 70.10% <100.00%> (+0.03%) ⬆️

cvat/apps/events/const.py Show resolved Hide resolved
cvat/apps/events/handlers.py Outdated Show resolved Hide resolved
cvat/apps/events/const.py Outdated Show resolved Hide resolved
cvat/apps/events/tests/test_events.py Outdated Show resolved Hide resolved
cvat/apps/events/tests/test_events.py Outdated Show resolved Hide resolved
cvat/apps/events/tests/test_events.py Outdated Show resolved Hide resolved
MAX_EVENT_DURATION = datetime.timedelta(seconds=100)
WORKING_TIME_RESOLUTION = datetime.timedelta(milliseconds=1)
WORKING_TIME_SCOPE = 'send:working_time'
COLLAPSED_EVENT_SCOPES = frozenset(("change:frame",))
Copy link
Contributor

@zhiltsov-max zhiltsov-max Dec 27, 2024

Choose a reason for hiding this comment

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

Probably, it makes sense to rename either this constant or the compressed_* tests to use the same term. I'd vote for the constant renaming, because the word "collapse" primarily means something different.

@archibald1418 archibald1418 merged commit 279db7c into develop Dec 30, 2024
35 checks passed
@archibald1418 archibald1418 deleted the ov/events_unit_tests_issue8349 branch December 30, 2024 13:21
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.

Unit tests in the events app are broken
3 participants