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

Fixing watcher tests with new CSI daemon task creation workflow #4001

Merged
merged 2 commits into from
Oct 30, 2023

Conversation

mye956
Copy link
Contributor

@mye956 mye956 commented Oct 27, 2023

Summary

This PR will fix and "prettify" all of the skipped watcher tests with the new watcher changes introduced in #3984.

Implementation details

Now using a test table instead of individual test functions for most of the handle EBS attachment test cases.

  • agent/ebs/watcher_test.go: New functionality called getEBSAttachmentProperties to obtain a new AttachmentProperties object with test values

Testing

Unit tests for the following scenario:

  • Handle EBS attachment with new CSI driver task
  • Handle already expired EBS attachment
  • Handle duplicate EBS attachments
  • Handle EBS attachment with an existing CSI driver task that's running
  • Handle EBS attachment with an existing CSI driver task that's stopped

New tests cover the changes: Yes

Description for the changelog

Fix and prettify EBS watcher unit tests

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mye956 mye956 force-pushed the ebsStateUnitTests branch 4 times, most recently from 98fae63 to 0b1027d Compare October 27, 2023 22:17
@mye956 mye956 marked this pull request as ready for review October 27, 2023 22:17
@mye956 mye956 requested a review from a team as a code owner October 27, 2023 22:17
@mye956 mye956 changed the title [WIP] Fixing watcher tests with new CSI daemon task creation workflow Fixing watcher tests with new CSI daemon task creation workflow Oct 27, 2023
amogh09
amogh09 previously approved these changes Oct 27, 2023
Comment on lines +372 to +369
// Note: There are cases where we need to tick more than once.
// Ex: Tick 1 -> Create a CSI driver task if it doesn't exist/isn't running, Tick 2 -> Find/Validate/Stage EBS volume
Copy link
Contributor

Choose a reason for hiding this comment

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

In future maybe we should have separate unit tests for tick and HandleEBSResourceAttachment methods. That should make the tests simpler I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's true, I originally wanted to test also test the general workflow as well. Especially in the test case where we already have an existing CSI task that's running or stopped.

Copy link
Contributor

@amogh09 amogh09 Oct 27, 2023

Choose a reason for hiding this comment

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

Yeah I understand the motivation. But setting up the mocks a certain way to make that happen is equivalent to directly calling the two methods with appropriate arguments for the different test cases. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep yep completely agree! I'll add this as a TODO.

Copy link
Member

Choose a reason for hiding this comment

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

(+1 I'd like to see this too.)

KnownStatusUnsafe: status.TaskRunning,
}).Times(1),
)
mockTaskEngine.EXPECT().GetDaemonManagers().Return(daemonManagers).Times(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Times(1) is redundant as by default gomock sets the number of expected calls to 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I was thinking more of a max amount of times it should be called. Perhaps I can use MaxTimes() as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

.Times(1) (and not having any .TImes(1) since 1 is the default) will make the mock check that the method was invoked one and only once.

Copy link
Member

Choose a reason for hiding this comment

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

TIL

Comment on lines +372 to +369
// Note: There are cases where we need to tick more than once.
// Ex: Tick 1 -> Create a CSI driver task if it doesn't exist/isn't running, Tick 2 -> Find/Validate/Stage EBS volume
Copy link
Member

Choose a reason for hiding this comment

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

(+1 I'd like to see this too.)

@mye956 mye956 force-pushed the ebsStateUnitTests branch from 4407aa0 to a797d15 Compare October 30, 2023 21:33
@mye956 mye956 merged commit 0dcc969 into aws:dev Oct 30, 2023
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