Skip to content

Commit

Permalink
fix(triggers): ensure canceling pipeline sends ExecutionComplete event
Browse files Browse the repository at this point in the history
  • Loading branch information
asher committed Oct 28, 2017
1 parent a0af1b1 commit 0d80769
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
package com.netflix.spinnaker.orca.q.handler

import com.netflix.spinnaker.orca.ExecutionStatus.PAUSED
import com.netflix.spinnaker.orca.ExecutionStatus.CANCELED
import com.netflix.spinnaker.orca.events.ExecutionComplete
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository
import com.netflix.spinnaker.orca.q.*
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Component

@Component
class CancelExecutionHandler(
override val queue: Queue,
override val repository: ExecutionRepository
override val repository: ExecutionRepository,
private val publisher: ApplicationEventPublisher
) : MessageHandler<CancelExecution> {
override val messageType = CancelExecution::class.java

Expand All @@ -43,6 +47,8 @@ class CancelExecutionHandler(

// then, make sure those runTask messages get run right away
queue.push(RescheduleExecution(execution))

publisher.publishEvent(ExecutionComplete(this, message.executionType, message.executionId, CANCELED))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,31 @@

package com.netflix.spinnaker.orca.q.handler

import com.netflix.spinnaker.orca.ExecutionStatus.PAUSED
import com.netflix.spinnaker.orca.ExecutionStatus.RUNNING
import com.netflix.spinnaker.orca.ExecutionStatus.*
import com.netflix.spinnaker.orca.events.ExecutionComplete
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository
import com.netflix.spinnaker.orca.q.*
import com.netflix.spinnaker.spek.shouldEqual
import com.nhaarman.mockito_kotlin.*
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.jetbrains.spek.api.lifecycle.CachingMode
import org.jetbrains.spek.subject.SubjectSpek
import org.springframework.context.ApplicationEventPublisher

object CancelExecutionHandlerTest : SubjectSpek<CancelExecutionHandler>({

val queue: Queue = mock()
val repository: ExecutionRepository = mock()
val publisher: ApplicationEventPublisher = mock()

subject(CachingMode.GROUP) {
CancelExecutionHandler(queue, repository)
CancelExecutionHandler(queue, repository, publisher)
}

fun resetMocks() = reset(queue, repository)
fun resetMocks() = reset(queue, repository, publisher)

describe("cancelling an execution") {
given("there are no paused stages") {
Expand Down Expand Up @@ -69,6 +72,14 @@ object CancelExecutionHandlerTest : SubjectSpek<CancelExecutionHandler>({
verify(queue).push(RescheduleExecution(pipeline))
}

it("publishes an execution complete event") {
verify(publisher).publishEvent(check<ExecutionComplete> {
it.executionType shouldEqual pipeline.javaClass
it.executionId shouldEqual pipeline.id
it.status shouldEqual CANCELED
})
}

it("does not send any further messages") {
verifyZeroInteractions(queue)
}
Expand Down

0 comments on commit 0d80769

Please sign in to comment.