Skip to content

Commit

Permalink
Fix compilation problems and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kinow committed Sep 6, 2021
1 parent 045123a commit c1022fa
Show file tree
Hide file tree
Showing 14 changed files with 324 additions and 420 deletions.
3 changes: 2 additions & 1 deletion src/components/cylc/common/deltas.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ function applyDeltasUpdated (updated, lookup) {
*/
function applyDeltasPruned (pruned, lookup) {
for (const prunedData of Object.values(pick(pruned, KEYS))) {
for (const id of prunedData) {
const items = isArray(prunedData) ? prunedData : [prunedData]
for (const id of items) {
if (lookup[id]) {
delete lookup[id]
}
Expand Down
35 changes: 6 additions & 29 deletions src/components/cylc/tree/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*/

import DeltasCallback from '@/services/callbacks'
import * as CylcTree from '@/components/cylc/tree/index'
import {
before,
after,
applyDeltasAdded,
applyDeltasUpdated,
applyDeltasPruned
Expand Down Expand Up @@ -46,39 +47,15 @@ class TreeCallback extends DeltasCallback {
before (deltas, store, errors) {
const lookup = store.state.workflows.lookup
const workflow = store.state.workflows.workflow
// first we check whether it is a new initial-data-burst
if (deltas && deltas.added && deltas.added.workflow) {
CylcTree.clear(workflow)
}
// Safe check in case the tree is empty.
if (CylcTree.isEmpty(workflow)) {
// When the tree is empty, we have two possible scenarios:
// 1. This means that we will receive our initial data burst in deltas.added
// which we can use to create the tree structure.
// 2. Or this means that after the shutdown (when we delete the tree), we received a delta.
// In this case we don't really have any way to fix the tree.
// In both cases, actually, the user has little that s/he could do, besides refreshing the
// page. So we fail silently and wait for a request with the initial data.
//
// We need at least a deltas.added.workflow in the deltas data, since it is the root node.
if (!deltas.added || !deltas.added.workflow) {
errors.push([
'Received a Tree delta before the workflow initial data burst',
deltas.added,
workflow,
lookup
])
}
}
this.workflow = Object.assign({}, workflow)
this.lookup = Object.assign({}, lookup)
const results = before(deltas, this.workflow, this.lookup)
errors.push(...results.errors)
}

after (deltas, store, errors) {
// if added, removed, or updated deltas, we want to re-calculate the cycle point states now
if (deltas.pruned || deltas.added || deltas.updated) {
CylcTree.tallyCyclePointStates(this.workflow)
}
const results = after(deltas, this.workflow, null)
errors.push(...results.errors)
}

tearDown (store, errors) {
Expand Down
54 changes: 54 additions & 0 deletions src/components/cylc/tree/deltas.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,58 @@ import {
} from '@/components/cylc/tree/nodes'
import * as CylcTree from '@/components/cylc/tree/index'

function before (deltas, workflow, lookup) {
const result = {
errors: []
}
// first we check whether it is a new initial-data-burst
if (deltas && deltas.added && deltas.added.workflow) {
CylcTree.clear(workflow)
}
// Safe check in case the tree is empty.
if (CylcTree.isEmpty(workflow)) {
// When the tree is empty, we have two possible scenarios:
// 1. This means that we will receive our initial data burst in deltas.added
// which we can use to create the tree structure.
// 2. Or this means that after the shutdown (when we delete the tree), we received a delta.
// In this case we don't really have any way to fix the tree.
// In both cases, actually, the user has little that s/he could do, besides refreshing the
// page. So we fail silently and wait for a request with the initial data.
//
// We need at least a deltas.added.workflow in the deltas data, since it is the root node.
if (!deltas.added || !deltas.added.workflow) {
result.errors.push([
'Received a Tree delta before the workflow initial data burst',
deltas.added,
workflow,
lookup
])
}
}
return result
}

function after (deltas, workflow, lookup) {
const result = {
errors: []
}
// if added, removed, or updated deltas, we want to re-calculate the cycle point states now
if (deltas.pruned || deltas.added || deltas.updated) {
try {
CylcTree.tallyCyclePointStates(workflow)
} catch (error) {
result.errors.push([
'Error tallying cycle point states, see browser console logs for more. Please reload your browser tab to retrieve the full flow state',
error,
deltas,
workflow,
lookup
])
}
}
return result
}

/**
* Helper object used to iterate added deltas data.
*/
Expand Down Expand Up @@ -170,6 +222,8 @@ function applyDeltasPruned (pruned, workflow, lookup, options) {
}

export {
before,
after,
applyDeltasAdded,
applyDeltasUpdated,
applyDeltasPruned
Expand Down
8 changes: 7 additions & 1 deletion src/model/Subscription.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
import ViewState from '@/model/ViewState.model'
import Alert from '@/model/Alert.model'

/**
* @typedef {Vue} View
* @property {ViewState} viewState
* @property {SubscriptionQuery} query
*/

/**
* A view or component subscription. Views or components will declare a SubscriptionQuery,
* that will be used to create a Subscription.
Expand All @@ -44,7 +50,7 @@ class Subscription {
*/
this.observable = null
/**
* @type {Object.<String, Vue>}
* @type {Object.<String, View>}
*/
this.subscribers = {}
/**
Expand Down
4 changes: 2 additions & 2 deletions src/services/workflow.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class WorkflowService {
// --- GraphQL query subscriptions

/**
* @param {Vue} componentOrView
* @param {View} componentOrView
* @returns {Subscription}
*/
getOrCreateSubscription (componentOrView) {
Expand All @@ -136,7 +136,7 @@ class WorkflowService {
}

/**
* @param {Vue} componentOrView
* @param {View} componentOrView
*/
subscribe (componentOrView) {
// First we retrieve the existing, or create a new subscription (and add to the pool).
Expand Down
56 changes: 25 additions & 31 deletions tests/unit/components/cylc/gscan/deltas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

import { expect } from 'chai'
import WorkflowState from '@/model/WorkflowState.model'
import applyWorkflowsDeltas from '@/components/cylc/gscan/deltas'
import {
applyDeltasAdded,
applyDeltasUpdated,
applyDeltasPruned
} from '@/components/cylc/gscan/deltas'

describe('GScan component', () => {
let workflows
Expand All @@ -32,59 +36,49 @@ describe('GScan component', () => {
describe('Deltas', () => {
describe('Added', () => {
it('should apply added deltas', () => {
const data = {
deltas: {
added: {
workflow: newWorkflow
}
const deltas = {
added: {
workflow: newWorkflow
}
}
applyWorkflowsDeltas(data, workflows)
applyDeltasAdded(deltas.added, workflows)
expect(workflows[newWorkflow.id]).to.not.equal(undefined)
})
})
describe('Updated', () => {
it('should apply updated deltas', () => {
const data = {
deltas: {
added: {
workflow: newWorkflow
}
const deltasAdded = {
added: {
workflow: newWorkflow
}
}
applyWorkflowsDeltas(data, workflows)
applyDeltasAdded(deltasAdded.added, workflows)
expect(workflows[newWorkflow.id].status).to.equal(WorkflowState.PAUSED)
newWorkflow.status = WorkflowState.STOPPED
const updateData = {
deltas: {
updated: {
workflow: newWorkflow
}
const deltasUpdated = {
updated: {
workflow: newWorkflow
}
}
applyWorkflowsDeltas(updateData, workflows)
applyDeltasUpdated(deltasUpdated.updated, workflows)
expect(workflows[newWorkflow.id].status).to.equal(WorkflowState.STOPPED)
})
})
describe('Pruned', () => {
it('should apply pruned deltas', () => {
const data = {
deltas: {
added: {
workflow: newWorkflow
}
const deltasAdded = {
added: {
workflow: newWorkflow
}
}
applyWorkflowsDeltas(data, workflows)
applyDeltasAdded(deltasAdded.added, workflows)
expect(workflows[newWorkflow.id]).to.not.equal(undefined)
const prunedData = {
deltas: {
pruned: {
workflow: newWorkflow.id
}
const deltasPruned = {
pruned: {
workflow: newWorkflow.id
}
}
applyWorkflowsDeltas(prunedData, workflows)
applyDeltasPruned(deltasPruned.pruned, workflows)
expect(workflows[newWorkflow.id]).to.equal(undefined)
})
})
Expand Down
Loading

0 comments on commit c1022fa

Please sign in to comment.