-
Notifications
You must be signed in to change notification settings - Fork 807
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
test(clouddriver): Test Suite Refinement: MonitoredDeployTask and getRetrofitLogMessage() Behaviour #4617
base: master
Are you sure you want to change the base?
Conversation
53bfc87
to
1192c2c
Compare
...lix/spinnaker/orca/clouddriver/tasks/monitoreddeploy/EvaluateDeploymentHealthTaskSpec.groovy
Show resolved
Hide resolved
f5a095f
to
f04e4ef
Compare
ed03ba2
to
f56086a
Compare
@@ -198,6 +204,202 @@ class EvaluateDeploymentHealthTaskSpec extends Specification { | |||
false | null || ExecutionStatus.FAILED_CONTINUE | |||
} | |||
|
|||
def "should handle retrofit http error and return the task status depending on the scenarios"() { |
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.
I'm not sure I see the point of all this added test coverage. I mean, I'm all for more test coverage, but if I'm reading the code correctly, EvaluateDeploymentHealthTask doesn't catch any RetrofitErrors (nor have any catch blocks at all), so I don't see how adding SpinnakerRetrofitErrorHandler to DeploymentMonitorService (e.g. in #4614) could change behavior specifically in EvaluateDeploymentHealthTask,
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.
@dbyron-sf - This is exactly what I mentioned in the comments : #4614 (comment)
There is no behavioural change . I added this to avoid the confusion we had over the above discussion
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.
The easiest way to resolve that thread is with some git juggling to move the addition of that one specific test case to a separate commit before the code change in that PR. I suppose these additional tests could be related, but it's hard to see how.
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.
These additional test cases are similar, only differences are the type of Spinnaker*Exceptions are different. However if this test cases are confusing / irrelevant , I can still go ahead and remove it.
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.
I'd rather focus on #4614.
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.
Added test case for EvaluateDeploymentTask and moved to a separate commit. : d481b84
@@ -168,6 +173,99 @@ void shouldReturnDefaultLogMsgWhenUnexpectedErrorHasOccurred() { | |||
assertThat(logMessageOnUnexpectedError).isEqualTo("<NO RESPONSE>"); | |||
} | |||
|
|||
@Test | |||
void shouldReturnEmptyHttpErrorDetailsWhenExceptionThrownWhileReadingHttpStatus() { |
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.
Seems like there's a much simpler way to test this case, e.g.:
@Test
void returnsEmptyHttpErrorDetailsWhenExceptionReadingHttpStatus() {
Response response = mock(Response.class);
when(response.getStatus()).thenThrow(IllegalArgumentException.class);
String logMessageOnHttpError = monitoredDeployBaseTask.getRetrofitLogMessage(response);
assertThat(logMessageOnHttpError).isEqualTo("status: \nheaders: \nresponse body: ");
}
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.
Simplified the test case that verifies the scenario when getRetrofitLogMessage() returns empty http error details.
} | ||
|
||
@Test | ||
void shouldReturnOnlyStatusWhenExceptionThrownWhileParsingHttpErrorBody() { |
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.
same here, e.g.:
@Test
void returnsOnlyStatusWhenExceptionParsingHttpErrorBody() {
Response response = mock(Response.class);
when(response.getStatus()).thenReturn(HttpStatus.BAD_REQUEST.value()); // arbitrary
when(response.getReason()).thenReturn("arbitrary reason");
when(response.getBody()).thenThrow(IllegalArgumentException.class);
String logMessageOnHttpError = monitoredDeployBaseTask.getRetrofitLogMessage(response);
String status = String.format("%d (%s)", response.getStatus(), response.getReason());
assertThat(logMessageOnHttpError).isEqualTo(String.format("status: %s\nheaders: \nresponse body: ", status));
}
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.
Simplified the test case that verifies the scenario when getRetrofitLogMessage() returns only status.
|
||
@Test | ||
void shouldReturnOnlyStatusAndBodyWhenExceptionThrownWhileReadingHttpHeaders() | ||
throws IOException { |
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.
I haven't worked through this one but I suspect it's similar.
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.
Simplified the test case that verifies the scenario when getRetrofitLogMessage() returns only status and body
f8a4f43
to
42d18e1
Compare
42d18e1
to
e114897
Compare
…for DeploymentMonitorService Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception. Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608 Additionally, a new specific exception handler is introduced to manage JsonProcessing during the serialization of the HTTP error body. The impact of these changes should be compared with another related PR: spinnaker#4617
…DeployTask and 'getRetrofitLogMessage()' This commit sets the stage for forthcoming changes currently in progress under PR : spinnaker#4614 . The primary goal is to compare the behaviour before and after enhancements by introducing test cases for the ‘MonitoredDeployTask’ and the ‘getRetrofitLogMessage()’ method. For ‘MonitoredDeployTask’: - Test Case to simulate networkError and observe behaviour - Test Case to simulate httpError and observe behaviour - Test Case to simulate unexpectedError and observe behaviour - Test Case to simulate conversionError and observe behaviour For ‘getRetrofitLogMessage()’: - Test Cases to verify behaviour during HTTP error details parsing when exceptions occur Additionally, a Mockito dependency ('org.mockito:mockito-inline') has been added to support spying/mocking on the final class 'retrofit.client.Response'. This resolves the issue encountered during testing where Mockito couldn't mock/spy the final class, preventing the following error: org.mockito.exceptions.base.MockitoException: Cannot mock/spy class retrofit.client.Response Mockito cannot mock/spy because : - final class at com.netflix.spinnaker.orca.clouddriver.tasks.monitoreddeploy.MonitoredDeployBaseTaskTest.shouldReturnOnlyStatusWhenExceptionThrownWhileParsingHttpErrorBody(MonitoredDeployBaseTaskTest.java:217) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688) at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:131)
e114897
to
43964ce
Compare
…for DeploymentMonitorService Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception. Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608 Additionally, a new specific exception handler is introduced to manage JsonProcessing during the serialization of the HTTP error body. The impact of these changes should be compared with another related PR: spinnaker#4617
…for DeploymentMonitorService Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception. Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608 Additionally, a new specific exception handler is introduced to manage JsonProcessing during the serialization of the HTTP error body. The impact of these changes should be compared with another related PR: spinnaker#4617
…for DeploymentMonitorService Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception. Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608 Additionally, a new specific exception handler is introduced to manage JsonProcessing during the serialization of the HTTP error body. The impact of these changes should be compared with another related PR: spinnaker#4617
This pull request aims to enhance the testing suite for the MonitoredDeployTask and the getRetrofitLogMessage() method, demonstrating their behavior and preparing for upcoming modifications, which are currently a work in progress under PR : #4614.
Key Changes:
Test Cases for MonitoredDeployTask: Added test cases to illustrate the behaviour of the MonitoredDeployTask when encountering various RetrofitErrors, including networkError, httpError, unexpectedError, and conversionError.
Test Cases for getRetrofitLogMessage(): Introduced test cases to validate the behaviour of the getRetrofitLogMessage() method, specifically during the parsing of HTTP error response details such as http headers, http status codes, reason, and http error body. These test cases cover scenarios where exceptions occur during the reading or parsing of these HTTP error details.
Dependency Addition:
org.mockito.exceptions.base.MockitoException:
Cannot mock/spy class retrofit.client.Response
Mockito cannot mock/spy because :
final class
at
com.netflix.spinnaker.orca.clouddriver.tasks.monitoreddeploy.MonitoredDeployBaseTaskTest.shouldReturnOnlyStatusWhenExceptionThrownWhileParsingHttpErrorBody(MonitoredDeployBaseTaskTest.java:217)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)