Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jwulf committed Jun 19, 2023
1 parent 9b68cb3 commit 9ea4871
Show file tree
Hide file tree
Showing 21 changed files with 261 additions and 379 deletions.
3 changes: 1 addition & 2 deletions src/__tests__/integration/Client-BroadcastSignal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { cancelProcesses } from '../ lib/cancelProcesses'
import { cancelProcesses } from '../../lib/cancelProcesses'
import { ZBClient } from '../..'
// import { createUniqueTaskType } from '../../lib/createUniqueTaskType'
import { CreateProcessInstanceResponse } from '../../lib/interfaces-grpc-1.0'

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cancelProcesses } from '../ lib/cancelProcesses'
import { cancelProcesses } from '../../lib/cancelProcesses'
import { DeployProcessResponse, ZBClient } from '../..'

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/integration/Client-DeployResource.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cancelProcesses } from '../ lib/cancelProcesses'
import { cancelProcesses } from '../../lib/cancelProcesses'
import { ZBClient, BpmnParser } from '../../index'
import fs from 'fs'
process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/integration/Client-MessageStart.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { v4 as uuid } from 'uuid'
import { DeployProcessResponse, ZBClient } from '../..'
import { cancelProcesses } from '../ lib/cancelProcesses'
import { cancelProcesses } from '../../lib/cancelProcesses'

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
jest.setTimeout(45000)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cancelProcesses } from "../ lib/cancelProcesses";
import { cancelProcesses } from "../../lib/cancelProcesses";
import { DeployProcessResponse, ZBClient } from "../../index";

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/integration/Client-PublishMessage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { v4 as uuid } from 'uuid'
import { DeployProcessResponse, ZBClient } from '../..'
import { cancelProcesses } from '../ lib/cancelProcesses'
import { cancelProcesses } from '../../lib/cancelProcesses'

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
jest.setTimeout(45000)
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/integration/Client-ThrowError.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Duration } from 'typed-duration'
import { ZBClient } from '../..'
import { cancelProcesses } from '../ lib/cancelProcesses'
import { cancelProcesses } from '../../lib/cancelProcesses'

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
jest.setTimeout(25000)
Expand Down
20 changes: 10 additions & 10 deletions src/__tests__/integration/Client-integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import { cancelProcesses } from '../ lib/cancelProcesses'
import { cancelProcesses } from '../../lib/cancelProcesses'
import { ZBClient } from '../../index'
import { CreateProcessInstanceResponse, DeployProcessResponse } from '../../lib/interfaces-grpc-1.0'
import { CreateProcessInstanceResponse } from '../../lib/interfaces-grpc-1.0'

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
jest.setTimeout(30000)

const zbc = new ZBClient()
let wf: CreateProcessInstanceResponse
let test1: DeployProcessResponse
let processId: string

beforeAll(async () => {
test1 = await zbc.deployProcess('./src/__tests__/testdata/hello-world.bpmn')
await cancelProcesses(test1.processes[0].bpmnProcessId)
const res = await zbc.deployProcess('./src/__tests__/testdata/hello-world.bpmn')
processId = res.processes[0].bpmnProcessId
await cancelProcesses(processId)
})

afterEach(async() => {
if (wf && wf.processInstanceKey) {
await zbc.cancelProcessInstance(wf.processInstanceKey).catch(e => e) // Cleanup any active processes
}
await cancelProcesses(test1.processes[0].bpmnProcessId)
await cancelProcesses(processId)
})

afterAll(async () => {
await zbc.close()
await cancelProcesses(test1.processes[0].bpmnProcessId)
await cancelProcesses(processId)
})

test('Can get the broker topology', async () => {
Expand All @@ -43,13 +44,12 @@ test('Can create a worker', async() => {
})

test('Can cancel a process', async () => {


const wf = await zbc.createProcessInstance(test1.processes[0].bpmnProcessId, {})
const wf = await zbc.createProcessInstance(processId, {})
const wfi = wf.processInstanceKey
expect(wfi).toBeTruthy()
await zbc.cancelProcessInstance(wfi)

// expect(async() => await zbc.cancelProcessInstance(wfi)).toThrow()
try {
await zbc.cancelProcessInstance(wfi) // A call to cancel a process that doesn't exist should throw
} catch (e: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/integration/Client-setVariables.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cancelProcesses } from '../ lib/cancelProcesses'
import { cancelProcesses } from '../../lib/cancelProcesses'
import { ZBClient } from '../..'
import { CreateProcessInstanceResponse, DeployProcessResponse } from '../../lib/interfaces-grpc-1.0'

Expand Down
15 changes: 14 additions & 1 deletion src/__tests__/integration/Client-startProcess.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cancelProcesses } from '../ lib/cancelProcesses'
import { cancelProcesses } from '../../lib/cancelProcesses'
import { ZBClient } from '../..'
import { CreateProcessInstanceResponse } from '../../lib/interfaces-grpc-1.0'

Expand All @@ -17,6 +17,19 @@ beforeAll(async () => {
processId2 = (await zbc.deployProcess('./src/__tests__/testdata/Client-SkipFirstTask.bpmn')).processes[0].bpmnProcessId
await cancelProcesses(processId)
await cancelProcesses(processId2)
await zbc.close()
})

beforeEach(() => {
zbc = new ZBClient()
})

afterEach(async () => {
if (id) {
// console.log(`Canceling process id ${id}`)
await zbc.cancelProcessInstance(id).catch(_ => _)
}
await zbc.close()
})

afterAll(async () => {
Expand Down
98 changes: 33 additions & 65 deletions src/__tests__/integration/Worker-1.0-complete.spec.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
import { cancelProcesses } from '../../lib/cancelProcesses'
import { ZBClient } from '../..'
import { createUniqueTaskType } from '../../lib/createUniqueTaskType'
import { CreateProcessInstanceResponse } from '../../lib/interfaces-grpc-1.0'

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
jest.setTimeout(30000)
let zbc: ZBClient
const zbc = new ZBClient()
let wf: CreateProcessInstanceResponse | undefined

beforeEach(async () => {
// tslint:disable-next-line: no-console
// console.log('Creating client...') // @DEBUG
let processId1: string
let processId2: string
let processId3: string

zbc = new ZBClient()
beforeAll(async () => {
const res1 = await zbc.deployProcess('./src/__tests__/testdata/hello-world.bpmn')
processId1 = res1.processes[0].bpmnProcessId
await cancelProcesses(processId1)
const res2 = await zbc.deployProcess('./src/__tests__/testdata/hello-world-complete.bpmn')
processId2 = res2.processes[0].bpmnProcessId
await cancelProcesses(processId2)
const res3 = await zbc.deployProcess('./src/__tests__/testdata/conditional-pathway.bpmn')
processId3 = res3.processes[0].bpmnProcessId
await cancelProcesses(processId3)
})

afterEach(async () => {
try {
if (wf?.processInstanceKey) {
await zbc.cancelProcessInstance(wf.processInstanceKey).catch(e => e)
}
} finally {
await zbc.close() // Makes sure we don't forget to close connection
} catch {

}
})

afterAll(async() => {
await zbc.close()
await cancelProcesses(processId1)
await cancelProcesses(processId2)
await cancelProcesses(processId3)
})

test('Can service a task', () =>
new Promise(async done => {
const { bpmn, taskTypes, processId } = createUniqueTaskType({
bpmnFilePath: './src/__tests__/testdata/hello-world.bpmn',
messages: [],
taskTypes: ['console-log'],
})
const res = await zbc.deployProcess({
definition: bpmn,
name: `service-hello-world-${processId}.bpmn`,
})

expect(res.processes.length).toBe(1)

// tslint:disable-next-line: no-console
// console.log('Creating process instance...') // @DEBUG
wf = await zbc.createProcessInstance(processId, {})
// tslint:disable-next-line: no-console
// console.log('Creating worker...') // @DEBUG

wf = await zbc.createProcessInstance(processId1, {})
zbc.createWorker({
taskType: taskTypes['console-log'],
taskType: 'console-log',
taskHandler: async job => {
expect(job.processInstanceKey).toBe(wf?.processInstanceKey)
const res1 = await job.complete(job.variables)
Expand All @@ -58,24 +57,9 @@ test('Can service a task', () =>

test('Can service a task with complete.success', () =>
new Promise(async done => {
const { bpmn, processId, taskTypes } = createUniqueTaskType({
bpmnFilePath: './src/__tests__/testdata/hello-world-complete.bpmn',
messages: [],
taskTypes: ['console-log-complete'],
})
const res = await zbc.deployProcess({
definition: bpmn,
name: `hello-world-complete-${processId}.bpmn`,
})

expect(res.processes.length).toBe(1)
// tslint:disable-next-line: no-console
// console.log('Creating process instance...') // @DEBUG
wf = await zbc.createProcessInstance(processId, {})
// tslint:disable-next-line: no-console
// console.log('Creating worker...') // @DEBUG
wf = await zbc.createProcessInstance(processId2, {})
zbc.createWorker({
taskType: taskTypes['console-log-complete'],
taskType: 'console-log-complete',
taskHandler: async job => {
expect(job.processInstanceKey).toBe(wf?.processInstanceKey)
const res1 = await job.complete(job.variables)
Expand All @@ -88,29 +72,14 @@ test('Can service a task with complete.success', () =>

test('Can update process variables with complete.success()', () =>
new Promise(async done => {
const { bpmn, taskTypes, processId } = createUniqueTaskType({
bpmnFilePath: './src/__tests__/testdata/conditional-pathway.bpmn',
messages: [],
taskTypes: ['wait', 'pathB'],
})
const res = await zbc.deployProcess({
definition: bpmn,
name: `conditional-pathway-${processId}.bpmn`,
})

expect(res.processes.length).toBe(1)
expect(res.processes[0].bpmnProcessId).toBe(processId)
// tslint:disable-next-line: no-console
// console.log('Creating process instance...') // @DEBUG
wf = await zbc.createProcessInstance(processId, {
wf = await zbc.createProcessInstance(processId3, {
conditionVariable: true,
})
const wfi = wf?.processInstanceKey
expect(wfi).toBeTruthy()
// tslint:disable-next-line: no-console
// console.log('Creating worker...') // @DEBUG

zbc.createWorker({
taskType: taskTypes.wait,
taskType: 'wait',
taskHandler: async job => {
expect(job.processInstanceKey).toBe(wfi)
return job.complete({
Expand All @@ -119,10 +88,9 @@ test('Can update process variables with complete.success()', () =>
},
loglevel: 'NONE',
})
// tslint:disable-next-line: no-console
// console.log('Creating worker...') // @DEBUG

zbc.createWorker({
taskType: taskTypes.pathB,
taskType: 'pathB',
taskHandler: async job => {
expect(job.processInstanceKey).toBe(wfi)
expect(job.variables.conditionVariable).toBe(false)
Expand Down
28 changes: 10 additions & 18 deletions src/__tests__/integration/Worker-BatchWorker.spec.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
import { cancelProcesses } from '../../lib/cancelProcesses'
import { Duration, ZBClient } from '../..'
import { createUniqueTaskType } from '../../lib/createUniqueTaskType'

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
jest.setTimeout(30000)
let zbc: ZBClient
const zbc = new ZBClient()
let processId: string

beforeEach(async () => {
zbc = new ZBClient()
beforeAll(async () => {
const res = await zbc.deployProcess('./src/__tests__/testdata/hello-world.bpmn')
processId = res.processes[0].bpmnProcessId
await cancelProcesses(processId)
})

afterEach(async () => {
afterAll(async () => {
await zbc.close() // Makes sure we don't forget to close connection
await cancelProcesses(processId)
})

test('BatchWorker gets ten jobs', () =>
new Promise(async done => {
const { bpmn, taskTypes, processId } = createUniqueTaskType({
bpmnFilePath: './src/__tests__/testdata/hello-world.bpmn',
messages: [],
taskTypes: ['console-log'],
})
const res = await zbc.deployProcess({
definition: bpmn,
name: `service-hello-world-${processId}.bpmn`,
})

expect(res.processes.length).toBe(1)

for (let i = 0; i < 10; i++) {
await zbc.createProcessInstance(processId, {})
}
Expand All @@ -41,6 +33,6 @@ test('BatchWorker gets ten jobs', () =>
done(null)
return res1
},
taskType: taskTypes['console-log'],
taskType: 'console-log',
})
}))
Loading

0 comments on commit 9ea4871

Please sign in to comment.