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

DATAGO-64300: Test negative scenarios #135

Merged
merged 17 commits into from
Dec 4, 2023
Merged

Conversation

gregmeldrum
Copy link
Collaborator

What is the purpose of this change?

Test many negative scenarios.
Added changes to improve error handling

How was this change implemented?

Add a new set of "real" tests that test against actual brokers. This makes regression much easier as well.

How was this change tested?

Manual testing from intellij

Is there anything the reviewers should focus on/be aware of?

No

@@ -305,6 +305,9 @@
<configuration>
<!--suppress UnresolvedMavenProperty -->
<argLine>${jacocoSurefire}</argLine>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't want the "real" tests to run as part of unit tests

Map<String, String> envVars;
try {
envVars = setBrokerSpecificEnvVars(request.getServiceId());
} catch (Exception e) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added error handling when we are unable to find the messaging service from the service id

switch (command.getCommandType()) {
case terraform:
terraformManager.execute(commandMapper.map(request), command, envVars);
break;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Send back an error when the command type is unknown

.build());
break;
}
} catch (Exception e) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Send back an error if any other type of exception occurs.

@Autowired
private EventPortalProperties eventPortalProperties;

@Test
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For now, just make sure the application starts up in standalone mode.

@@ -0,0 +1,130 @@
springdoc:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An application yml file for negative config push tests.

<cleanHistoryOnStart>false</cleanHistoryOnStart>
</rollingPolicy>
</appender>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

New test output appender. This is written in markdown which makes it easy to drag/drop into confluence.

@@ -27,6 +28,10 @@ public class SolacePublisher {
private final OutboundMessageBuilder outboundMessageBuilder;
private final DirectMessagePublisher directMessagePublisher;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The date wasn't serializing in the command response, needed to add this module to the mapper.

@@ -89,8 +88,10 @@ private static String executeTerraformCommand(Command command, Map<String, Strin
switch (commandVerb) {
case "apply" -> {
writeHclToFile(command, configPath);
terraformClient.plan(envVars).get();
terraformClient.apply(envVars).get();
Boolean planSuccessful = terraformClient.plan(envVars).get();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No point in running apply if the plan failed. This short circuit saves us 255 seconds on a config push request.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!
If the apply is not successful, would we return a response back to ep-core?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we always send a response back to ep-core. If the plan step fails, we expect to get terraform error logs that would cause the EMA response to be an error. (with the error logs in the response).

byte[] decodedBytes;
try {
decodedBytes = Base64.getDecoder().decode(command.getBody());
} catch (IllegalArgumentException e) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Catch and rethrow since the original exception has a cryptic message.


@Test
public void manyRequestsForTheSameContextAtTheSameTime() {
String context = "abc123";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like context is same value in all tests, can we move it to the @BeforeEach section?

@gregmeldrum gregmeldrum merged commit 3d1db1a into main Dec 4, 2023
1 check passed
Copy link

SonarQube Quality Gate

Quality Gate failed

Failed condition 14.8% 14.8% Coverage on New Code (is less than 80%)

See analysis details on SonarQube

@gregmeldrum gregmeldrum deleted the DATAGO-64300-error-handling branch December 4, 2023 19:10
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.

2 participants