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

test failing #1150

Merged
merged 4 commits into from
Jul 22, 2024
Merged

test failing #1150

merged 4 commits into from
Jul 22, 2024

Conversation

alex-Arc
Copy link
Collaborator

@alex-Arc alex-Arc commented Jul 19, 2024

test failing in github actions

Copy link
Contributor

coderabbitai bot commented Jul 19, 2024

Walkthrough

The changes enhance the testing framework for the runtimeState functionality by integrating the withFlushTimers utilities, which allow for better simulation of time-dependent behaviors during tests. This modification ensures that asynchronous operations and scheduled tasks are executed accurately. Additionally, updates to the "runtime offset" test case improve its reliability by accommodating asynchronous behavior, thereby increasing the efficiency of tests involving timed events.

Changes

Files Change Summary
apps/server/src/stores/__tests__/runtimeState.test.ts Enhanced testing with asynchronous describe and test blocks; improved time manipulation using withFlushTimersAsync.
packages/utils/src/test/withFlushTimers.ts Introduced withFlushTimers and withFlushTimersAsync utilities to manage timers in both synchronous and asynchronous tests.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Suite
    participant R as Runtime State
    participant TE as Timer Engine

    T->>TE: useFakeTimers()
    T->>R: Initialize rundown with events
    T->>TE: runAllTimers()
    T->>R: Execute scheduled tasks
    T->>TE: useRealTimers()
Loading

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@alex-Arc alex-Arc marked this pull request as ready for review July 19, 2024 15:53
@alex-Arc alex-Arc requested a review from cpvalente July 19, 2024 15:53
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e6e00c0 and 850e964.

Files selected for processing (1)
  • apps/server/src/stores/tests/runtimeState.test.ts (1 hunks)
Additional comments not posted (2)
apps/server/src/stores/__tests__/runtimeState.test.ts (2)

162-166: LGTM! The setup and teardown for fake timers are correctly implemented.

The use of vi.useFakeTimers(), vi.runAllTimers(), and vi.useRealTimers() ensures controlled time manipulation during the tests and reverts back to real timers afterward, maintaining test isolation.


167-167: LGTM! The runtime offset test case has been correctly updated to handle asynchronous operations.

The use of async ensures that any asynchronous operations within the test are properly awaited, improving test accuracy.

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: 1

Outside diff range, codebase verification and nitpick comments (2)
packages/utils/src/test/withFlushTimers.test.ts (2)

1-1: Consider adding a docstring or comment to explain the function.

Adding a comment or docstring to describe the purpose and usage of the withFlushTimers function would improve readability and maintainability.

/**
 * Executes a function with fake timers and then reverts to real timers.
 * @param fn - The function to execute.
 * @param args - The arguments to pass to the function.
 * @returns The return value of the executed function.
 */

3-3: Consider renaming ret to a more descriptive variable name.

Using a more descriptive variable name instead of ret would improve code readability.

const result = fn(...args);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 850e964 and 8cfc26a.

Files ignored due to path filters (1)
  • packages/utils/index.ts is excluded by none and included by none
Files selected for processing (2)
  • apps/server/src/stores/tests/runtimeState.test.ts (2 hunks)
  • packages/utils/src/test/withFlushTimers.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/server/src/stores/tests/runtimeState.test.ts
Additional comments not posted (3)
packages/utils/src/test/withFlushTimers.test.ts (3)

4-4: Ensure vi.runAllTimers() is always called.

To ensure that vi.runAllTimers() is always called, even if fn throws an error, it should be placed inside a finally block.


5-5: Ensure vi.useRealTimers() is always called.

To ensure that vi.useRealTimers() is always called, even if fn throws an error, it should be placed inside a finally block.


6-6: Return the result of the executed function.

The return statement is correct, but ensure that the result is returned after reverting to real timers.

packages/utils/src/test/withFlushTimers.test.ts Outdated Show resolved Hide resolved
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: 1

Outside diff range, codebase verification and nitpick comments (1)
packages/utils/src/test/withFlushTimers.ts (1)

1-1: Ensure type safety for the args parameter.

The args parameter is typed as Array<any>, which can lead to potential type safety issues. Consider using a more specific type if possible.

export function withFlushTimers<T extends any[], U>(fn: (...args: T) => U, args: T) {
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8cfc26a and e00defc.

Files ignored due to path filters (1)
  • packages/utils/index.ts is excluded by none and included by none
Files selected for processing (1)
  • packages/utils/src/test/withFlushTimers.ts (1 hunks)

packages/utils/src/test/withFlushTimers.ts Outdated Show resolved Hide resolved
@@ -159,7 +159,8 @@ describe('mutation on runtimeState', () => {
const event1 = { ...mockEvent, id: 'event1', timeStart: 0, timeEnd: 1000, duration: 1000 };
const event2 = { ...mockEvent, id: 'event2', timeStart: 1000, timeEnd: 1500, duration: 500 };
// force update
initRundown([event1, event2], {});
withFlushTimers(initRundown, [[event1, event2], {}]);
Copy link
Owner

Choose a reason for hiding this comment

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

question: dont we need to await the init rundown?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah you might be right, initRundown is async...
I will try and see if I can adapt the function

@alex-Arc alex-Arc requested a review from cpvalente July 22, 2024 11:18
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e00defc and 5e42b73.

Files ignored due to path filters (1)
  • packages/utils/index.ts is excluded by none and included by none
Files selected for processing (2)
  • apps/server/src/stores/tests/runtimeState.test.ts (3 hunks)
  • packages/utils/src/test/withFlushTimers.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/server/src/stores/tests/runtimeState.test.ts
Additional comments not posted (1)
packages/utils/src/test/withFlushTimers.ts (1)

1-7: Ensure fake timers are properly restored in case of errors.

If fn throws an error, vi.useRealTimers() may not be called. Consider using a try...finally block to ensure timers are always restored.

vi.useFakeTimers();
let ret: U;
try {
  ret = fn(...args);
  vi.runAllTimers();
} finally {
  vi.useRealTimers();
}
return ret;

packages/utils/src/test/withFlushTimers.ts Outdated Show resolved Hide resolved
@alex-Arc alex-Arc force-pushed the test-'runtime-offset'-failing branch from 5e42b73 to 57a34f2 Compare July 22, 2024 11:55
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5e42b73 and 57a34f2.

Files selected for processing (1)
  • apps/server/src/stores/tests/runtimeState.test.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/server/src/stores/tests/runtimeState.test.ts

Copy link
Owner

@cpvalente cpvalente left a comment

Choose a reason for hiding this comment

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

Good work

@alex-Arc alex-Arc merged commit 91d6adf into master Jul 22, 2024
3 checks passed
@alex-Arc alex-Arc deleted the test-'runtime-offset'-failing branch July 22, 2024 12: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.

2 participants