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

Development: Fix load rating api spam and fix flaky e2e tests #9665

Merged
merged 3 commits into from
Nov 4, 2024

Conversation

EneaGore
Copy link
Contributor

@EneaGore EneaGore commented Nov 4, 2024

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the client coding and design guidelines.

Motivation and Context

There were some flaky tests. It was because the rating api was being spam called in the on changed hook .

Description

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Student
  1. Log in to Artemis
  2. Participate in the text/modeling/file-upload exercise
  3. Assess and view result
  4. Make sure rating component still exists in results and works when clicked

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1

Manual Tests

  • Test 1

Summary by CodeRabbit

  • Bug Fixes

    • Improved performance by optimizing the rating loading process, ensuring ratings are only fetched when the result changes.
  • Refactor

    • Enhanced internal logic for tracking previously processed results without altering the public interface.
  • Tests

    • Expanded test coverage for the RatingComponent, ensuring correct behavior when the result changes and preventing unnecessary API calls. Adjusted tests to handle scenarios with missing data.

@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Nov 4, 2024
@EneaGore EneaGore temporarily deployed to artemis-test1.artemis.cit.tum.de November 4, 2024 00:21 — with GitHub Actions Inactive
@EneaGore EneaGore changed the title fix load rating api spam Development Fix load rating api spam and fix flaky tests Nov 4, 2024
@EneaGore EneaGore changed the title Development Fix load rating api spam and fix flaky tests ´Development´ Fix load rating api spam and fix flaky tests Nov 4, 2024
@EneaGore EneaGore changed the title ´Development´ Fix load rating api spam and fix flaky tests Development Fix load rating api spam and fix flaky tests Nov 4, 2024
@EneaGore EneaGore changed the title Development Fix load rating api spam and fix flaky tests Development: Fix load rating api spam and fix flaky tests Nov 4, 2024
@EneaGore EneaGore marked this pull request as ready for review November 4, 2024 00:50
@EneaGore EneaGore requested a review from a team as a code owner November 4, 2024 00:50
Copy link

coderabbitai bot commented Nov 4, 2024

Walkthrough

The changes in the rating.component.ts file involve the addition of a private property previousResultId to the RatingComponent class. This property is utilized to track the ID of the previously processed result. The ngOnChanges method has been updated to conditionally invoke loadRating() only when the current result's ID differs from previousResultId. This modification optimizes the component's behavior by preventing unnecessary calls to loadRating() during change detection cycles. Additionally, the test suite for the RatingComponent has been enhanced to cover new scenarios related to the result changes.

Changes

File Change Summary
src/main/webapp/app/exercises/shared/rating/rating.component.ts Added private property previousResultId to track the previous result ID; modified ngOnChanges to check for changes before calling loadRating().
src/test/javascript/spec/component/rating/rating.component.spec.ts Added tests for loadRating method calls based on result changes; refined existing tests for accuracy regarding result and participation properties.

Possibly related PRs

Suggested reviewers

  • krusche
  • coolchock
  • DominikRemo
  • sarpsahinalp

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1c82313 and 9c9ac6d.

📒 Files selected for processing (1)
  • src/test/javascript/spec/component/rating/rating.component.spec.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/javascript/spec/component/rating/rating.component.spec.ts

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 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 or @coderabbitai title anywhere in the PR title to generate the title automatically.

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.

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 4, 2024
Copy link
Contributor

@florian-glombik florian-glombik left a comment

Choose a reason for hiding this comment

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

While the fix looks good, would it be possible to add a small client test that ensures (and documents) that this issue does not occur again?
Not that somebody tries to simplify the condition and the test turns flaky again 😅

Copy link

@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

🧹 Outside diff range and nitpick comments (2)
src/test/javascript/spec/component/rating/rating.component.spec.ts (2)

97-101: Enhance test specificity for result changes.

The test correctly verifies the number of loadRating calls and final rating value. However, we could make it more explicit and robust.

Consider enhancing the test:

 ratingComponent.result = { id: 91 } as Result;
+ratingComponent.result.submission = { id: 1 } as Submission;
+ratingComponent.result.participation = { id: 1 } as Participation;
 ratingComponentFixture.detectChanges();
-expect(loadRatingSpy).toHaveBeenCalledTimes(2);
+expect(loadRatingSpy).toHaveBeenCalledExactlyOnceWith(90);
+expect(loadRatingSpy).toHaveBeenCalledExactlyOnceWith(91);
 expect(ratingComponent.rating).toBe(2);

103-112: LGTM! Consider additional edge cases.

The test effectively verifies the optimization to prevent unnecessary API calls. Good job documenting the purpose with the comment.

Consider adding these edge cases:

it('should not call loadRating when only result object reference changes', () => {
    const loadRatingSpy = jest.spyOn(ratingComponent, 'loadRating');
    ratingComponent.result = { id: 90, submission: { id: 1 }, participation: { id: 1 } } as Result;
    ratingComponentFixture.detectChanges();
    
    // Create new object with same ID but different reference
    ratingComponent.result = { 
        id: 90, 
        submission: { id: 2 }, // different submission
        participation: { id: 1 } 
    } as Result;
    ratingComponentFixture.detectChanges();
    
    expect(loadRatingSpy).toHaveBeenCalledOnce();
    expect(loadRatingSpy).toHaveBeenCalledExactlyOnceWith(90);
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 370efab and 1c82313.

📒 Files selected for processing (1)
  • src/test/javascript/spec/component/rating/rating.component.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/test/javascript/spec/component/rating/rating.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 4, 2024
@EneaGore EneaGore changed the title Development: Fix load rating api spam and fix flaky tests Development: Fix load rating api spam and fix flaky e2e tests Nov 4, 2024
Copy link
Contributor

@edkaya edkaya left a comment

Choose a reason for hiding this comment

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

Code lgtm, e2e tests pass

Copy link
Contributor

@muradium muradium left a comment

Choose a reason for hiding this comment

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

Thanks for the fix. LGTM

Copy link
Member

@krusche krusche left a comment

Choose a reason for hiding this comment

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

Code looks good to me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix client Pull requests that update TypeScript code. (Added Automatically!) ready for review small tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants