8000 test: (temporal) add unit tests for temporal workflow activities by laouji · Pull Request #278 · formancehq/payments · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

test: (temporal) add unit tests for temporal workflow activities #278

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 2 commits into from
Jan 24, 2025

Conversation

laouji
Copy link
Contributor
@laouji laouji commented Jan 23, 2025

No description provided.

Copy link
Contributor
coderabbitai bot commented Jan 23, 2025

Walkthrough

This pull request introduces three new test files in the activities_test package, focusing on testing Temporal-related activities within the internal connectors engine. The new test files cover three specific methods: TemporalScheduleCreate, TemporalWorkflowExecutionsList, and TemporalWorkflowTerminate. Each test file uses the Ginkgo testing framework and Gomock for creating mock objects, ensuring comprehensive test coverage for error handling, successful execution paths, and specific method behaviors.

Changes

File Change Summary
internal/connectors/engine/activities/temporal_schedule_create_test.go New test file for TemporalScheduleCreate with custom matcher and tests for error handling and option forwarding
internal/connectors/engine/activities/temporal_workflow_executions_list_test.go New test file for TemporalWorkflowExecutionsList covering error scenarios and successful execution list retrieval
internal/connectors/engine/activities/temporal_workflow_terminate_test.go New test file for TemporalWorkflowTerminate testing unhandled errors, workflow not found scenarios, and successful termination

Sequence Diagram

sequenceDiagram
    participant Test as Test Suite
    participant Activities as Activities Struct
    participant TemporalClient as Temporal Client
    
    Test->>Activities: Initialize with Mocks
    Test->>Activities: Call Method (e.g., TemporalScheduleCreate)
    Activities->>TemporalClient: Invoke Client Method
    TemporalClient-->>Activities: Return Result/Error
    Activities-->>Test: Propagate Result/Error
    Test->>Test: Assert Expected Behavior
Loading

Possibly related PRs

Poem

🐰 Temporal tests, oh what delight!
Mocking clients with all my might
Errors caught, workflows controlled
Our code's behavior now untold
Rabbit's testing dance tonight! 🧪

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

@laouji laouji force-pushed the test/activity-tests branch from 79aad5c to d142247 Compare January 23, 2025 13:15
Copy link
codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.96%. Comparing base (8422142) to head (d142247).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #278      +/-   ##
==========================================
+ Coverage   72.91%   72.96%   +0.04%     
==========================================
  Files         537      537              
  Lines       26988    26988              
==========================================
+ Hits        19679    19691      +12     
+ Misses       6248     6235      -13     
- Partials     1061     1062       +1     

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

@laouji laouji marked this pull request as ready for review January 24, 2025 09:03
@laouji laouji requested a review from a team as a code owner January 24, 2025 09:03
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 (10)
internal/connectors/engine/activities/temporal_workflow_terminate_test.go (2)

7-16: Unused imports
The import paths here look consistent with the test's usage, except it appears there's no direct usage of events in this file. If evts isn't needed, you might consider removing both the variable and the import statements to avoid clutter.

-	"github.com/formancehq/payments/internal/events"
...
-	evts   *events.Events

18-31: Suggestion: Wrap in a 'Context' block for clarity
While this works fine, consider grouping the related variables (workflowID, runID, reason) in a Context block or a dedicated Describe to enhance readability when scaling up test scenarios in the future.

internal/connectors/engine/activities/temporal_workflow_executions_list_test.go (4)

31-45: Consider initializing or removing evts if unused.
Having evts declared without assignment may lead to confusion. If it's not needed for these tests, please remove it. Otherwise, initialize it properly to ensure clarity.

-evts       *events.Events
...
-act = activities.New(logger, t, s, evts, p, time.Millisecond)
+// If 'evts' is not used in tests, remove its declaration and pass nil explicitly
+// or if it is required, initialize it. For example:
+evts := events.New(...)
+act = activities.New(logger, t, s, evts, p, time.Millisecond)

12-13: Unify or clarify the use of two mocking frameworks.
The test imports both "github.com/golang/mock/gomock" (aliased as legacy_gomock) and "go.uber.org/mock/gomock" (aliased as gomock). Maintaining two versions of gomock might cause confusion. Consider unifying them if there is no specific need for both.

Also applies to: 17-18


52-57: Validate error content for deeper test coverage.
While verifying that the error is not nil is sufficient for presence checks, confirming that the error message matches an expected substring or error type can provide more robust test coverage and clarity.

-Expect(err).NotTo(BeNil())
+Expect(err).To(HaveOccurred())
+Expect(err.Error()).To(ContainSubstring("some error"))

68-72: Double-check the request argument with stricter matching.
Currently, ListWorkflowExecutions is invoked with gomock.Any(). Using argument matchers like gomock.Eq(req) or a more specific custom matcher can ensure the request object is passed correctly.

-w.EXPECT().ListWorkflowExecutions(ctx, gomock.Any()).Return(expectedRes, nil)
+w.EXPECT().ListWorkflowExecutions(ctx, gomock.Eq(req)).Return(expectedRes, nil)
internal/connectors/engine/activities/temporal_schedule_create_test.go (4)

19-24: Add coverage for additional schedule options
Currently, this matcher covers only a subset of the schedule options. If the TemporalScheduleCreate activity later includes other fields (e.g., CalendarSpecs, CronExpressions, or any advanced scheduling features), you might miss regressions. Consider expanding the test matcher coverage to ensure that all critical fields are checked.


47-49: Include all fields in String() method for enhanced diagnostic output
The current String() method only displays the schedule ID and trigger flag, which can make it harder to debug failures if other fields are mismatched. Including the overlap policy, jitter, and additional fields in the output could reduce debugging time.


76-88: Check for specific error messages to confirm error-handling logic
While checking that err is non-nil confirms a failure, you might also verify that the error message or type is what you expect (e.g., confirming that it's a Temporal client error vs. a different error). This can increase confidence in correct error-handling paths.


89-107: Consider adding test coverage for different schedule creation edge cases
For improved test coverage, include variations such as TriggerImmediately = false, an invalid overlap policy, or an intentionally empty ScheduleID. This helps ensure TemporalScheduleCreate behaves correctly under all valid and invalid conditions.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8422142 and d142247.

⛔ Files ignored due to path filters (1)
  • go.mod is excluded by !**/*.mod
📒 Files selected for processing (3)
  • internal/connectors/engine/activities/temporal_schedule_create_test.go (1 hunks)
  • internal/connectors/engine/activities/temporal_workflow_executions_list_test.go (1 hunks)
  • internal/connectors/engine/activities/temporal_workflow_terminate_test.go (1 hunks)
🔇 Additional comments (5)
internal/connectors/engine/activities/temporal_workflow_terminate_test.go (3)

47-53: Good test coverage for unhandled errors
Verifying that TemporalWorkflowTerminate correctly propagates unhandled errors ensures robust error handling.


54-59: Workflow not found scenario
It's a good pattern to ignore not-found errors, preventing the test from failing if the workflow is already terminated or missing.


61-66: Successful workflow termination
This test scenario is concise and confirms correct behavior when no error is returned.

internal/connectors/engine/activities/temporal_schedule_create_test.go (2)

41-45: Guard against potential nil pointer access in opts.Spec
Though rare, if opts.Spec is ever nil, opts.Spec.Jitter could panic. To be safer, consider a short-circuit check or add an additional condition to prevent nil pointer dereferencing.


65-74: Verify the unused evts dependency initialization
You declare evts but never assign it before passing it to activities.New(...). If this is intentional, consider removing evts from the constructor for clarity, or fully initialize it if needed for upcoming tests.

Copy link
Contributor
@paul-nicolas paul-nicolas left a comment

Choose a reason for hiding this comment

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

Nice I have a PR fixing something in the create schedule activity, let's merge your PR first so that I can add a test about that !

@laouji laouji merged commit 0522cb6 into main Jan 24, 2025
9 checks passed
@laouji laouji deleted the test/activity-tests branch January 24, 2025 09:36
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
0