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

update mocks in async package to mockery v2 generated mocks #6220

Conversation

popojk
Copy link
Contributor

@popojk popojk commented Feb 4, 2025

Tracking issue

Related to #149

Why are the changes needed?

FlyteAdmin currently relies on manually crafted mocks, which are cumbersome to maintain and extend for new interfaces. Switching to Mockery v2 generated mocks is a more efficient approach, eliminating repetitive boilerplate code and streamlining the development process.

What changes were proposed in this pull request?

This PR updates the mocks in flyteadmin/pkg/async to use Mockery v2 generated mocks and includes modifications to the related test cases to ensure compatibility.

Check all the applicable boxes

  • All new and existing tests passed.
  • All commits are signed-off.

Summary by Bito

This PR modernizes FlyteAdmin's async package by migrating from manual mocks to Mockery v2 generated mocks. The update includes adding mockery-v2 generation directives, regenerating mocks using mockery v2.40.3, and refactoring test files with new mock syntax. These changes enhance type safety, improve testing infrastructure, and reduce maintenance overhead through auto-generated implementations.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 5

@flyte-bot
Copy link
Collaborator

flyte-bot commented Feb 4, 2025

Code Review Agent Run #067023

Actionable Suggestions - 10
  • flyteadmin/pkg/async/notifications/mocks/ses_client.go - 1
    • Consider error handling for nil handler · Line 23-23
  • flyteadmin/pkg/manager/impl/launch_plan_manager_test.go - 4
  • flyteadmin/pkg/async/notifications/implementations/sandbox_processor_test.go - 1
    • Consider proper mock initialization pattern · Line 69-69
  • flyteadmin/pkg/async/cloudevent/mocks/publisher.go - 2
    • Consider impact of mock pattern change · Line 22-23
    • Consider error handling instead of panic · Line 30-33
  • flyteadmin/pkg/async/notifications/mocks/processor.go - 1
    • Consider enhancing mock Return implementation · Line 42-44
  • flyteadmin/pkg/manager/impl/execution_manager_test.go - 1
    • Mock type changed to interface type · Line 81-81
Additional Suggestions - 10
  • flyteadmin/pkg/manager/impl/launch_plan_manager_test.go - 2
  • flyteadmin/pkg/async/notifications/implementations/aws_processor_test.go - 2
    • Consider simplifying mock emailer access · Line 41-41
    • Consider using specific mock matchers · Line 41-41
  • flyteadmin/pkg/async/notifications/mocks/processor.go - 1
    • Consider adding error return to mock · Line 20-22
  • flyteadmin/pkg/manager/impl/execution_manager_test.go - 1
  • flyteadmin/pkg/async/notifications/implementations/gcp_processor_test.go - 4
Review Details
  • Files reviewed - 29 · Commit Range: b12cfdc..b12cfdc
    • flyteadmin/pkg/async/cloudevent/interfaces/publisher.go
    • flyteadmin/pkg/async/cloudevent/interfaces/sender.go
    • flyteadmin/pkg/async/cloudevent/mocks/publisher.go
    • flyteadmin/pkg/async/cloudevent/mocks/sender.go
    • flyteadmin/pkg/async/events/interfaces/node_execution.go
    • flyteadmin/pkg/async/events/interfaces/workflow_execution.go
    • flyteadmin/pkg/async/events/mocks/node_execution_event_writer.go
    • flyteadmin/pkg/async/events/mocks/workflow_execution_event_writer.go
    • flyteadmin/pkg/async/notifications/implementations/aws_processor_test.go
    • flyteadmin/pkg/async/notifications/implementations/gcp_processor_test.go
    • flyteadmin/pkg/async/notifications/implementations/publisher_test.go
    • flyteadmin/pkg/async/notifications/implementations/sandbox_processor_test.go
    • flyteadmin/pkg/async/notifications/interfaces/emailer.go
    • flyteadmin/pkg/async/notifications/interfaces/processor.go
    • flyteadmin/pkg/async/notifications/interfaces/publisher.go
    • flyteadmin/pkg/async/notifications/interfaces/smtp_client.go
    • flyteadmin/pkg/async/notifications/mocks/emailer.go
    • flyteadmin/pkg/async/notifications/mocks/processor.go
    • flyteadmin/pkg/async/notifications/mocks/publisher.go
    • flyteadmin/pkg/async/notifications/mocks/ses_client.go
    • flyteadmin/pkg/async/schedule/interfaces/event_scheduler.go
    • flyteadmin/pkg/async/schedule/interfaces/workflow_executor.go
    • flyteadmin/pkg/async/schedule/mocks/event_scheduler.go
    • flyteadmin/pkg/async/schedule/mocks/mock_event_scheduler.go
    • flyteadmin/pkg/async/schedule/mocks/mock_workflow_executor.go
    • flyteadmin/pkg/async/schedule/mocks/workflow_executor.go
    • flyteadmin/pkg/manager/impl/execution_manager.go
    • flyteadmin/pkg/manager/impl/execution_manager_test.go
    • flyteadmin/pkg/manager/impl/launch_plan_manager_test.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 20.10724% with 298 lines in your changes missing coverage. Please review.

Project coverage is 36.85%. Comparing base (7d53a6e) to head (8875d98).
Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
...eadmin/pkg/async/schedule/mocks/event_scheduler.go 42.39% 48 Missing and 5 partials ⚠️
...dmin/pkg/async/schedule/mocks/workflow_executor.go 0.00% 48 Missing ⚠️
...teadmin/pkg/async/notifications/mocks/processor.go 0.00% 47 Missing ⚠️
.../async/events/mocks/node_execution_event_writer.go 0.00% 34 Missing ⚠️
...nc/events/mocks/workflow_execution_event_writer.go 0.00% 34 Missing ⚠️
flyteadmin/pkg/async/cloudevent/mocks/publisher.go 0.00% 23 Missing ⚠️
flyteadmin/pkg/async/cloudevent/mocks/sender.go 0.00% 23 Missing ⚠️
...lyteadmin/pkg/async/notifications/mocks/emailer.go 42.42% 17 Missing and 2 partials ⚠️
...teadmin/pkg/async/notifications/mocks/publisher.go 50.00% 13 Missing and 3 partials ⚠️
...eadmin/pkg/async/notifications/mocks/ses_client.go 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6220      +/-   ##
==========================================
- Coverage   36.90%   36.85%   -0.05%     
==========================================
  Files        1317     1318       +1     
  Lines      134061   134530     +469     
==========================================
+ Hits        49474    49584     +110     
- Misses      80294    80626     +332     
- Partials     4293     4320      +27     
Flag Coverage Δ
unittests-datacatalog 51.58% <ø> (ø)
unittests-flyteadmin 51.92% <20.10%> (-0.56%) ⬇️
unittests-flytecopilot 30.99% <ø> (ø)
unittests-flytectl 62.29% <ø> (ø)
unittests-flyteidl 7.23% <ø> (-0.01%) ⬇️
unittests-flyteplugins 53.91% <ø> (+0.04%) ⬆️
unittests-flytepropeller 42.78% <ø> (+0.05%) ⬆️
unittests-flytestdlib 55.33% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Signed-off-by: Alex Wu <[email protected]>
@flyte-bot
Copy link
Collaborator

flyte-bot commented Feb 4, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Testing - Mock Framework Modernization

publisher.go - Updated mock generation directive to use mockery-v2

sender.go - Updated mock generation directive to use mockery-v2

publisher.go - Regenerated mock using mockery v2.40.3 with expecter pattern

sender.go - Regenerated mock using mockery v2.40.3 with expecter pattern

node_execution.go - Updated mock generation directive to use mockery-v2

workflow_execution.go - Updated mock generation directive to use mockery-v2

node_execution_event_writer.go - Regenerated mock using mockery v2.40.3 with expecter pattern

workflow_execution_event_writer.go - Regenerated mock using mockery v2.40.3 with expecter pattern

aws_processor_test.go - Updated test to use new mockery v2 syntax

gcp_processor_test.go - Updated test to use new mockery v2 syntax

sandbox_processor_test.go - Updated test to use new mockery v2 syntax

emailer.go - Added mockery-v2 generation directive

processor.go - Added mockery-v2 generation directive

emailer.go - Regenerated mock using mockery v2.40.3 with expecter pattern

processor.go - Regenerated mock using mockery v2.40.3 with expecter pattern

Testing - Mock Framework Modernization

processor.go - Regenerated mock using mockery v2.40.3 with expecter pattern

publisher.go - Regenerated mock using mockery v2.40.3 with expecter pattern

ses_client.go - Added new SES client mock implementation

event_scheduler.go - Added mockery-v2 generation directive

workflow_executor.go - Added mockery-v2 generation directive

event_scheduler.go - Regenerated mock using mockery v2.40.3 with expecter pattern

workflow_executor.go - Regenerated mock using mockery v2.40.3 with expecter pattern

execution_manager_test.go - Updated test cases to use new mockery v2 syntax

launch_plan_manager_test.go - Updated test cases to use new mockery v2 syntax

Testing - Mock Framework Modernization

launch_plan_manager_test.go - Updated test cases to use EXPECT() syntax and modernized mock scheduler initialization

publisher.go - Updated mock generation directive to use mockery-v2

sender.go - Updated mock generation directive to use mockery-v2

publisher.go - Regenerated mock using mockery v2.40.3 with expecter pattern

sender.go - Regenerated mock using mockery v2.40.3 with expecter pattern

node_execution.go - Updated mock generation directive to use mockery-v2

workflow_execution.go - Updated mock generation directive to use mockery-v2

node_execution_event_writer.go - Regenerated mock using mockery v2.40.3 with expecter pattern

workflow_execution_event_writer.go - Regenerated mock using mockery v2.40.3 with expecter pattern

aws_processor_test.go - Updated test to use new mockery v2 syntax

gcp_processor_test.go - Updated test to use new mockery v2 syntax

sandbox_processor_test.go - Updated test to use new mockery v2 syntax

emailer.go - Added mockery-v2 generation directive

processor.go - Added mockery-v2 generation directive

emailer.go - Regenerated mock using mockery v2.40.3 with expecter pattern

processor.go - Regenerated mock using mockery v2.40.3 with expecter pattern

publisher.go - Regenerated mock using mockery v2.40.3 with expecter pattern

ses_client.go - Added new SES client mock implementation

event_scheduler.go - Added mockery-v2 generation directive

workflow_executor.go - Added mockery-v2 generation directive

event_scheduler.go - Regenerated mock using mockery v2.40.3 with expecter pattern

workflow_executor.go - Regenerated mock using mockery v2.40.3 with expecter pattern

execution_manager_test.go - Updated test cases to use new mockery v2 syntax

Comment on lines +445 to +446
mockScheduler := &mocks.EventScheduler{}
mockScheduler.EXPECT().AddSchedule(mock.Anything, mock.Anything).RunAndReturn(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using gomock controller for mocks

Consider using gomock.NewController(t) and mocks.NewMockEventScheduler instead of directly initializing the mock struct. This ensures proper cleanup and validation of mock expectations.

Code suggestion
Check the AI-generated fix before applying
Suggested change
mockScheduler := &mocks.EventScheduler{}
mockScheduler.EXPECT().AddSchedule(mock.Anything, mock.Anything).RunAndReturn(
ctrl := gomock.NewController(t)
mockScheduler := mocks.NewMockEventScheduler(ctrl)
mockScheduler.EXPECT().AddSchedule(mock.Anything, mock.Anything).RunAndReturn(

Code Review Run #067023


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +911 to +912
mockScheduler := &mocks.EventScheduler{}
mockScheduler.EXPECT().RemoveSchedule(mock.Anything, mock.Anything).RunAndReturn(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using mock constructor method

Consider using NewMockEventScheduler() instead of directly instantiating &mocks.EventScheduler{} to ensure proper mock initialization.

Code suggestion
Check the AI-generated fix before applying
Suggested change
mockScheduler := &mocks.EventScheduler{}
mockScheduler.EXPECT().RemoveSchedule(mock.Anything, mock.Anything).RunAndReturn(
mockScheduler := mocks.NewMockEventScheduler()
mockScheduler.(*mocks.MockEventScheduler).SetRemoveScheduleFunc(

Code Review Run #067023


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +911 to +912
mockScheduler := &mocks.EventScheduler{}
mockScheduler.EXPECT().RemoveSchedule(mock.Anything, mock.Anything).RunAndReturn(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mock setup could be more specific

Consider using a more descriptive mock setup by adding expectations for the specific input parameters that RemoveSchedule should receive. This would make the test more explicit about what it's verifying.

Code suggestion
Check the AI-generated fix before applying
Suggested change
mockScheduler := &mocks.EventScheduler{}
mockScheduler.EXPECT().RemoveSchedule(mock.Anything, mock.Anything).RunAndReturn(
mockScheduler := &mocks.EventScheduler{}
mockScheduler.EXPECT().RemoveSchedule(
mock.MatchedBy(func(ctx context.Context) bool { return true }),
mock.MatchedBy(func(input scheduleInterfaces.RemoveScheduleInput) bool { return input.Identifier == launchPlanNamedIdentifier }),
).RunAndReturn(

Code Review Run #067023


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@@ -816,8 +908,8 @@ func TestDisableLaunchPlan(t *testing.T) {
}

var removeScheduleFuncCalled bool
mockScheduler := mocks.NewMockEventScheduler()
mockScheduler.(*mocks.MockEventScheduler).SetRemoveScheduleFunc(
mockScheduler := &mocks.EventScheduler{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using mock constructor method

Consider using NewMockEventScheduler() constructor instead of direct struct initialization for mockScheduler to ensure proper mock initialization.

Code suggestion
Check the AI-generated fix before applying
Suggested change
mockScheduler := &mocks.EventScheduler{}
mockScheduler := mocks.NewMockEventScheduler()

Code Review Run #067023


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@@ -65,6 +66,7 @@ func TestSandboxProcessor_StartProcessingMessageError(t *testing.T) {
}

func TestSandboxProcessor_StartProcessingEmailError(t *testing.T) {
mockSandboxEmailer := mocks.Emailer{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider proper mock initialization pattern

Consider using mockSandboxEmailer := mocks.NewEmailer() instead of empty struct initialization to ensure proper mock setup. The mock expectations are being set using testify's mock package which requires proper initialization.

Code suggestion
Check the AI-generated fix before applying
Suggested change
mockSandboxEmailer := mocks.Emailer{}
mockSandboxEmailer := mocks.NewEmailer()

Code Review Run #067023


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +22 to +23
func (_m *Publisher) EXPECT() *Publisher_Expecter {
return &Publisher_Expecter{mock: &_m.Mock}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider impact of mock pattern change

Consider whether the mock expectation pattern being introduced with EXPECT() aligns with the existing mock usage pattern. The change removes OnPublish and OnPublishMatch methods in favor of an expecter pattern which may impact existing tests.

Code suggestion
Check the AI-generated fix before applying
Suggested change
func (_m *Publisher) EXPECT() *Publisher_Expecter {
return &Publisher_Expecter{mock: &_m.Mock}
func (_m *Publisher) OnPublish(ctx context.Context, notificationType string, msg protoiface.MessageV1) *Publisher_Publish {
c_call := _m.On("Publish", ctx, notificationType, msg)
return &Publisher_Publish{Call: c_call}
}
func (_m *Publisher) OnPublishMatch(matchers ...interface{}) *Publisher_Publish {
c_call := _m.On("Publish", matchers...)
return &Publisher_Publish{Call: c_call}

Code Review Run #067023


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +30 to +33
if len(ret) == 0 {
panic("no return value specified for Publish")
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider error handling instead of panic

Consider adding error handling for the panic case in the mock Publish method. A panic could make tests harder to debug. Maybe return an error instead?

Code suggestion
Check the AI-generated fix before applying
Suggested change
if len(ret) == 0 {
panic("no return value specified for Publish")
}
if len(ret) == 0 {
return fmt.Errorf("no return value specified for Publish")
}

Code Review Run #067023


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +42 to +44
func (_c *Processor_StartProcessing_Call) Return() *Processor_StartProcessing_Call {
_c.Call.Return()
return _c
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider enhancing mock Return implementation

The Return() method implementation appears to be incomplete. Consider returning the mock call results to maintain consistency with other mock implementations.

Code suggestion
Check the AI-generated fix before applying
Suggested change
func (_c *Processor_StartProcessing_Call) Return() *Processor_StartProcessing_Call {
_c.Call.Return()
return _c
func (_c *Processor_StartProcessing_Call) Return(results ...interface{}) *Processor_StartProcessing_Call {
_c.Call.Return(results...)
return _c

Code Review Run #067023


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@@ -78,7 +78,7 @@ var executionIdentifier = core.WorkflowExecutionIdentifier{
Domain: "domain",
Name: "name",
}
var mockPublisher notificationMocks.MockPublisher
var mockPublisher notificationMocks.Publisher
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mock type changed to interface type

Consider if using the concrete interface notificationMocks.Publisher instead of the mock type notificationMocks.MockPublisher is intentional, as this could affect test behavior.

Code suggestion
Check the AI-generated fix before applying
Suggested change
var mockPublisher notificationMocks.Publisher
var mockPublisher notificationMocks.MockPublisher

Code Review Run #067023


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Signed-off-by: Alex Wu <[email protected]>
@flyte-bot
Copy link
Collaborator

flyte-bot commented Feb 4, 2025

Code Review Agent Run #41e83e

Actionable Suggestions - 1
  • flyteadmin/pkg/manager/impl/execution_manager_test.go - 1
    • Consider consolidating duplicated request creation code · Line 2413-2420
Review Details
  • Files reviewed - 2 · Commit Range: b12cfdc..8875d98
    • flyteadmin/pkg/manager/impl/execution_manager.go
    • flyteadmin/pkg/manager/impl/execution_manager_test.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Comment on lines +2413 to +2420
req = &admin.WorkflowExecutionEventRequest{
RequestId: "1",
Event: &event.WorkflowExecutionEvent{
ExecutionId: &executionIdentifier,
Phase: core.WorkflowExecution_QUEUED,
OccurredAt: timestamppb.New(time.Now()),
},
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider consolidating duplicated request creation code

Consider consolidating the repeated workflow execution event request creation into a helper function to reduce code duplication. The same request structure is created multiple times with only the phase changing.

Code suggestion
Check the AI-generated fix before applying
 -	req := &admin.WorkflowExecutionEventRequest{
 -		RequestId: "1",
 -		Event: &event.WorkflowExecutionEvent{
 -			ExecutionId: &executionIdentifier,
 -			Phase:       core.WorkflowExecution_ABORTED,
 -			OccurredAt:  timestamppb.New(time.Now()),
 -		},
 -	}
 +	req := createTestWorkflowEvent(core.WorkflowExecution_ABORTED)

 -	req = &admin.WorkflowExecutionEventRequest{
 -		RequestId: "1",
 -		Event: &event.WorkflowExecutionEvent{
 -			ExecutionId: &executionIdentifier,
 -			Phase:       core.WorkflowExecution_QUEUED,
 -			OccurredAt:  timestamppb.New(time.Now()),
 -		},
 -	}
 +	req = createTestWorkflowEvent(core.WorkflowExecution_QUEUED)

 -	req = &admin.WorkflowExecutionEventRequest{
 -		RequestId: "1",
 -		Event: &event.WorkflowExecutionEvent{
 -			ExecutionId: &executionIdentifier,
 -			Phase:       core.WorkflowExecution_RUNNING,
 -			OccurredAt:  timestamppb.New(time.Now()),
 -		},
 -	}
 +	req = createTestWorkflowEvent(core.WorkflowExecution_RUNNING)

Code Review Run #41e83e


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Copy link
Member

@troychiu troychiu left a comment

Choose a reason for hiding this comment

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

Thank you!

@troychiu
Copy link
Member

troychiu commented Feb 4, 2025

@eapolinario I saw you review #6197. Mind also reviewing this one?

Copy link
Contributor

@eapolinario eapolinario left a comment

Choose a reason for hiding this comment

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

Awesome. Thank you!

@eapolinario eapolinario merged commit a6197d0 into flyteorg:master Feb 4, 2025
51 of 53 checks passed
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.

4 participants