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

fix(gcb): Return mutable lists from methods annoated with PostFilter #673

Merged
merged 4 commits into from Mar 20, 2020
Merged

fix(gcb): Return mutable lists from methods annoated with PostFilter #673

merged 4 commits into from Mar 20, 2020

Conversation

ezimanyi
Copy link
Collaborator

Fixes spinnaker/spinnaker#5593

  • test(gcb): Update tests to run postFilter logic

    The GCB integration tests currently don't run the postFilter logic that is added as an annotation on controller methods. I believe this is because we've been to selective in exactly the beans that should be present in the test, and are not pulling in the required Spring Security beans.

    In order to fix this, add the same @componentscan that we have on Main.class to the test so it pulls in the same beans. (We can then also remove the specific controller bean we'd been pulling in, but will leave all the configuration beans in place.)

    This causes the listAccountTest to fail because the listAccounts function is currently broken; the next commit will fix the function and the test.

  • fix(gcb): Return mutable lists from methods annoated with PostFilter

    Controller methods annotated with PostFilter cannot return immutable lists because the filtering is done in-place on the returned array; update all controller methods in GoogleCloudBuildController to return a mutable list.

    As we would like the lower levels of the stack to deal in immutable collections as much as possible, just create a mutable collection at the last step before returning from the controller method.

The GCB integration tests currently don't run the postFilter logic
that is added as an annotation on controller methods. I believe this
is because we've been to selective in exactly the beans that should
be present in the test, and are not pulling in the required Spring
Security beans.

In order to fix this, add the same @componentscan that we have on
Main.class to the test so it pulls in the same beans.  (We can then
also remove the specific controller bean we'd been pulling in, but
will leave all the configuration beans in place.)

This causes the listAccountTest to fail because the listAccounts
function is currently broken; the next commit will fix the function
and the test.
Controller methods annotated with PostFilter cannot return immutable
lists because the filtering is done in-place on the returned array;
update all controller methods in GoogleCloudBuildController to return
a mutable list.

As we would like the lower levels of the stack to deal in immutable
collections as much as possible, just create a mutable collection
at the last step before returning from the controller method.
@ezimanyi
Copy link
Collaborator Author

Will look into that failing test, this is passing locally but not in Github Actions.

Copy link

@maggieneterval maggieneterval left a comment

Choose a reason for hiding this comment

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

☁️ 🔨 😶 🔇 💯

As we are now fully loading the application context as part of
the GCB tests, we should mark the test with DirtiesContext so
that it does not interfere with other tests.
@ezimanyi ezimanyi added the ready to merge Approved and ready for merge label Mar 20, 2020
The tests were failing because we can only ever create a single
HystrixSpectatorPublisher bean, due to the fact that it mutates
a static field on the HystrixPlugins class, which causes a
failure if we try to mutate it again.

This was addressed in MainTest by clearing the Hystrix class after
every test, but let's just inject a mock bean instead to avoid
mutating the static class in the first place.
@mergify mergify bot merged commit ac9a58a into spinnaker:master Mar 20, 2020
@mergify mergify bot added the auto merged label Mar 20, 2020
@ezimanyi ezimanyi deleted the fix-immutable branch March 20, 2020 17:04
@ezimanyi
Copy link
Collaborator Author

@spinnakerbot cherry-pick 1.19

spinnakerbot pushed a commit that referenced this pull request Mar 20, 2020
…673)

* test(gcb): Update tests to run postFilter logic

The GCB integration tests currently don't run the postFilter logic
that is added as an annotation on controller methods. I believe this
is because we've been to selective in exactly the beans that should
be present in the test, and are not pulling in the required Spring
Security beans.

In order to fix this, add the same @componentscan that we have on
Main.class to the test so it pulls in the same beans.  (We can then
also remove the specific controller bean we'd been pulling in, but
will leave all the configuration beans in place.)

This causes the listAccountTest to fail because the listAccounts
function is currently broken; the next commit will fix the function
and the test.

* fix(gcb): Return mutable lists from methods annoated with PostFilter

Controller methods annotated with PostFilter cannot return immutable
lists because the filtering is done in-place on the returned array;
update all controller methods in GoogleCloudBuildController to return
a mutable list.

As we would like the lower levels of the stack to deal in immutable
collections as much as possible, just create a mutable collection
at the last step before returning from the controller method.

* fix(gcb): Dirty application context for GCB tests

As we are now fully loading the application context as part of
the GCB tests, we should mark the test with DirtiesContext so
that it does not interfere with other tests.

* fix(gcb): Use mock HystrixSpectatorPublisher bean

The tests were failing because we can only ever create a single
HystrixSpectatorPublisher bean, due to the fact that it mutates
a static field on the HystrixPlugins class, which causes a
failure if we try to mutate it again.

This was addressed in MainTest by clearing the Hystrix class after
every test, but let's just inject a mock bean instead to avoid
mutating the static class in the first place.
@spinnakerbot
Copy link
Contributor

Cherry pick successful: #674

ezimanyi added a commit that referenced this pull request Mar 20, 2020
…673) (#674)

* test(gcb): Update tests to run postFilter logic

The GCB integration tests currently don't run the postFilter logic
that is added as an annotation on controller methods. I believe this
is because we've been to selective in exactly the beans that should
be present in the test, and are not pulling in the required Spring
Security beans.

In order to fix this, add the same @componentscan that we have on
Main.class to the test so it pulls in the same beans.  (We can then
also remove the specific controller bean we'd been pulling in, but
will leave all the configuration beans in place.)

This causes the listAccountTest to fail because the listAccounts
function is currently broken; the next commit will fix the function
and the test.

* fix(gcb): Return mutable lists from methods annoated with PostFilter

Controller methods annotated with PostFilter cannot return immutable
lists because the filtering is done in-place on the returned array;
update all controller methods in GoogleCloudBuildController to return
a mutable list.

As we would like the lower levels of the stack to deal in immutable
collections as much as possible, just create a mutable collection
at the last step before returning from the controller method.

* fix(gcb): Dirty application context for GCB tests

As we are now fully loading the application context as part of
the GCB tests, we should mark the test with DirtiesContext so
that it does not interfere with other tests.

* fix(gcb): Use mock HystrixSpectatorPublisher bean

The tests were failing because we can only ever create a single
HystrixSpectatorPublisher bean, due to the fact that it mutates
a static field on the HystrixPlugins class, which causes a
failure if we try to mutate it again.

This was addressed in MainTest by clearing the Hystrix class after
every test, but let's just inject a mock bean instead to avoid
mutating the static class in the first place.

Co-authored-by: Eric Zimanyi <ezimanyi@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants