Repository navigation
CTM-659: add retries for eventual consistency #495
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ | |
| import static bio.terra.buffer.service.resource.flight.GoogleProjectConfigUtils.REGION_TO_IP_RANGE; | ||
| import static bio.terra.buffer.service.resource.flight.GoogleProjectConfigUtils.getRegionToIpRange; | ||
| import static bio.terra.buffer.service.resource.flight.GoogleUtils.*; | ||
| import static org.awaitility.Awaitility.await; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
|
@@ -127,11 +128,13 @@ | |
| import com.google.common.collect.ImmutableList; | ||
| import java.io.IOException; | ||
| import java.math.BigDecimal; | ||
| import java.time.Duration; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.stream.Collectors; | ||
| import org.awaitility.core.ConditionFactory; | ||
| import org.hamcrest.Matchers; | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
@@ -525,6 +528,8 @@ public void testCreateGoogleProject_errorWhenResourceStateChange() throws Except | |
| FlightStatus.ERROR, stairwayComponent.get().getFlightState(flightId).getFlightStatus()); | ||
| } | ||
|
|
||
| @Disabled( | ||
| "Since Oct 2026, the integration test environment is not working correctly for quota changes; root cause unknown") | ||
| @Test | ||
| public void testCreateGoogleProject_createsConsumerOverride() throws Exception { | ||
| FlightManager manager = | ||
|
|
@@ -691,28 +696,31 @@ private void assertEnableApisContains(Project project, List<String> enabledApis) | |
| Matchers.hasItems(serviceNames.toArray())); | ||
| } | ||
|
|
||
| private void assertIamBindingsContains(Project project, List<IamBinding> iamBindings) | ||
| throws Exception { | ||
| private void assertIamBindingsContains(Project project, List<IamBinding> iamBindings) { | ||
| // By default we enable some services, which causes GCP to automatically create Service Accounts | ||
| // and grant them permissions on the project. | ||
| // e.g.,"serviceAccount:{projectId}-compute@developer.gserviceaccount.com" has editor role. | ||
| // So we need to iterate through all bindings and verify they at least contain the members & | ||
| // roles we expect. | ||
|
|
||
| Map<String, List<String>> allBindings = | ||
| rmCow | ||
| .projects() | ||
| .getIamPolicy(project.getProjectId(), new GetIamPolicyRequest()) | ||
| .execute() | ||
| .getBindings() | ||
| .stream() | ||
| .collect(Collectors.toMap(Binding::getRole, Binding::getMembers)); | ||
|
|
||
| for (IamBinding iamBinding : iamBindings) { | ||
| assertThat( | ||
| new ArrayList<>(allBindings.get(iamBinding.getRole())), | ||
| Matchers.hasItems(iamBinding.getMembers().toArray())); | ||
| } | ||
| // IAM policy changes may not be visible immediately, so poll until they are. | ||
| awaitEventualConsistency() | ||
| .untilAsserted( | ||
| () -> { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this diff is easier to see if you hide whitespace! |
||
| Map<String, List<String>> allBindings = | ||
| rmCow | ||
| .projects() | ||
| .getIamPolicy(project.getProjectId(), new GetIamPolicyRequest()) | ||
| .execute() | ||
| .getBindings() | ||
| .stream() | ||
| .collect(Collectors.toMap(Binding::getRole, Binding::getMembers)); | ||
|
|
||
| for (IamBinding iamBinding : iamBindings) { | ||
| assertThat( | ||
| new ArrayList<>(allBindings.getOrDefault(iamBinding.getRole(), List.of())), | ||
| Matchers.hasItems(iamBinding.getMembers().toArray())); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private void assertLogStorageBucketExists(Project project) throws Exception { | ||
|
|
@@ -1002,19 +1010,30 @@ private void assertDefaultVpcNotExists(Project project) throws Exception { | |
| 404)); | ||
| } | ||
|
|
||
| private void assertServiceAccountExists(Project project, String serviceAccountEmail) | ||
| throws Exception { | ||
| List<ServiceAccount> serviceAccounts = | ||
| Optional.ofNullable( | ||
| iamCow | ||
| .projects() | ||
| .serviceAccounts() | ||
| .list("projects/" + project.getProjectId()) | ||
| .execute() | ||
| .getAccounts()) | ||
| .orElse(List.of()); | ||
|
|
||
| assertTrue(serviceAccounts.stream().anyMatch(s -> serviceAccountEmail.equals(s.getEmail()))); | ||
| private void assertServiceAccountExists(Project project, String serviceAccountEmail) { | ||
| // Newly created service accounts may not show up in the list immediately. | ||
| awaitEventualConsistency() | ||
| .untilAsserted( | ||
| () -> { | ||
| List<ServiceAccount> serviceAccounts = | ||
| Optional.ofNullable( | ||
| iamCow | ||
| .projects() | ||
| .serviceAccounts() | ||
| .list("projects/" + project.getProjectId()) | ||
| .execute() | ||
| .getAccounts()) | ||
| .orElse(List.of()); | ||
|
|
||
| assertTrue( | ||
| serviceAccounts.stream().anyMatch(s -> serviceAccountEmail.equals(s.getEmail())), | ||
| "Service account " + serviceAccountEmail + " not found"); | ||
| }); | ||
| } | ||
|
|
||
| /** Polls for GCP state that may not be immediately visible after a flight completes. */ | ||
| private static ConditionFactory awaitEventualConsistency() { | ||
| return await().atMost(Duration.ofMinutes(4)).pollInterval(Duration.ofSeconds(5)); | ||
| } | ||
|
|
||
| private void assertDefaultServiceAccountExists(Project project) throws Exception { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the only step in the flight that didn't have the retry rule. Adding it.