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

Refactor applicationEventQueueLoop so it can be unit tested, and write new unit tests for it #502

Merged
merged 3 commits into from
Aug 1, 2023

Conversation

jgwest
Copy link
Member

@jgwest jgwest commented Jul 14, 2023

Description:

  • Move the contents of applicationEventQueueLoop into a separate struct, so that the state can be verified by unit tests
  • Move the existing logic (which processesindividual application event messages) into a new function processApplicationEventQueueLoopMessage
  • Call processApplicationEventQueueLoopMessage via new unit tests

Link to JIRA Story (if applicable): N/A

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 14, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 14, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jgwest

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jgwest jgwest changed the title Refactor applicationEventQueueLoop so it can be unit testsed and write new unit tests Refactor applicationEventQueueLoop so it can be unit tested, and write new unit tests for it Jul 14, 2023
@jgwest
Copy link
Member Author

jgwest commented Jul 17, 2023

/test all

@@ -114,8 +114,34 @@ func startApplicationEventQueueLoopWithFactory(ctx context.Context, aeqlParam Ap

}

type applicationEventQueueLoopState struct {

Copy link
Member Author

Choose a reason for hiding this comment

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

Note for reviewer: I moved these out of applicationEventQueueLoop, and added some comments, they are otherwise the same as before.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I don't see where these fields are moved out from applicationEventQueueLoop at line 65. You'd think that there would be a git diff on this?

Copy link
Member Author

@jgwest jgwest Jul 31, 2023

Choose a reason for hiding this comment

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

Yah, GitHub diff isn't very good here, in this case I often find I have to copy/paste the change into a text file, and compare them using another tool like VS Code, Meld Merge, or BeyondCompare.

log.V(logutil.LogLevel_Debug).Info("applicationEventQueueLoop received event",
"event", eventlooptypes.StringEventLoopEvent(eventLoopMessage))
// returns true if the event loop should be terminated, false otherwise.
func processApplicationEventQueueLoopMessage(ctx context.Context, newEvent RequestMessage, state *applicationEventQueueLoopState, input chan RequestMessage, k8sClient client.Client, log logr.Logger) bool {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note for reviewer: I moved the contents of applicationEventQueueLoop into its own function, so it was easier to unit test. The code is otherwise the same (the GitHub compare is mangling it 😄 )

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, looks like you did move the contents of that loop out to the new function.

I think you added the two new const booleans.

@jgwest jgwest marked this pull request as ready for review July 22, 2023 09:59
@openshift-ci openshift-ci bot requested review from jopit and Rizwana777 July 22, 2023 09:59
@jgwest jgwest requested review from keithchong and removed request for jopit and Rizwana777 July 24, 2023 11:40
Event: &eventlooptypes.EventLoopEvent{
EventType: eventlooptypes.SyncRunModified,
ReqResource: eventlooptypes.GitOpsDeploymentSyncRunTypeName,
WorkspaceID: string(workspaceUID),
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace with: WorkspaceID: workspaceUID,

Event: &eventlooptypes.EventLoopEvent{
EventType: eventlooptypes.SyncRunModified,
ReqResource: eventlooptypes.GitOpsDeploymentSyncRunTypeName,
WorkspaceID: string(workspaceUID),
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace with: WorkspaceID: workspaceUID,

Event: &eventlooptypes.EventLoopEvent{
EventType: eventlooptypes.DeploymentModified,
ReqResource: eventlooptypes.GitOpsDeploymentTypeName,
WorkspaceID: string(workspaceUID),
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace with: WorkspaceID: workspaceUID,

Event: &eventlooptypes.EventLoopEvent{
EventType: eventlooptypes.DeploymentModified,
ReqResource: eventlooptypes.GitOpsDeploymentTypeName,
WorkspaceID: string(workspaceUID),
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace with: WorkspaceID: workspaceUID,

Event: &eventlooptypes.EventLoopEvent{
EventType: eventlooptypes.ManagedEnvironmentModified,
ReqResource: eventlooptypes.GitOpsDeploymentManagedEnvironmentTypeName,
WorkspaceID: string(workspaceUID),
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace with: WorkspaceID: workspaceUID,

MessageType: eventlooptypes.ApplicationEventLoopMessageType_Event,
Event: &eventlooptypes.EventLoopEvent{
EventType: eventlooptypes.UpdateDeploymentStatusTick,
WorkspaceID: string(workspaceUID),
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace with: WorkspaceID: workspaceUID,

MessageType: eventlooptypes.ApplicationEventLoopMessageType_WorkComplete,
Event: &eventlooptypes.EventLoopEvent{
EventType: eventlooptypes.UpdateDeploymentStatusTick,
WorkspaceID: string(workspaceUID),
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace with: WorkspaceID: workspaceUID,

@codecov
Copy link

codecov bot commented Jul 29, 2023

Codecov Report

Patch coverage: 73.58% and project coverage change: +0.87% 🎉

Comparison is base (5580df0) 51.60% compared to head (b9898e9) 52.48%.
Report is 110 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #502      +/-   ##
==========================================
+ Coverage   51.60%   52.48%   +0.87%     
==========================================
  Files         109      108       -1     
  Lines       19041    19091      +50     
==========================================
+ Hits         9827    10020     +193     
+ Misses       8029     7858     -171     
- Partials     1185     1213      +28     
Files Changed Coverage Δ
...p/application_event_loop/application_event_loop.go 76.51% <73.07%> (+18.97%) ⬆️
...io.redhat.com/deploymenttargetbinder_controller.go 70.38% <100.00%> (+0.45%) ⬆️

... and 32 files with indirect coverage changes

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

@jgwest jgwest merged commit b510bcb into redhat-appstudio:main Aug 1, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants