2020-01-29 16:15:51 +01:00
|
|
|
import { assert } from 'chai'
|
|
|
|
import sinon from 'sinon'
|
2020-01-21 21:21:19 +01:00
|
|
|
|
2020-01-31 00:15:55 +01:00
|
|
|
import { Ocean } from '../../../src/ocean/Ocean'
|
2020-01-21 21:21:19 +01:00
|
|
|
import config from '../config'
|
2020-01-31 00:15:55 +01:00
|
|
|
import { Account } from '../../../src/squid'
|
|
|
|
import { OceanCompute, ComputeJobStatus } from '../../../src/ocean/OceanCompute'
|
2020-01-29 16:15:51 +01:00
|
|
|
import TestIdGenerator from '../TestIdGenerator'
|
2020-01-21 21:21:19 +01:00
|
|
|
|
|
|
|
describe('OceanCompute', () => {
|
|
|
|
let ocean: Ocean
|
|
|
|
let account: Account
|
|
|
|
let compute: OceanCompute
|
2020-01-29 16:15:51 +01:00
|
|
|
let agreementId: string
|
2020-01-21 21:21:19 +01:00
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
ocean = await Ocean.getInstance(config)
|
|
|
|
;[account] = await ocean.accounts.list()
|
|
|
|
compute = ocean.compute // eslint-disable-line prefer-destructuring
|
2020-01-29 16:15:51 +01:00
|
|
|
agreementId = TestIdGenerator.generatePrefixedId()
|
2020-01-21 21:21:19 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
2020-01-29 16:15:51 +01:00
|
|
|
sinon.reset()
|
|
|
|
sinon.restore()
|
2020-01-21 21:21:19 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('#start()', () => {
|
|
|
|
it('should start a new job', async () => {
|
2020-03-06 11:35:31 +01:00
|
|
|
sinon.stub(ocean.brizo, 'compute').returns([{ jobId: 'my-job-id' }] as any)
|
2020-01-29 16:15:51 +01:00
|
|
|
const response = await compute.start(account, agreementId, 'did:op:0xxx')
|
2020-01-21 21:21:19 +01:00
|
|
|
assert(response.jobId === 'my-job-id')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('#stop()', () => {
|
|
|
|
it('should stop a job', async () => {
|
2020-01-29 16:15:51 +01:00
|
|
|
sinon
|
|
|
|
.stub(ocean.brizo, 'compute')
|
2020-03-06 11:35:31 +01:00
|
|
|
.returns([{ status: ComputeJobStatus.Completed }] as any)
|
2020-01-21 21:21:19 +01:00
|
|
|
|
2020-01-29 16:15:51 +01:00
|
|
|
const response = await compute.stop(account, agreementId, 'xxx')
|
2020-01-28 18:00:06 +01:00
|
|
|
assert(response.status === ComputeJobStatus.Completed)
|
2020-01-21 21:21:19 +01:00
|
|
|
})
|
|
|
|
})
|
2020-01-22 11:30:27 +01:00
|
|
|
|
|
|
|
describe('#restart()', () => {
|
|
|
|
it('should restart a job', async () => {
|
2020-01-29 16:15:51 +01:00
|
|
|
sinon
|
|
|
|
.stub(ocean.brizo, 'compute')
|
2020-03-06 11:35:31 +01:00
|
|
|
.returns([{ status: ComputeJobStatus.Started, jobId: 'my-job-id' }] as any)
|
2020-01-22 11:30:27 +01:00
|
|
|
|
2020-01-29 16:15:51 +01:00
|
|
|
const response = await compute.restart(account, agreementId, 'xxx')
|
2020-01-22 11:30:27 +01:00
|
|
|
assert(response.jobId === 'my-job-id')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('#delete()', () => {
|
|
|
|
it('should delete a job', async () => {
|
2020-01-29 16:15:51 +01:00
|
|
|
sinon
|
|
|
|
.stub(ocean.brizo, 'compute')
|
2020-03-06 11:35:31 +01:00
|
|
|
.returns([{ status: ComputeJobStatus.Deleted }] as any)
|
2020-01-22 11:30:27 +01:00
|
|
|
|
2020-01-29 16:15:51 +01:00
|
|
|
const response = await compute.delete(account, agreementId, 'xxx')
|
2020-01-28 18:00:06 +01:00
|
|
|
assert(response.status === ComputeJobStatus.Deleted)
|
2020-01-22 11:30:27 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('#status()', () => {
|
|
|
|
it('should get the status of one job', async () => {
|
2020-01-29 16:15:51 +01:00
|
|
|
sinon
|
|
|
|
.stub(ocean.brizo, 'compute')
|
|
|
|
.returns([{ status: ComputeJobStatus.Started }] as any)
|
2020-01-22 11:30:27 +01:00
|
|
|
|
2020-01-29 16:15:51 +01:00
|
|
|
const response = await compute.status(account, agreementId, 'xxx')
|
2020-01-22 11:30:27 +01:00
|
|
|
assert(response.length === 1)
|
2020-01-28 18:00:06 +01:00
|
|
|
assert(response[0].status === ComputeJobStatus.Started)
|
2020-01-22 11:30:27 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the status of multiple jobs', async () => {
|
2020-01-29 16:15:51 +01:00
|
|
|
sinon
|
|
|
|
.stub(ocean.brizo, 'compute')
|
|
|
|
.returns([
|
2020-01-28 18:00:06 +01:00
|
|
|
{ status: ComputeJobStatus.Started },
|
|
|
|
{ status: ComputeJobStatus.Started }
|
2020-01-29 16:15:51 +01:00
|
|
|
] as any)
|
2020-01-22 11:30:27 +01:00
|
|
|
|
2020-01-29 16:15:51 +01:00
|
|
|
const response = await compute.status(account, agreementId)
|
2020-01-22 11:30:27 +01:00
|
|
|
assert(response.length === 2)
|
2020-01-28 18:00:06 +01:00
|
|
|
assert(response[0].status === ComputeJobStatus.Started)
|
2020-01-22 11:30:27 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should get all jobs for one owner', async () => {
|
2020-01-29 16:15:51 +01:00
|
|
|
sinon
|
|
|
|
.stub(ocean.brizo, 'compute')
|
|
|
|
.returns([
|
2020-01-28 18:00:06 +01:00
|
|
|
{ status: ComputeJobStatus.Started },
|
|
|
|
{ status: ComputeJobStatus.Started }
|
2020-01-29 16:15:51 +01:00
|
|
|
] as any)
|
2020-01-22 11:30:27 +01:00
|
|
|
|
|
|
|
const response = await compute.status(account)
|
|
|
|
assert(response.length === 2)
|
2020-01-28 18:00:06 +01:00
|
|
|
assert(response[0].status === ComputeJobStatus.Started)
|
2020-01-22 11:30:27 +01:00
|
|
|
})
|
|
|
|
})
|
2020-02-03 11:46:48 +01:00
|
|
|
|
|
|
|
describe('#checkOutput()', () => {
|
|
|
|
it('should return default values', async () => {
|
|
|
|
const defaultOutput = { publishAlgorithmLog: false, publishOutput: false }
|
|
|
|
const output = compute.checkOutput(account, undefined)
|
|
|
|
assert.deepEqual(output, defaultOutput)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return output values', async () => {
|
|
|
|
const newOutput = {
|
|
|
|
publishAlgorithmLog: true,
|
|
|
|
publishOutput: true,
|
|
|
|
brizoAddress: 'hello',
|
|
|
|
brizoUri: 'hello',
|
|
|
|
metadataUri: 'hello',
|
|
|
|
nodeUri: 'hello',
|
|
|
|
owner: '0xhello',
|
|
|
|
secretStoreUri: 'hello'
|
|
|
|
}
|
|
|
|
const output = compute.checkOutput(account, newOutput)
|
|
|
|
assert.deepEqual(output, newOutput)
|
|
|
|
})
|
|
|
|
})
|
2020-01-21 21:21:19 +01:00
|
|
|
})
|