|
| 1 | +import { |
| 2 | + assignNodesToJobUpdate, |
| 3 | + startClusterSignal, |
| 4 | + shutdownClusterSignal, |
| 5 | + deleteJobUpdate, |
| 6 | + getClusterStatusQuery, |
| 7 | +} from './workflows'; |
| 8 | +import { startClusterManager } from './client'; |
| 9 | +import assert from 'assert'; |
| 10 | + |
| 11 | +async function testClusterManager() { |
| 12 | + const workflow = await startClusterManager(); |
| 13 | + await workflow.signal(startClusterSignal); |
| 14 | + const request1 = { |
| 15 | + numNodes: 5, |
| 16 | + jobName: 'job1', |
| 17 | + }; |
| 18 | + |
| 19 | + // Use an update to assign nodes. |
| 20 | + const updateResult1 = await workflow.executeUpdate(assignNodesToJobUpdate, { |
| 21 | + args: [request1], |
| 22 | + }); |
| 23 | + assert.equal(updateResult1.assignedNodes, request1.numNodes); |
| 24 | + assert.equal(updateResult1.maxAssignedNodes, request1.numNodes); |
| 25 | + |
| 26 | + // Assign nodes to a job and then delete it |
| 27 | + const request2 = { |
| 28 | + numNodes: 6, |
| 29 | + jobName: 'job2', |
| 30 | + }; |
| 31 | + const updateResult2 = await workflow.executeUpdate(assignNodesToJobUpdate, { |
| 32 | + args: [request2], |
| 33 | + }); |
| 34 | + assert.equal(updateResult2.assignedNodes, request1.numNodes + request2.numNodes); |
| 35 | + assert.equal(updateResult2.maxAssignedNodes, request1.numNodes + request2.numNodes); |
| 36 | + |
| 37 | + await workflow.executeUpdate(deleteJobUpdate, { args: [{ jobName: 'job2' }] }); |
| 38 | + |
| 39 | + // The delete doesn't return anything; use the query to get current cluster state |
| 40 | + const queryResult = await workflow.query(getClusterStatusQuery); |
| 41 | + assert.equal( |
| 42 | + queryResult.assignedNodes, |
| 43 | + request1.numNodes, |
| 44 | + `expected ${request1.numNodes} left after deleting ${request2.numNodes}` |
| 45 | + ); |
| 46 | + assert.equal(queryResult.maxAssignedNodes, request1.numNodes + request2.numNodes); |
| 47 | + |
| 48 | + // Terminate the workflow and check that workflow returns same value as obtained from last query. |
| 49 | + await workflow.signal(shutdownClusterSignal); |
| 50 | + const wfResult = await workflow.result(); |
| 51 | + assert.deepEqual(wfResult, queryResult); |
| 52 | +} |
| 53 | + |
| 54 | +async function runTests() { |
| 55 | + for (const fn of [testClusterManager]) { |
| 56 | + console.log(fn.name); |
| 57 | + await fn(); |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +runTests().catch((err) => { |
| 62 | + console.error(err); |
| 63 | + process.exit(1); |
| 64 | +}); |
0 commit comments