8000 feat(tests): clean connectors for every tests by paul-nicolas · Pull Request #409 · formancehq/payments · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(tests): clean connectors for every tests #409

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

Merged
merged 1 commit into from
Apr 10, 2025

Conversation

paul-nicolas
Copy link
Contributor
@paul-nicolas paul-nicolas commented Apr 9, 2025

Fixes PMNT-86

Copy link
Contributor
coderabbitai bot commented Apr 9, 2025

Walkthrough

This pull request updates the project’s configuration and end-to-end test suites. The .gitignore file is modified to re-add an ignored directory and add a new file pattern. In the test suites, lifecycle hooks are standardized by replacing JustBeforeEach with BeforeEach and adding AfterEach blocks to ensure that connectors are uninstalled after each test. One test file also introduces a new helper function to uninstall connectors. These changes aim to improve test clarity and proper cleanup.

Changes

Files Change Summary
.gitignore Re-added the ignore pattern for tools/connector-template/connector-template and added a new ignore entry for coverage.txt.
test/e2e/api_accounts_test.go, test/e2e/api_bank_accounts_test.go, test/e2e/api_payment_initiations_test.go, test/e2e/api_payments_test.go, test/e2e/api_pools_test.go Replaced JustBeforeEach with BeforeEach and added AfterEach hooks to manage connector installation and cleanup; minor adjustments to variable declarations and timeouts.
test/e2e/api_connectors_test.go Replaced JustBeforeEach with BeforeEach, and added a new function uninstallConnector to handle connector uninstallation with proper error handling.

Sequence Diagram(s)

sequenceDiagram
    participant TR as Test Runner
    participant BE as BeforeEach Hook
    participant TC as Test Case
    participant AE as AfterEach Hook
    participant CT as Connector

    TR->>BE: Execute setup
    BE->>CT: Install connector (or prepare UUID)
    TR->>TC: Run test scenario
    TC->>TR: Perform assertions
    TR->>AE: Execute teardown
    AE->>CT: Uninstall connector
Loading

Assessment against linked issues

Objective Addressed Explanation
Clean up temporal state after each test (PMNT-86)

Suggested reviewers

  • laouji

Poem

I’m a little rabbit, hopping through code so fine,
With BeforeEach at dawn and AfterEach by twilight’s shine.
Connectors installed then uninstalled with care,
Test suites in order, light as air.
Hoppy cleanups make my heart simply divine!
🐇🥕

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@paul-nicolas paul-nicolas force-pushed the feat/clean-temporal-tests branch from 6d7db33 to 425598d Compare April 9, 2025 11:27
Copy link
codecov bot commented Apr 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.63%. Comparing base (7932cd2) to head (425598d).
Report is 12 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #409   +/-   ##
=======================================
  Coverage   59.63%   59.63%           
=======================================
  Files         538      538           
  Lines       26734    26734           
=======================================
  Hits        15942    15942           
  Misses       9953     9953           
  Partials      839      839           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@paul-nicolas paul-nicolas marked this pull request as ready for review April 9, 2025 11:37
@paul-nicolas paul-nicolas requested a review from a team as a code owner April 9, 2025 11:37
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)
test/e2e/api_pools_test.go (1)

69-70: Simplification of expectation.

The timeout specification was removed from the Eventually matcher. This is generally acceptable if the default timeout is sufficient for the test case to complete.

However, if this test is occasionally flaky or takes longer than expected, you might want to consider explicitly setting an appropriate timeout.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7932cd2 and 425598d.

📒 Files selected for processing (7)
  • .gitignore (1 hunks)
  • test/e2e/api_accounts_test.go (3 hunks)
  • test/e2e/api_bank_accounts_test.go (8 hunks)
  • test/e2e/api_connectors_test.go (7 hunks)
  • test/e2e/api_payment_initiations_test.go (11 hunks)
  • test/e2e/api_payments_test.go (4 hunks)
  • test/e2e/api_pools_test.go (7 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
test/e2e/api_payment_initiations_test.go (7)
pkg/testserver/matchers.go (4)
  • Event (142-147)
  • WithPayloadSubset (92-97)
  • HaveTaskStatus (184-189)
  • WithError (212-216)
pkg/events/event.go (4)
  • EventTypeSavedPaymentInitiation (16-16)
  • EventTypeSavedPaymentInitiationAdjustment (17-17)
  • EventTypeSavedPayments (11-11)
  • EventTypeSavedPaymentInitiationRelatedPayment (18-18)
internal/models/payment_initiation_adjusments_status.go (2)
  • PAYMENT_INITIATION_ADJUSTMENT_STATUS_WAITING_FOR_VALIDATION (14-14)
  • PAYMENT_INITIATION_ADJUSTMENT_STATUS_PROCESSED (16-16)
pkg/testserver/helpers.go (1)
  • TaskPoller (41-43)
internal/models/task_id.go (1)
  • TaskID (12-15)
internal/models/tasks.go (2)
  • TASK_STATUS_SUCCEEDED (15-15)
  • TASK_STATUS_FAILED (16-16)
internal/connectors/engine/workflow/reverse.go (1)
  • ErrPaymentInitiationNotProcessed (17-17)
test/e2e/api_connectors_test.go (6)
pkg/testserver/server.go (1)
  • Server (61-71)
internal/models/task_id.go (2)
  • TaskIDFromString (37-49)
  • TaskID (12-15)
pkg/testserver/helpers.go (1)
  • TaskPoller (41-43)
internal/models/plugin.go (1)
  • DefaultConnectorClientTimeout (9-9)
pkg/testserver/matchers.go (1)
  • HaveTaskStatus (184-189)
internal/models/tasks.go (1)
  • TASK_STATUS_SUCCEEDED (15-15)
test/e2e/api_pools_test.go (2)
pkg/testserver/helpers.go (1)
  • Subscribe (30-39)
pkg/testserver/matchers.go (2)
  • Event (142-147)
  • WithPayloadSubset (92-97)
test/e2e/api_accounts_test.go (5)
internal/connectors/plugins/public/dummypay/plugin.go (1)
  • New (27-38)
pkg/testserver/helpers.go (1)
  • Subscribe (30-39)
pkg/testserver/matchers.go (2)
  • Event (142-147)
  • WithCallback (45-50)
pkg/events/event.go (2)
  • EventTypeSavedAccounts (12-12)
  • EventTypeSavedBalances (13-13)
internal/events/balance.go (1)
  • BalanceMessagePayload (12-20)
🔇 Additional comments (26)
.gitignore (1)

12-13: Well-organized repository structure updates.

The additions to .gitignore look appropriate: re-adding the connector-template directory and adding coverage.txt to avoid tracking test coverage reports in version control.

test/e2e/api_payments_test.go (4)

51-53: Proper test lifecycle standardization.

Replacing JustBeforeEach with BeforeEach ensures setup happens at the right moment in the Ginkgo test lifecycle. This change promotes better test isolation.


61-63: Good cleanup practice added.

Adding the AfterEach block to uninstall the connector after each test ensures proper cleanup of resources, preventing state leakage between tests.


113-121: Proper test lifecycle standardization.

Similar to the v3 test case, this standardizes the setup timing by using BeforeEach instead of JustBeforeEach.


123-125: Good cleanup practice added.

Adding the AfterEach block to uninstall the connector after the v2 tests maintains consistency with the v3 tests and ensures proper resource cleanup.

test/e2e/api_connectors_test.go (3)

48-50: Improved test isolation for UUID generation.

Standardizing the use of BeforeEach for UUID generation ensures each test gets a fresh UUID, improving test isolation and predictability.


140-142: Consistent test setup timing.

Standardizing the use of BeforeEach across all test cases ensures consistent behavior in the test lifecycle. This makes tests more reliable and maintainable.

Also applies to: 217-219, 253-255, 290-306, 331-340


522-539: Well-structured connector cleanup function.

The new uninstallConnector function properly encapsulates the logic for uninstalling a connector and verifying the task completion. This centralized approach ensures consistent cleanup across all tests.

The function:

  1. Calls the SDK's UninstallConnector method
  2. Verifies the task ID is valid and contains "uninstall"
  3. Sets up a task poller to monitor the uninstallation
  4. Blocks until the workflow completes
  5. Verifies that the task status is SUCCEEDED

This implementation aligns perfectly with the PR objective of properly cleaning connectors for every test.

test/e2e/api_pools_test.go (2)

49-53: Standardized test setup timing.

Consistently using BeforeEach instead of JustBeforeEach across all test cases improves test organization and ensures setup happens at the same phase in the test lifecycle.

Also applies to: 120-124, 196-212, 262-278


55-57: Proper test resource cleanup.

Adding AfterEach blocks to uninstall connectors after each test ensures proper cleanup of resources, preventing state leakage between tests and potential resource exhaustion during test runs.

Also applies to: 126-128, 214-216, 280-282

test/e2e/api_payment_initiations_test.go (7)

56-87: Improved test setup and teardown via BeforeEach & AfterEach

The change from JustBeforeEach to BeforeEach ensures that connector installation and subscription happen at the right stage in the test lifecycle. Adding the AfterEach block for uninstalling the connector ensures proper cleanup after each test, preventing potential test pollution.


80-86: Simplified Eventually assertions

Removed the unnecessary .WithTimeout(2 * time.Second) from these Eventually assertions, making the code more concise while relying on default timeout settings.


89-91: Added connector cleanup in AfterEach block

This addition ensures that connectors are properly uninstalled after each test, which improves test isolation and prevents potential interference between tests.


118-124: Simplified Eventually assertions

Removed the .WithTimeout(2 * time.Second) from these assertions, making the code more concise while maintaining the same behavior through default timeout settings.


126-126: Adjusted taskPoller timeout

The timeout for the task polling operation has been adjusted to 2 seconds, providing a more appropriate constraint for expected response times.


205-229: Improved test setup for payout initiation tests

Similar to the previous test block, changing to BeforeEach improves the test lifecycle management for the payout initiation tests.


231-233: Added connector cleanup for payout tests

This AfterEach block ensures proper cleanup of connectors after payout initiation tests, consistent with the pattern established in other test blocks.

test/e2e/api_bank_accounts_test.go (5)

65-69: Updated test setup timing with BeforeEach

Changed from JustBeforeEach to BeforeEach to ensure the setup code executes at the appropriate time in the test lifecycle, improving test predictability.


107-117: Restructured connector setup for bank account forwarding tests

Moved setup code to BeforeEach to ensure proper initialization before 8000 each test runs, improving test isolation and reliability.


119-121: Added connector cleanup for bank account forwarding tests

This AfterEach block ensures connectors are properly uninstalled after each test, preventing potential interference between tests and resource leaks.


184-193: Updated setup for v2 bank account forwarding tests

Changed setup timing from JustBeforeEach to BeforeEach for consistency with other test blocks and improved test lifecycle management.


195-197: Added connector cleanup for v2 bank account forwarding tests

Ensures proper cleanup of connectors after each v2 bank account forwarding test, consistent with the cleanup pattern established in other test blocks.

test/e2e/api_accounts_test.go (4)

49-52: Improved variable declarations

Added explicit variable declarations for connectorID and err at the test block level, making them accessible throughout the test scope while improving code organization.


54-61: Added proper setup and teardown for account creation tests

Moved connector installation to BeforeEach and added AfterEach to uninstall the connector after each test. This ensures proper test isolation and prevents resource leaks.


110-113: Enhanced variable declarations for account balances tests

Added explicit variable declarations for connectorID and err at the test block level, consistent with the pattern in other test blocks, improving code organization.


126-128: Added connector cleanup for account balances tests

This AfterEach block ensures connectors are properly uninstalled after each account balances test, improving test isolation and resource management.

Comment on lines +59 to +61
AfterEach(func() {
uninstallConnector(ctx, app.GetValue(), connectorID)
})
Copy link
Contributor

Choose a reason for hiding this comment

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

In the future it might not be a bad idea to implement a t.CleanupTest() type function that allows us to setup the AfterEach tear down functions in the constructors.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just in case you don't know, you can use DeferCleanup

@paul-nicolas paul-nicolas merged commit ad2275b into main Apr 10, 2025
9 checks passed
@paul-nicolas paul-nicolas deleted the feat/clean-temporal-tests branch April 10, 2025 12:34
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.

3 participants
0