Skip to content

Commit d481b84

Browse files
committed
test(deploymentmonitor): Add Test Case for EvaluateDeploymentTask
This commit introduces a test case aimed at demonstrating the existing behaviour of the ‘EvaluateDeploymentTask’ task. The primary objective of this test case is to verify the proper handling of ‘RetrofitError’ thrown by the retrofit client when interacting with DeploymentMonitorService APIs. Details: - Added a dedicated test case to assess the behaviour of ‘EvaluateDeploymentTask’. - The test case specifically focuses on handling ‘RetrofitError’ instances thrown by DeploymentMonitorService APIs. - This step is essential for understanding and validating the current behaviour of the task in response to potential errors during API interactions. This test case serves as a baseline for future modifications and enhancements related to the ‘EvaluateDeploymentTask’.
1 parent adc81ac commit d481b84

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/monitoreddeploy/EvaluateDeploymentHealthTaskSpec.groovy

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,23 @@
1616

1717
package com.netflix.spinnaker.orca.clouddriver.tasks.monitoreddeploy
1818

19+
import com.fasterxml.jackson.databind.ObjectMapper
1920
import com.netflix.spectator.api.NoopRegistry
2021
import com.netflix.spinnaker.config.DeploymentMonitorDefinition
2122
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus
2223
import com.netflix.spinnaker.orca.api.pipeline.TaskResult
24+
import com.netflix.spinnaker.orca.clouddriver.MortServiceSpec
2325
import com.netflix.spinnaker.orca.deploymentmonitor.DeploymentMonitorService
2426
import com.netflix.spinnaker.orca.deploymentmonitor.models.DeploymentMonitorStageConfig
2527
import com.netflix.spinnaker.orca.deploymentmonitor.models.DeploymentStep
2628
import com.netflix.spinnaker.orca.deploymentmonitor.models.EvaluateHealthResponse
2729
import com.netflix.spinnaker.orca.deploymentmonitor.models.MonitoredDeployInternalStageData
2830
import com.netflix.spinnaker.orca.pipeline.model.PipelineExecutionImpl
2931
import com.netflix.spinnaker.orca.pipeline.model.StageExecutionImpl
32+
import org.springframework.http.HttpStatus
3033
import retrofit.RetrofitError
34+
import retrofit.client.Response
35+
import retrofit.converter.JacksonConverter
3136
import spock.lang.Specification
3237
import com.netflix.spinnaker.orca.deploymentmonitor.DeploymentMonitorServiceProvider
3338
import spock.lang.Unroll
@@ -198,6 +203,50 @@ class EvaluateDeploymentHealthTaskSpec extends Specification {
198203
false | null || ExecutionStatus.FAILED_CONTINUE
199204
}
200205

206+
def "should return status as RUNNING when Retrofit http error is thrown"() {
207+
208+
def converter = new JacksonConverter(new ObjectMapper())
209+
210+
Response response =
211+
new Response(
212+
"/deployment/evaluateHealth",
213+
HttpStatus.BAD_REQUEST.value(),
214+
"bad-request",
215+
Collections.emptyList(),
216+
new MortServiceSpec.MockTypedInput(converter, [
217+
accountName: "account",
218+
description: "simple description",
219+
name: "sg1",
220+
region: "region",
221+
type: "openstack"
222+
]))
223+
224+
given:
225+
def monitorServiceStub = Stub(DeploymentMonitorService) {
226+
evaluateHealth(_) >> {
227+
throw RetrofitError.httpError("https://foo.com/deployment/evaluateHealth", response, converter, null)
228+
}
229+
}
230+
231+
def serviceProviderStub = getServiceProviderStub(monitorServiceStub)
232+
233+
def task = new EvaluateDeploymentHealthTask(serviceProviderStub, new NoopRegistry())
234+
235+
MonitoredDeployInternalStageData stageData = new MonitoredDeployInternalStageData()
236+
stageData.deploymentMonitor = new DeploymentMonitorStageConfig()
237+
stageData.deploymentMonitor.id = "LogMonitorId"
238+
239+
def stage = new StageExecutionImpl(pipe, "evaluateDeploymentHealth", stageData.toContextMap() + [application: pipe.application])
240+
stage.startTime = Instant.now().toEpochMilli()
241+
242+
when: 'we can still retry'
243+
TaskResult result = task.execute(stage)
244+
245+
then: 'should retry'
246+
result.status == ExecutionStatus.RUNNING
247+
result.context.deployMonitorHttpRetryCount == 1
248+
}
249+
201250
private getServiceProviderStub(monitorServiceStub) {
202251
return getServiceProviderStub(monitorServiceStub, {})
203252
}

0 commit comments

Comments
 (0)