-
Notifications
You must be signed in to change notification settings - Fork 1
Add a wait on stop run and remove running check on delete #1211
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
Open
lalepee
wants to merge
7
commits into
main
Choose a base branch
from
LAL/BUG-async_stop_run-PROD-16436
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a508b38
Add a wait on stop run and remove running check on delete
lalepee 8f70fce
fix: set status after lauching deletion process and set a garde on do…
lalepee 67ac053
fix keep check on running run to stay in fix version scope
lalepee 83c1e22
fix check on terminal state
lalepee cce3dfd
add unit test on runStop func
lalepee dc213f1
fix NPE on runner with no run
lalepee 29db5e7
fix remove irrelevent code
lalepee 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
Some comments aren't visible on the classic Files Changed page.
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
147 changes: 147 additions & 0 deletions
147
run/src/test/kotlin/com/cosmotech/run/service/RunServiceImplTests.kt
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 |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| // Copyright (c) Cosmo Tech. | ||
| // Licensed under the MIT license. | ||
| package com.cosmotech.run.service | ||
|
|
||
| import com.cosmotech.common.events.RunStop | ||
| import com.cosmotech.common.rbac.CsmRbac | ||
| import com.cosmotech.common.rbac.ROLE_ADMIN | ||
| import com.cosmotech.run.RunContainerFactory | ||
| import com.cosmotech.run.domain.Run | ||
| import com.cosmotech.run.domain.RunEditInfo | ||
| import com.cosmotech.run.domain.RunState | ||
| import com.cosmotech.run.domain.RunStatus | ||
| import com.cosmotech.run.repository.RunRepository | ||
| import com.cosmotech.run.workflow.WorkflowService | ||
| import com.cosmotech.runner.RunnerApiServiceInterface | ||
| import com.cosmotech.runner.domain.LastRunInfo | ||
| import com.cosmotech.runner.domain.Runner | ||
| import com.cosmotech.runner.domain.RunnerAccessControl | ||
| import com.cosmotech.runner.domain.RunnerDatasets | ||
| import com.cosmotech.runner.domain.RunnerEditInfo | ||
| import com.cosmotech.runner.domain.RunnerSecurity | ||
| import com.cosmotech.runner.domain.RunnerValidationStatus | ||
| import io.mockk.MockKAnnotations | ||
| import io.mockk.every | ||
| import io.mockk.impl.annotations.InjectMockKs | ||
| import io.mockk.impl.annotations.MockK | ||
| import io.mockk.impl.annotations.RelaxedMockK | ||
| import io.mockk.junit5.MockKExtension | ||
| import io.mockk.slot | ||
| import io.mockk.verify | ||
| import java.util.Optional | ||
| import kotlin.test.BeforeTest | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertFailsWith | ||
| import org.junit.jupiter.api.Assertions.assertEquals | ||
| import org.junit.jupiter.api.extension.ExtendWith | ||
|
|
||
| private const val ORGANIZATION_ID = "o-organizationid" | ||
| private const val WORKSPACE_ID = "w-workspaceid" | ||
| private const val RUNNER_ID = "r-runnerid" | ||
| private const val RUN_ID = "run-runid" | ||
|
|
||
| @ExtendWith(MockKExtension::class) | ||
| class RunServiceImplTests { | ||
|
|
||
| @Suppress("unused") @MockK private lateinit var containerFactory: RunContainerFactory | ||
| @MockK private lateinit var workflowService: WorkflowService | ||
| @MockK private lateinit var runnerApiService: RunnerApiServiceInterface | ||
| @MockK private lateinit var runRepository: RunRepository | ||
| @Suppress("unused") @RelaxedMockK private lateinit var csmRbac: CsmRbac | ||
|
|
||
| @InjectMockKs private lateinit var runServiceImpl: RunServiceImpl | ||
|
|
||
| @BeforeTest | ||
| fun setUp() { | ||
| MockKAnnotations.init(this) | ||
| } | ||
|
|
||
| private fun buildRunner(lastRunId: String? = RUN_ID) = | ||
| Runner( | ||
| id = RUNNER_ID, | ||
| name = "runner", | ||
| createInfo = RunnerEditInfo(timestamp = 0L, userId = "user"), | ||
| updateInfo = RunnerEditInfo(timestamp = 0L, userId = "user"), | ||
| solutionId = "sol-id", | ||
| runTemplateId = "runtemplate-id", | ||
| organizationId = ORGANIZATION_ID, | ||
| workspaceId = WORKSPACE_ID, | ||
| datasets = RunnerDatasets(bases = mutableListOf(), parameter = ""), | ||
| parametersValues = mutableListOf(), | ||
| lastRunInfo = | ||
| LastRunInfo( | ||
| lastRunId = lastRunId, | ||
| lastRunStatus = LastRunInfo.LastRunStatus.Running, | ||
| ), | ||
| validationStatus = RunnerValidationStatus.Validated, | ||
| security = | ||
| RunnerSecurity( | ||
| default = ROLE_ADMIN, | ||
| accessControlList = | ||
| mutableListOf(RunnerAccessControl(id = "user", role = ROLE_ADMIN)), | ||
| ), | ||
| ) | ||
|
|
||
| private fun buildRun(state: RunState?) = | ||
| Run( | ||
| id = RUN_ID, | ||
| organizationId = ORGANIZATION_ID, | ||
| workspaceId = WORKSPACE_ID, | ||
| runnerId = RUNNER_ID, | ||
| state = state, | ||
| createInfo = RunEditInfo(timestamp = 0L, userId = "user"), | ||
| ) | ||
|
|
||
| @Test | ||
| fun `onRunStop stops workflow and sets run state to Failed when run is not in terminal state`() { | ||
| val runner = buildRunner() | ||
| val run = buildRun(RunState.Running) | ||
| val runStopRequest = RunStop(this, runner) | ||
|
|
||
| every { runnerApiService.getRunner(ORGANIZATION_ID, WORKSPACE_ID, RUNNER_ID) } returns runner | ||
| every { runRepository.findBy(ORGANIZATION_ID, WORKSPACE_ID, RUNNER_ID, RUN_ID) } returns | ||
| Optional.of<Run>(run) | ||
| every { workflowService.getRunStatus(run) } returns RunStatus(id = RUN_ID, phase = "Running") | ||
| every { workflowService.stopWorkflow(run) } returns RunStatus(id = RUN_ID) | ||
|
|
||
| val savedRunSlot = slot<Run>() | ||
| every { runRepository.save(capture(savedRunSlot)) } answers { savedRunSlot.captured } | ||
|
|
||
| runServiceImpl.onRunStop(runStopRequest) | ||
|
|
||
| verify(exactly = 1) { workflowService.stopWorkflow(run) } | ||
| assertEquals(RunState.Failed, savedRunSlot.captured.state) | ||
| } | ||
|
|
||
| @Test | ||
| fun `onRunStop throws IllegalStateException when run is Successful (terminal state)`() { | ||
| val runner = buildRunner() | ||
| val run = buildRun(RunState.Successful) | ||
| val runStopRequest = RunStop(this, runner) | ||
|
|
||
| every { runnerApiService.getRunner(ORGANIZATION_ID, WORKSPACE_ID, RUNNER_ID) } returns runner | ||
| every { runRepository.findBy(ORGANIZATION_ID, WORKSPACE_ID, RUNNER_ID, RUN_ID) } returns | ||
| Optional.of(run) | ||
|
|
||
| assertFailsWith<IllegalStateException> { runServiceImpl.onRunStop(runStopRequest) } | ||
|
|
||
| verify(exactly = 0) { workflowService.stopWorkflow(any()) } | ||
| verify(exactly = 0) { runRepository.save(any()) } | ||
| } | ||
|
|
||
| @Test | ||
| fun `onRunStop throws IllegalStateException when run is Failed (terminal state)`() { | ||
| val runner = buildRunner() | ||
| val run = buildRun(RunState.Failed) | ||
| val runStopRequest = RunStop(this, runner) | ||
|
|
||
| every { runnerApiService.getRunner(ORGANIZATION_ID, WORKSPACE_ID, RUNNER_ID) } returns runner | ||
| every { runRepository.findBy(ORGANIZATION_ID, WORKSPACE_ID, RUNNER_ID, RUN_ID) } returns | ||
| Optional.of(run) | ||
|
|
||
| assertFailsWith<IllegalStateException> { runServiceImpl.onRunStop(runStopRequest) } | ||
|
|
||
| verify(exactly = 0) { workflowService.stopWorkflow(any()) } | ||
| verify(exactly = 0) { runRepository.save(any()) } | ||
| } | ||
| } |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.