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

fix: flaky mongo spec test #36220

Merged
merged 22 commits into from
Sep 10, 2024
Merged

fix: flaky mongo spec test #36220

merged 22 commits into from
Sep 10, 2024

Conversation

AmanAgarwal041
Copy link
Contributor

@AmanAgarwal041 AmanAgarwal041 commented Sep 10, 2024

Description

RCA:
The test started acting flaky because of the ted mongo db had new entries which changed the index value of the record that we were trying to verify.

Solution:
We get the index value of the record by finding the record entry in a column and the traversing back to parent and getting index of the row item. This returned index is then used to match the record instead of just passing 0 which will still work if the new entries are made in the db.

Fixes #35149
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Datasource"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10789425505
Commit: dc720a1
Cypress dashboard.
Tags: @tag.Datasource
Spec:


Tue, 10 Sep 2024 09:51:00 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced CRUD validation tests for MongoDB, improving dropdown selection and table data validation.
    • Introduced a new method for more precise targeting of table column data based on column index and text content.
  • Bug Fixes

    • Improved reliability of tests by dynamically locating data rows instead of using hardcoded values.
  • Chores

    • Updated the limited tests to reflect a shift in focus from client-side to server-side functionality.

Copy link
Contributor

coderabbitai bot commented Sep 10, 2024

Walkthrough

This pull request introduces enhancements to the Cypress test suite for validating CRUD operations within a MongoDB context. Key modifications include improved dropdown item selection, a refactored row validation logic using a new helper function, and an updated test specification list that shifts focus from client-side to server-side tests. Additionally, a new method has been added to the Table class to enhance targeting of table column data based on specific criteria.

Changes

File Path Change Summary
app/client/cypress/e2e/Regression/ServerSide/GenerateCRUD/Mongo_Spec.ts Enhanced dropdown selection and refactored row validation logic using findTheDataRow helper function.
app/client/cypress/limited-tests.txt Updated test specifications: replaced client-side test with server-side test and commented out another server-side test.
app/client/cypress/support/Pages/Table.ts Added _tableColumnDataWithText method for improved targeting of table column data.

Possibly related issues

🌟 In the land of code where tests do play,
A dropdown now dances in a clearer way.
Rows once static now find their own place,
With helpers to guide them, they quicken their pace.
Server-side tests take the spotlight anew,
In the realm of CRUD, there's much work to do! ✨


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

@github-actions github-actions bot added the Bug Something isn't working label Sep 10, 2024
@AmanAgarwal041
Copy link
Contributor Author

/ci-test-limit-count run_count=20

Copy link

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

Outside diff range, codebase verification and nitpick comments (1)
app/client/cypress/e2e/Regression/ServerSide/GenerateCRUD/Mongo_Spec.ts (1)

44-47: Excellent enhancements to the CRUD validation process!

The new click action on the dropdown to select the image option strengthens the CRUD validation coverage. And the refactored table validation logic using the findTheDataRow helper function is a great improvement in terms of robustness and adaptability.

Just a minor suggestion to improve code readability:

Consider using more descriptive variable names for col1Text, col2Text, and col3Text. For example, imageUrl, pokemonId, and types would make the code more self-explanatory.

Also applies to: 116-143

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 182dbe7 and ae19c25.

Files selected for processing (3)
  • app/client/cypress/e2e/Regression/ServerSide/GenerateCRUD/Mongo_Spec.ts (2 hunks)
  • app/client/cypress/limited-tests.txt (1 hunks)
  • app/client/cypress/support/Pages/Table.ts (1 hunks)
Additional context used
Path-based instructions (3)
app/client/cypress/limited-tests.txt (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/e2e/Regression/ServerSide/GenerateCRUD/Mongo_Spec.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/support/Pages/Table.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
Additional comments not posted (3)
app/client/cypress/limited-tests.txt (1)

2-3: Great work shifting the focus to server-side tests!

The changes align perfectly with the PR objective of fixing the flaky MongoDB spec test. Removing the client-side test and adding the relevant server-side test is a step in the right direction.

app/client/cypress/e2e/Regression/ServerSide/GenerateCRUD/Mongo_Spec.ts (1)

147-171: Great job abstracting the row-finding logic!

The findTheDataRow function is a valuable addition to the test suite. It encapsulates the logic for determining the row index based on the text in the first column, making the code more maintainable and less prone to errors.

app/client/cypress/support/Pages/Table.ts (1)

62-70: Excellent addition to the Table class!

The new _tableColumnDataWithText method is a valuable enhancement to the Table class. It allows for more specific targeting of table column data based on both column index and text content, improving the flexibility and usability of the table manipulation features. Well done!

Copy link

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10787240712.
Cypress dashboard url: Click here!
All cypress tests have passed 🎉🎉🎉

***** Repeat Run Summary ***** Total Tests with repeat: 40 Total Passed: 40 Total Failed: 0 Total Skipped: 0 *****************************

@github-actions github-actions bot added the cypress-flaky-fix This label is auto-added when a PR which only has Cypress fixes are merged to release label Sep 10, 2024
@github-actions github-actions bot added Stability Pod For all issues/tasks to be prioritized under Stability pod Task A simple Todo labels Sep 10, 2024
@AmanAgarwal041 AmanAgarwal041 added the ok-to-test Required label for CI label Sep 10, 2024
@AmanAgarwal041 AmanAgarwal041 merged commit ad8924d into release Sep 10, 2024
47 checks passed
@AmanAgarwal041 AmanAgarwal041 deleted the fix/mongo-spec branch September 10, 2024 09:57
});

//Validating loaded JSON form
cy.xpath(locators._buttonByText("Update")).then((selector) => {
Copy link
Member

Choose a reason for hiding this comment

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

@sagar-qa007 @AmanAgarwal041 Is using an xpath a best practice in Cypress? Or do we have no other alternatives that could have been used here?

I'm asking this because the package cypress-xpath has been deprecated a year ago. Additionally, Cypress recommends using more specific ids to select elements rather than xpath.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mohanarpit Yeah we should ideally remove that and go for the css selectors. It was already there, but we can definitely update this.
cc @sagar-qa007

Copy link
Contributor

@sagar-qa007 sagar-qa007 Sep 10, 2024

Choose a reason for hiding this comment

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

Yes agree and noted. @mohanarpit

@AmanAgarwal041 It has present multiple places, can we update on that specs too? It will be good optimisation.

cy.xpath(locators._buttonByText("Update")).then((selector)

Copy link
Member

Choose a reason for hiding this comment

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

@AmanAgarwal041 Is there a CSS selector already available for this validation today? If yes, can we change it right now? If not, then we'll leave it for the time being.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mohanarpit I am not really sure we have something like that, because we have a repetitive block in around 8 files. @sagar-qa007 Can we add a task to update this block at every place ?
List of files :

  1. app/client/cypress/e2e/Regression/ServerSide/GenerateCRUD/Mongo_Spec.ts
  2. app/client/cypress/e2e/Regression/ServerSide/GenerateCRUD/MongoURI_Spec.ts
  3. app/client/cypress/e2e/Regression/ServerSide/GenerateCRUD/MySQL1_Spec.ts
  4. app/client/cypress/e2e/Regression/ServerSide/GenerateCRUD/MySQL2_Spec.ts
  5. app/client/cypress/e2e/Regression/ServerSide/GenerateCRUD/Postgres1_Spec.ts
  6. app/client/cypress/e2e/Regression/ServerSide/GenerateCRUD/Postgres2_Spec.ts
  7. app/client/cypress/e2e/Regression/ServerSide/QueryPane/Mongo1_spec.ts
  8. app/client/cypress/e2e/Sanity/Datasources/MsSQL_Basic_Spec.ts

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

#36230

created task.

Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working cypress-flaky-fix This label is auto-added when a PR which only has Cypress fixes are merged to release Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Product Issues related to a specific integration ok-to-test Required label for CI Query & JS Pod Issues related to the query & JS Pod Stability Pod For all issues/tasks to be prioritized under Stability pod Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Fix flakiness of cypress/e2e/Regression/ServerSide/GenerateCRUD/Mongo_Spec.ts
3 participants