Skip to content

Commit

Permalink
add integration test for inline stop action
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed May 9, 2023
1 parent ef5237f commit 83c2878
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 23 deletions.
46 changes: 23 additions & 23 deletions extension/src/experiments/model/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,10 @@ export class ExperimentsTree
}

private registerWorkaroundCommands() {
const callCommandWithSelected = async (
command:
| RegisteredCliCommands.EXPERIMENT_VIEW_REMOVE
| RegisteredCliCommands.EXPERIMENT_VIEW_PUSH
| RegisteredCommands.EXPERIMENT_VIEW_STOP,
experimentItem: ExperimentItem | string,
types: ExperimentType[]
) => {
const selected = [
...this.getSelectedExperimentItems(),
experimentItem
] as (string | ExperimentItem)[]

const acc = collectExperimentType(selected, new Set(types))

for (const [dvcRoot, ids] of Object.entries(acc)) {
await commands.executeCommand(command, { dvcRoot, ids: [...ids] })
}
}

commands.registerCommand(
'dvc.views.experimentsTree.removeExperiment',
(experimentItem: ExperimentItem) =>
callCommandWithSelected(
this.callCommandWithSelected(
RegisteredCliCommands.EXPERIMENT_VIEW_REMOVE,
experimentItem,
[ExperimentType.EXPERIMENT, ExperimentType.QUEUED]
Expand All @@ -157,7 +137,7 @@ export class ExperimentsTree
commands.registerCommand(
'dvc.views.experimentsTree.pushExperiment',
(experimentItem: ExperimentItem) =>
callCommandWithSelected(
this.callCommandWithSelected(
RegisteredCliCommands.EXPERIMENT_VIEW_PUSH,
experimentItem,
[ExperimentType.EXPERIMENT]
Expand All @@ -167,14 +147,34 @@ export class ExperimentsTree
commands.registerCommand(
'dvc.views.experimentsTree.stopExperiment',
(experimentItem: ExperimentItem) =>
callCommandWithSelected(
this.callCommandWithSelected(
RegisteredCommands.EXPERIMENT_VIEW_STOP,
experimentItem,
[ExperimentType.RUNNING]
)
)
}

private async callCommandWithSelected(
command:
| RegisteredCliCommands.EXPERIMENT_VIEW_REMOVE
| RegisteredCliCommands.EXPERIMENT_VIEW_PUSH
| RegisteredCommands.EXPERIMENT_VIEW_STOP,
experimentItem: ExperimentItem | string,
types: ExperimentType[]
) {
const selected = [...this.getSelectedExperimentItems(), experimentItem] as (
| string
| ExperimentItem
)[]

const acc = collectExperimentType(selected, new Set(types))

for (const [dvcRoot, ids] of Object.entries(acc)) {
await commands.executeCommand(command, { dvcRoot, ids: [...ids] })
}
}

private async getRootElements() {
await this.experiments.isReady()
const dvcRoots = this.experiments.getDvcRoots()
Expand Down
49 changes: 49 additions & 0 deletions extension/src/test/suite/experiments/model/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,55 @@ suite('Experiments Tree Test Suite', () => {
)
})

it('should be able to stop multiple running experiments with dvc.views.experimentsTree.stopExperiment', async () => {
bypassProgressCloseDelay()
const mockFirstExperimentId = 'first-exp-stopped'
const mockSecondExperimentId = 'second-exp-stopped'
const mockQueuedExperimentLabel = 'queued-excluded'

const mockStopExperiments = stub(
WorkspaceExperiments.prototype,
'stopExperiments'
).resolves(undefined)

stubPrivatePrototypeMethod(
ExperimentsTree,
'getSelectedExperimentItems'
).returns([
dvcDemoPath,
{
dvcRoot: dvcDemoPath,
label: mockQueuedExperimentLabel,
type: ExperimentType.QUEUED
},
{
dvcRoot: dvcDemoPath,
id: mockFirstExperimentId,
type: ExperimentType.RUNNING
},
{
dvcRoot: dvcDemoPath,
id: 'workspace-excluded',
type: ExperimentType.WORKSPACE
}
])

await commands.executeCommand(
'dvc.views.experimentsTree.stopExperiment',
{
dvcRoot: dvcDemoPath,
id: mockSecondExperimentId,
type: ExperimentType.RUNNING
}
)

expect(mockStopExperiments).to.be.calledWithExactly(
dvcDemoPath,
mockFirstExperimentId,
mockSecondExperimentId
)
})

it('should be able to apply an experiment to the workspace with dvc.views.experiments.applyExperiment', async () => {
const { experiments } = buildExperiments(disposable)

Expand Down

0 comments on commit 83c2878

Please sign in to comment.