teraslice-client-js 2.16.2 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/src/executions.d.ts +1 -1
  2. package/dist/src/executions.d.ts.map +1 -1
  3. package/package.json +7 -4
  4. package/dist/test/assets-spec.d.ts +0 -2
  5. package/dist/test/assets-spec.d.ts.map +0 -1
  6. package/dist/test/assets-spec.js +0 -322
  7. package/dist/test/assets-spec.js.map +0 -1
  8. package/dist/test/client-spec.d.ts +0 -2
  9. package/dist/test/client-spec.d.ts.map +0 -1
  10. package/dist/test/client-spec.js +0 -374
  11. package/dist/test/client-spec.js.map +0 -1
  12. package/dist/test/cluster-spec.d.ts +0 -2
  13. package/dist/test/cluster-spec.d.ts.map +0 -1
  14. package/dist/test/cluster-spec.js +0 -143
  15. package/dist/test/cluster-spec.js.map +0 -1
  16. package/dist/test/ex-spec.d.ts +0 -2
  17. package/dist/test/ex-spec.d.ts.map +0 -1
  18. package/dist/test/ex-spec.js +0 -550
  19. package/dist/test/ex-spec.js.map +0 -1
  20. package/dist/test/executions-spec.d.ts +0 -2
  21. package/dist/test/executions-spec.d.ts.map +0 -1
  22. package/dist/test/executions-spec.js +0 -233
  23. package/dist/test/executions-spec.js.map +0 -1
  24. package/dist/test/job-spec.d.ts +0 -2
  25. package/dist/test/job-spec.d.ts.map +0 -1
  26. package/dist/test/job-spec.js +0 -837
  27. package/dist/test/job-spec.js.map +0 -1
  28. package/dist/test/jobs-spec.d.ts +0 -2
  29. package/dist/test/jobs-spec.d.ts.map +0 -1
  30. package/dist/test/jobs-spec.js +0 -241
  31. package/dist/test/jobs-spec.js.map +0 -1
  32. package/dist/tsconfig.tsbuildinfo +0 -1
  33. package/examples/cluster.js +0 -13
  34. package/examples/list.js +0 -16
  35. package/examples/submit.js +0 -48
  36. package/src/assets.ts +0 -99
  37. package/src/client.ts +0 -197
  38. package/src/cluster.ts +0 -48
  39. package/src/ex.ts +0 -223
  40. package/src/executions.ts +0 -82
  41. package/src/index.ts +0 -39
  42. package/src/interfaces.ts +0 -12
  43. package/src/job.ts +0 -260
  44. package/src/jobs.ts +0 -66
  45. package/test/assets-spec.ts +0 -376
  46. package/test/client-spec.ts +0 -416
  47. package/test/cluster-spec.ts +0 -167
  48. package/test/ex-spec.ts +0 -628
  49. package/test/executions-spec.ts +0 -260
  50. package/test/fixtures/test.txt +0 -1
  51. package/test/job-spec.ts +0 -947
  52. package/test/jobs-spec.ts +0 -272
  53. package/tsconfig.json +0 -12
package/test/job-spec.ts DELETED
@@ -1,947 +0,0 @@
1
- import nock from 'nock';
2
- import { Teraslice } from '@terascope/types';
3
- import Job from '../src/job.js';
4
-
5
- describe('Teraslice Job', () => {
6
- let scope: nock.Scope;
7
- const baseUrl = 'http://teraslice.example.dev/v1';
8
-
9
- beforeEach(() => {
10
- nock.cleanAll();
11
- scope = nock(baseUrl);
12
- });
13
-
14
- const requestOptions = { headers: { 'Some-Header': 'yes' } };
15
-
16
- const clusterState: any = {
17
- 'some-node-id': {
18
- hostname: 'host',
19
- pid: 111,
20
- node_version: '10',
21
- teraslice_version: 'fabled v1.0',
22
- total: 2,
23
- state: 'connected',
24
- available: 3,
25
- node_id: 'some-node-id',
26
- active: [
27
- {
28
- job_id: 'some-job-id',
29
- ex_id: 'some-ex-id',
30
- worker_id: 'someId',
31
- pid: 1324,
32
- assignment: 'worker'
33
- },
34
- {
35
- job_id: 'some-job-id',
36
- ex_id: 'some-ex-id',
37
- worker_id: 'someId',
38
- pid: 1324,
39
- assignment: 'worker'
40
- }
41
- ]
42
- },
43
- 'some-other-node-id': {
44
- hostname: 'host',
45
- pid: 222,
46
- node_version: '10',
47
- teraslice_version: 'fabled v1.0',
48
- total: 2,
49
- state: 'connected',
50
- available: 3,
51
- node_id: 'some-other-node-id',
52
- active: [
53
- {
54
- job_id: 'some-job-id',
55
- ex_id: 'some-ex-id',
56
- worker_id: 'someId',
57
- pid: 1324,
58
- assignment: 'worker'
59
- },
60
- {
61
- job_id: 'some-other-job-id',
62
- ex_id: 'some-other-ex-id',
63
- worker_id: 'someId',
64
- pid: 1324,
65
- assignment: 'worker'
66
- },
67
- {
68
- job_id: 'some-other-job-id',
69
- ex_id: 'some-other-ex-id',
70
- worker_id: 'someId',
71
- pid: 1324,
72
- assignment: 'execution_controller'
73
- }
74
- ]
75
- }
76
- };
77
- const date = new Date().toISOString();
78
-
79
- const executionResults: Teraslice.ExecutionConfig[] = [
80
- {
81
- active: true,
82
- analytics: false,
83
- assets: [],
84
- lifecycle: 'once',
85
- max_retries: 3,
86
- name: 'some_name',
87
- apis: [],
88
- operations: [{ _op: 'someOp' }],
89
- probation_window: 3,
90
- env_vars: {},
91
- slicers: 1,
92
- workers: 1,
93
- metadata: {},
94
- _created: date,
95
- _updated: date,
96
- _context: 'ex',
97
- _status: Teraslice.ExecutionStatusEnum.running,
98
- ex_id: '123456789',
99
- job_id: '123456789',
100
- slicer_hostname: 'hostname',
101
- slicer_port: 5673,
102
- _has_errors: false,
103
- _slicer_stats: {},
104
- _failureReason: '',
105
- teraslice_version: 'v3.0.0'
106
- },
107
- ];
108
-
109
- describe('->id', () => {
110
- describe('when constructed without a jobId', () => {
111
- it('should throw an error', () => {
112
- // @ts-expect-error
113
- expect(() => new Job()).toThrow('Job requires jobId');
114
- });
115
- });
116
-
117
- describe('when constructed with a invalid jobId', () => {
118
- it('should throw an error', () => {
119
- // @ts-expect-error
120
- expect(() => new Job({}, { invalid: true })).toThrow('Job requires jobId to be a string');
121
- });
122
- });
123
-
124
- describe('when constructed with a jobId', () => {
125
- it('should return the jobId', () => {
126
- const job = new Job({}, 'some-job-id');
127
- expect(job.id()).toEqual('some-job-id');
128
- });
129
- });
130
- });
131
-
132
- describe('->slicer', () => {
133
- describe('when called with nothing', () => {
134
- beforeEach(() => {
135
- scope.get('/jobs/some-job-id/slicer')
136
- .reply(200, { id: 'example' });
137
- });
138
-
139
- it('should resolve json results from Teraslice', async () => {
140
- const job = new Job({ baseUrl }, 'some-job-id');
141
- const results = await job.slicer();
142
- expect(results).toEqual({ id: 'example' });
143
- });
144
- });
145
- });
146
-
147
- describe('->controller', () => {
148
- describe('when called with nothing', () => {
149
- beforeEach(() => {
150
- scope.get('/jobs/some-job-id/controller')
151
- .reply(200, { id: 'example' });
152
- });
153
-
154
- it('should resolve json results from Teraslice', async () => {
155
- const job = new Job({ baseUrl }, 'some-job-id');
156
- const results = await job.controller();
157
- expect(results).toEqual({ id: 'example' });
158
- });
159
- });
160
-
161
- describe('when called with options', () => {
162
- beforeEach(() => {
163
- scope.get('/jobs/some-job-id/controller')
164
- .matchHeader('Some-Header', 'yes')
165
- .reply(200, { foo: 'bar' });
166
- });
167
-
168
- it('should resolve json results from Teraslice', async () => {
169
- const job = new Job({ baseUrl }, 'some-job-id');
170
- const results = await job.controller(requestOptions);
171
- expect(results).toEqual({ foo: 'bar' });
172
- });
173
- });
174
- });
175
-
176
- const methodTestCases = [
177
- 'start',
178
- 'stop',
179
- 'pause',
180
- 'resume'
181
- ] as const;
182
- describe.each(methodTestCases)('->%s', (method) => {
183
- describe('when called with nothing', () => {
184
- beforeEach(() => {
185
- scope.post(`/jobs/some-job-id/_${method}`)
186
- .reply(200, { testMethod: method });
187
- });
188
-
189
- it('should resolve json results from Teraslice', async () => {
190
- const job = new Job({ baseUrl }, 'some-job-id');
191
- const results = await job[method]();
192
- expect(results).toEqual({ testMethod: method });
193
- });
194
- });
195
-
196
- describe('when called with a query', () => {
197
- beforeEach(() => {
198
- scope.post(`/jobs/some-job-id/_${method}`)
199
- .query({ someParam: 'yes' })
200
- .reply(200, { key: 'some-other-key' });
201
- });
202
-
203
- it('should resolve json results from Teraslice', async () => {
204
- const job = new Job({ baseUrl }, 'some-job-id');
205
- const results = await job[method]({ someParam: 'yes' });
206
- expect(results).toEqual({ key: 'some-other-key' });
207
- });
208
- });
209
-
210
- describe('when called with a query and options', () => {
211
- beforeEach(() => {
212
- scope.post(`/jobs/some-job-id/_${method}`)
213
- .query({ foo: 'bar' })
214
- .matchHeader('Some-Header', 'yes')
215
- .reply(200, { key: 'some-random-key' });
216
- });
217
-
218
- it('should resolve json results from Teraslice', async () => {
219
- const job = new Job({ baseUrl }, 'some-job-id');
220
- const results = await job[method]({ foo: 'bar' }, requestOptions);
221
- expect(results).toEqual({ key: 'some-random-key' });
222
- });
223
- });
224
- });
225
-
226
- describe('->start', () => {
227
- describe('when the server returns deprecation warnings', () => {
228
- const deprecationWarning: Teraslice.JobWarning = {
229
- type: 'JobValidation',
230
- reason: {
231
- type: 'assetOperation',
232
- kind: 'deprecation',
233
- reason: {
234
- _op: 'some-op',
235
- field: 'old_field',
236
- description: 'old_field is deprecated, use new_field instead',
237
- },
238
- },
239
- };
240
-
241
- const response: Teraslice.ApiJobCreateResponse = {
242
- job_id: 'some-job-id',
243
- warnings: [deprecationWarning],
244
- };
245
-
246
- beforeEach(() => {
247
- scope.post('/jobs/some-job-id/_start')
248
- .reply(200, response);
249
- });
250
-
251
- it('should return the response with warnings', async () => {
252
- const job = new Job({ baseUrl }, 'some-job-id');
253
- const result = await job.start();
254
- expect(result.job_id).toEqual('some-job-id');
255
- expect(result.warnings).toBeArrayOfSize(1);
256
- expect(result.warnings![0]).toMatchObject(deprecationWarning);
257
- });
258
- });
259
- });
260
-
261
- describe('->recover', () => {
262
- describe('when called with nothing', () => {
263
- beforeEach(() => {
264
- scope.post('/jobs/some-other-job-id/_recover')
265
- .reply(200, { job_id: 'some-other-job-id' });
266
- });
267
-
268
- it('should resolve json results from Teraslice', async () => {
269
- const job = new Job({ baseUrl }, 'some-other-job-id');
270
- const results = await job.recover();
271
- expect(results).toEqual({ job_id: 'some-other-job-id' });
272
- });
273
- });
274
-
275
- describe('when called with a query', () => {
276
- beforeEach(() => {
277
- scope.post('/jobs/foo-bar/_recover')
278
- .query({ cleanup: 'errors' })
279
- .reply(200, { job_id: 'foo-bar' });
280
- });
281
-
282
- it('should resolve json results from Teraslice', async () => {
283
- const job = new Job({ baseUrl }, 'foo-bar');
284
- const results = await job.recover({
285
- cleanup: Teraslice.RecoveryCleanupType.errors
286
- });
287
- expect(results).toEqual({ job_id: 'foo-bar' });
288
- });
289
- });
290
-
291
- describe('when called with a query and options', () => {
292
- beforeEach(() => {
293
- scope.post('/jobs/some-job-id/_recover')
294
- .matchHeader('Some-Header', 'yes')
295
- .query({ cleanup: 'errors' })
296
- .reply(200, {
297
- key: 'some-other-key'
298
- });
299
- });
300
-
301
- it('should resolve json results from Teraslice', async () => {
302
- const job = new Job({ baseUrl }, 'some-job-id');
303
- const results = await job.recover({
304
- cleanup: Teraslice.RecoveryCleanupType.errors
305
- }, requestOptions);
306
- expect(results).toEqual({
307
- key: 'some-other-key'
308
- });
309
- });
310
- });
311
- });
312
-
313
- describe('->recover with warnings', () => {
314
- describe('when the server returns deprecation warnings', () => {
315
- const deprecationWarning: Teraslice.JobWarning = {
316
- type: 'JobValidation',
317
- reason: {
318
- type: 'assetAPIProperty',
319
- kind: 'deprecation',
320
- reason: {
321
- api_name: 'some-api',
322
- field: 'old_api_field',
323
- description: 'old_api_field is deprecated, use new_api_field instead',
324
- },
325
- },
326
- };
327
-
328
- const response: Teraslice.ApiJobCreateResponse = {
329
- job_id: 'some-other-job-id',
330
- warnings: [deprecationWarning],
331
- };
332
-
333
- beforeEach(() => {
334
- scope.post('/jobs/some-other-job-id/_recover')
335
- .reply(200, response);
336
- });
337
-
338
- it('should return the response with warnings', async () => {
339
- const job = new Job({ baseUrl }, 'some-other-job-id');
340
- const result = await job.recover();
341
- expect(result.job_id).toEqual('some-other-job-id');
342
- expect(result.warnings).toBeArrayOfSize(1);
343
- expect(result.warnings![0]).toMatchObject(deprecationWarning);
344
- });
345
- });
346
- });
347
-
348
- describe('->execution', () => {
349
- const exJobId = executionResults[0].job_id;
350
- describe('when called with nothing', () => {
351
- beforeEach(() => {
352
- scope.get(`/jobs/${exJobId}/ex`)
353
- .reply(200, executionResults);
354
- });
355
-
356
- it('should resolve json results from Teraslice', async () => {
357
- const job = new Job({ baseUrl }, exJobId);
358
- const results = await job.execution();
359
- expect(results).toEqual(executionResults);
360
- });
361
- });
362
-
363
- describe('when called with options', () => {
364
- beforeEach(() => {
365
- scope.get(`/jobs/${exJobId}/ex`)
366
- .matchHeader('Some-Header', 'yes')
367
- .reply(200, executionResults);
368
- });
369
-
370
- it('should resolve json results from Teraslice', async () => {
371
- const job = new Job({ baseUrl }, exJobId);
372
- const results = await job.execution(requestOptions);
373
- expect(results).toEqual(executionResults);
374
- });
375
- });
376
- });
377
-
378
- describe('->update', () => {
379
- describe('when updating the whole config', () => {
380
- const body: Teraslice.JobConfig = {
381
- name: 'hello',
382
- apis: [],
383
- operations: [],
384
- active: true,
385
- analytics: false,
386
- autorecover: false,
387
- assets: [],
388
- lifecycle: 'once',
389
- max_retries: 0,
390
- probation_window: 30000,
391
- slicers: 1,
392
- workers: 1,
393
- env_vars: {},
394
- _context: 'job',
395
- job_id: 'some-job-id',
396
- _created: 'hello',
397
- _updated: 'hello'
398
- };
399
-
400
- beforeEach(() => {
401
- scope.put('/jobs/some-job-id', body as any)
402
- .reply(200, body);
403
- });
404
-
405
- it('should resolve the update job config', async () => {
406
- const job = new Job({ baseUrl }, 'some-job-id');
407
- const result = await job.update(body);
408
- expect(result).toEqual(body);
409
- });
410
- });
411
- });
412
-
413
- describe('->updatePartial', () => {
414
- describe('when updating a partial config', () => {
415
- const body: Teraslice.JobConfig = {
416
- name: 'hello',
417
- apis: [],
418
- operations: [],
419
- active: true,
420
- analytics: false,
421
- autorecover: false,
422
- assets: [],
423
- lifecycle: 'once',
424
- max_retries: 0,
425
- probation_window: 30000,
426
- slicers: 1,
427
- workers: 1,
428
- env_vars: {},
429
- _context: 'job',
430
- job_id: 'some-job-id',
431
- _created: 'hello',
432
- _updated: 'hello'
433
- };
434
-
435
- const expected = {
436
- ...body,
437
- name: 'howdy'
438
- };
439
-
440
- beforeEach(() => {
441
- scope.get('/jobs/some-job-id')
442
- .reply(200, body);
443
- scope.put('/jobs/some-job-id', expected as any)
444
- .reply(200, expected);
445
- });
446
-
447
- it('should resolve the update job config', async () => {
448
- const job = new Job({ baseUrl }, 'some-job-id');
449
- const result = await job.updatePartial({ name: 'howdy' });
450
- expect(result).toEqual(expected);
451
- });
452
- });
453
- });
454
-
455
- describe('->deleteJob', () => {
456
- describe('when called', () => {
457
- beforeEach(() => {
458
- scope.delete('/jobs/some-other-job-id')
459
- .reply(200, { job_id: 'some-other-job-id', _deleted: true });
460
- });
461
-
462
- it('should resolve json results from Teraslice', async () => {
463
- const job = new Job({ baseUrl }, 'some-other-job-id');
464
- const results = await job.deleteJob();
465
- expect(results).toEqual({ job_id: 'some-other-job-id', _deleted: true });
466
- });
467
- });
468
- });
469
-
470
- describe('->exId', () => {
471
- describe('when called with nothing', () => {
472
- beforeEach(() => {
473
- scope.get('/jobs/some-job-id/ex')
474
- .reply(200, { ex_id: 'example-ex-id' });
475
- });
476
-
477
- it('should resolve json results from Teraslice', async () => {
478
- const job = new Job({ baseUrl }, 'some-job-id');
479
- const results = await job.exId();
480
- expect(results).toEqual('example-ex-id');
481
- });
482
- });
483
-
484
- describe('when called with options', () => {
485
- beforeEach(() => {
486
- scope.get('/jobs/some-job-id/ex')
487
- .matchHeader('Some-Header', 'yes')
488
- .reply(200, { ex_id: 'other-ex-id' });
489
- });
490
-
491
- it('should resolve json results from Teraslice', async () => {
492
- const job = new Job({ baseUrl }, 'some-job-id');
493
- const results = await job.exId(requestOptions);
494
- expect(results).toEqual('other-ex-id');
495
- });
496
- });
497
- });
498
-
499
- describe('->status', () => {
500
- describe('when called with nothing', () => {
501
- beforeEach(() => {
502
- scope.get('/jobs/some-job-id/ex')
503
- .reply(200, {
504
- ex_id: 'example-ex-id',
505
- _status: 'example'
506
- });
507
- });
508
-
509
- it('should resolve json results from Teraslice', async () => {
510
- const job = new Job({ baseUrl }, 'some-job-id');
511
- const results = await job.status();
512
- expect(results).toEqual('example');
513
- });
514
- });
515
-
516
- describe('when called with options', () => {
517
- beforeEach(() => {
518
- scope.get('/jobs/some-job-id/ex')
519
- .matchHeader('Some-Header', 'yes')
520
- .reply(200, {
521
- ex_id: 'example-ex-id',
522
- _status: 'other-status'
523
- });
524
- });
525
-
526
- it('should resolve json results from Teraslice', async () => {
527
- const job = new Job({ baseUrl }, 'some-job-id');
528
- const results = await job.status(requestOptions);
529
- expect(results).toEqual('other-status');
530
- });
531
- });
532
- });
533
-
534
- describe('->config', () => {
535
- describe('when called with nothing', () => {
536
- const data = {
537
- job_id: 'example-job-id',
538
- ex_id: 'example-ex-id',
539
- example: 'job-spec'
540
- };
541
-
542
- beforeEach(() => {
543
- scope.get('/jobs/example-job-id')
544
- .reply(200, data);
545
- });
546
-
547
- it('should resolve json results from Teraslice', async () => {
548
- const job = new Job({ baseUrl }, 'example-job-id');
549
- const results = await job.config();
550
- expect(results).toEqual(data);
551
- });
552
- });
553
-
554
- describe('when called with with options', () => {
555
- beforeEach(() => {
556
- scope.get('/jobs/some-job-id')
557
- .matchHeader('Some-Header', 'yes')
558
- .reply(200, {
559
- job_id: 'example-job-id',
560
- ex_id: 'example-ex-id',
561
- example: 'job-spec'
562
- });
563
- });
564
-
565
- it('should resolve json results from Teraslice', async () => {
566
- const job = new Job({ baseUrl }, 'some-job-id');
567
- const results = await job.config(requestOptions);
568
- expect(results).toEqual({
569
- job_id: 'example-job-id',
570
- ex_id: 'example-ex-id',
571
- example: 'job-spec'
572
- });
573
- });
574
- });
575
- });
576
-
577
- describe('->errors', () => {
578
- describe('when called with nothing', () => {
579
- beforeEach(() => {
580
- scope.get('/jobs/some-job-id/errors')
581
- .reply(200, [
582
- { error: 'example' },
583
- { error: 'example-2' }
584
- ]);
585
- });
586
-
587
- it('should resolve json results from Teraslice', async () => {
588
- const job = new Job({ baseUrl }, 'some-job-id');
589
- const results = await job.errors();
590
- expect(results).toEqual([
591
- { error: 'example' },
592
- { error: 'example-2' }
593
- ]);
594
- });
595
- });
596
- });
597
-
598
- describe('->workers', () => {
599
- const workerData: Teraslice.WorkerNode[] = [];
600
-
601
- const jobId = 'some-job-id';
602
- for (const [nodeName, node] of Object.entries(clusterState)) {
603
- // @ts-expect-error TODO: fixme
604
- node.active.forEach((child) => {
605
- if (child.assignment === 'worker' && child.job_id === jobId) {
606
- child.node_id = nodeName;
607
- workerData.push(child);
608
- }
609
- });
610
- }
611
-
612
- describe('when called and the state has workers', () => {
613
- beforeEach(() => {
614
- scope.get('/cluster/state')
615
- .reply(200, clusterState);
616
- });
617
-
618
- it('should resolve json results from Teraslice', async () => {
619
- const job = new Job({ baseUrl }, jobId);
620
- const results = await job.workers();
621
- expect(results).toEqual(workerData);
622
- });
623
- });
624
-
625
- describe('when called and the state has workers (with headers)', () => {
626
- beforeEach(() => {
627
- scope.get('/cluster/state')
628
- .matchHeader('Some-Header', 'yes')
629
- .reply(200, clusterState);
630
- });
631
-
632
- it('should resolve json results from Teraslice', async () => {
633
- const job = new Job({ baseUrl }, 'some-job-id');
634
- const results = await job.workers(requestOptions);
635
-
636
- expect(results).toEqual(workerData);
637
- });
638
- });
639
- });
640
-
641
- describe('->changeWorkers', () => {
642
- const response = { message: 'Changed workers!' };
643
-
644
- describe('when response returns a string', () => {
645
- const oldStrResponse = 'hello';
646
-
647
- beforeEach(() => {
648
- scope.post('/jobs/some-job-id/_workers')
649
- .query({ add: 2 })
650
- .reply(200, oldStrResponse);
651
- });
652
-
653
- it('should resolve json results from Teraslice', async () => {
654
- const job = new Job({ baseUrl }, 'some-job-id');
655
- const results = await job.changeWorkers('add', 2);
656
- expect(results).toEqual(oldStrResponse);
657
- });
658
- });
659
-
660
- describe('when called with add and num', () => {
661
- beforeEach(() => {
662
- scope.post('/jobs/some-job-id/_workers')
663
- .query({ add: 2 })
664
- .reply(200, response);
665
- });
666
-
667
- it('should resolve json results from Teraslice', async () => {
668
- const job = new Job({ baseUrl }, 'some-job-id');
669
- const results = await job.changeWorkers('add', 2);
670
- expect(results).toEqual(response);
671
- });
672
- });
673
-
674
- describe('when called with remove and num', () => {
675
- beforeEach(() => {
676
- scope.post('/jobs/some-job-id/_workers')
677
- .query({ remove: 2 })
678
- .reply(200, response);
679
- });
680
-
681
- it('should resolve json results from Teraslice', async () => {
682
- const job = new Job({ baseUrl }, 'some-job-id');
683
- const results = await job.changeWorkers('remove', 2);
684
- expect(results).toEqual(response);
685
- });
686
- });
687
-
688
- describe('when called with total and num', () => {
689
- beforeEach(() => {
690
- scope.post('/jobs/some-job-id/_workers')
691
- .query({ total: 2 })
692
- .reply(200, response);
693
- });
694
-
695
- it('should resolve json results from Teraslice', async () => {
696
- const job = new Job({ baseUrl }, 'some-job-id');
697
- const results = await job.changeWorkers('total', 2);
698
- expect(results).toEqual(response);
699
- });
700
- });
701
-
702
- describe('when called with nothing', () => {
703
- it('should reject with an error', async () => {
704
- expect.hasAssertions();
705
- const job = new Job({ baseUrl }, 'some-job-id');
706
- try {
707
- // @ts-expect-error
708
- await job.changeWorkers();
709
- } catch (err) {
710
- expect(err.message).toEqual('Change workers requires action and count');
711
- }
712
- });
713
- });
714
-
715
- describe('when called with an invalid action', () => {
716
- it('should reject with an error', async () => {
717
- expect.hasAssertions();
718
- const job = new Job({ baseUrl }, 'some-job-id');
719
- try {
720
- // @ts-expect-error
721
- await job.changeWorkers('invalid', 2);
722
- } catch (err) {
723
- expect(err.message).toEqual('Change workers requires action to be one of add, remove, or total');
724
- }
725
- });
726
- });
727
- });
728
-
729
- describe('->waitForStatus', () => {
730
- describe('when called and it matches on the first try', () => {
731
- beforeEach(() => {
732
- scope.get('/jobs/some-job-id/ex')
733
- .reply(200, {
734
- ex_id: 'example-ex-id',
735
- _status: Teraslice.ExecutionStatusEnum.running
736
- });
737
- });
738
-
739
- it('should resolve json results from Teraslice', async () => {
740
- const job = new Job({ baseUrl }, 'some-job-id');
741
- const results = await job.waitForStatus(Teraslice.ExecutionStatusEnum.running);
742
- expect(results).toEqual(Teraslice.ExecutionStatusEnum.running);
743
- });
744
- });
745
-
746
- describe('when called with status array and matches on the first try', () => {
747
- beforeEach(() => {
748
- scope.get('/jobs/some-job-id/ex')
749
- .reply(200, {
750
- ex_id: 'example-ex-id',
751
- _status: Teraslice.ExecutionStatusEnum.running
752
- });
753
- });
754
-
755
- it('should resolve json results from Teraslice', async () => {
756
- const job = new Job({ baseUrl }, 'some-job-id');
757
- const results = await job.waitForStatus([
758
- Teraslice.ExecutionStatusEnum.failing,
759
- Teraslice.ExecutionStatusEnum.running
760
- ]);
761
-
762
- expect(results).toEqual(Teraslice.ExecutionStatusEnum.running);
763
- });
764
- });
765
-
766
- describe('when called and it matches on the first try (with headers)', () => {
767
- const searchOptions = { headers: { 'Some-Header': 'yes' } };
768
-
769
- beforeEach(() => {
770
- scope.get('/jobs/some-job-id/ex')
771
- .matchHeader('Some-Header', 'yes')
772
- .reply(200, {
773
- ex_id: 'example-ex-id',
774
- _status: Teraslice.ExecutionStatusEnum.running
775
- });
776
- });
777
-
778
- it('should resolve json results from Teraslice', async () => {
779
- const job = new Job({ baseUrl }, 'some-job-id');
780
- const results = await job.waitForStatus(
781
- Teraslice.ExecutionStatusEnum.running,
782
- 1000,
783
- 0,
784
- searchOptions
785
- );
786
- expect(results).toEqual(Teraslice.ExecutionStatusEnum.running);
787
- });
788
- });
789
-
790
- describe('when called and it matches on the second try', () => {
791
- beforeEach(() => {
792
- scope.get('/jobs/some-job-id/ex')
793
- .reply(200, {
794
- ex_id: 'example-ex-id',
795
- _status: Teraslice.ExecutionStatusEnum.running
796
- });
797
-
798
- scope.get('/jobs/some-job-id/ex')
799
- .reply(200, {
800
- ex_id: 'example-ex-id',
801
- _status: Teraslice.ExecutionStatusEnum.completed
802
- });
803
- });
804
-
805
- it('should resolve json results from Teraslice', async () => {
806
- const job = new Job({ baseUrl }, 'some-job-id');
807
- const results = await job.waitForStatus(Teraslice.ExecutionStatusEnum.completed);
808
- expect(results).toEqual(Teraslice.ExecutionStatusEnum.completed);
809
- });
810
- });
811
-
812
- describe('when called with array of statuses and matches on the second try', () => {
813
- beforeEach(() => {
814
- scope.get('/jobs/some-job-id/ex')
815
- .reply(200, {
816
- ex_id: 'example-ex-id',
817
- _status: Teraslice.ExecutionStatusEnum.running
818
- });
819
-
820
- scope.get('/jobs/some-job-id/ex')
821
- .reply(200, {
822
- ex_id: 'example-ex-id',
823
- _status: Teraslice.ExecutionStatusEnum.terminated
824
- });
825
- });
826
-
827
- it('should resolve json results from Teraslice', async () => {
828
- const job = new Job({ baseUrl }, 'some-job-id');
829
- const results = await job.waitForStatus([
830
- Teraslice.ExecutionStatusEnum.completed,
831
- Teraslice.ExecutionStatusEnum.failed,
832
- Teraslice.ExecutionStatusEnum.terminated
833
- ]);
834
-
835
- expect(results).toEqual(Teraslice.ExecutionStatusEnum.terminated);
836
- });
837
- });
838
-
839
- describe('when called and it never matches', () => {
840
- beforeEach(() => {
841
- scope.get('/jobs/some-job-id/ex')
842
- .times(1)
843
- .reply(200, {
844
- ex_id: 'example-ex-id',
845
- _status: Teraslice.ExecutionStatusEnum.initializing
846
- });
847
-
848
- scope.get('/jobs/some-job-id/ex')
849
- .times(11)
850
- .reply(200, {
851
- ex_id: 'example-ex-id',
852
- _status: Teraslice.ExecutionStatusEnum.running
853
- });
854
- });
855
-
856
- it('should reject with a timeout error', async () => {
857
- expect.hasAssertions();
858
- const job = new Job({ baseUrl }, 'some-job-id');
859
- try {
860
- await job.waitForStatus(Teraslice.ExecutionStatusEnum.completed, 100, 1000);
861
- } catch (err) {
862
- expect(err.message).toEqual('Job status failed to change from status "running" to "completed" within 1000ms');
863
- }
864
- });
865
- });
866
-
867
- describe('when called with array of statuses and it never matches', () => {
868
- beforeEach(() => {
869
- scope.get('/jobs/some-job-id/ex')
870
- .times(1)
871
- .reply(200, {
872
- ex_id: 'example-ex-id',
873
- _status: Teraslice.ExecutionStatusEnum.initializing
874
- });
875
-
876
- scope.get('/jobs/some-job-id/ex')
877
- .times(11)
878
- .reply(200, {
879
- ex_id: 'example-ex-id',
880
- _status: Teraslice.ExecutionStatusEnum.running
881
- });
882
- });
883
-
884
- it('should reject with a timeout error', async () => {
885
- expect.hasAssertions();
886
- const job = new Job({ baseUrl }, 'some-job-id');
887
- try {
888
- await job.waitForStatus([
889
- Teraslice.ExecutionStatusEnum.completed,
890
- Teraslice.ExecutionStatusEnum.failed,
891
- Teraslice.ExecutionStatusEnum.stopped
892
- ], 100, 1000);
893
- } catch (err) {
894
- expect(err.message).toEqual('Job status failed to change from status "running" to "completed,failed,stopped" within 1000ms');
895
- }
896
- });
897
- });
898
-
899
- describe('when called and one request times out', () => {
900
- beforeEach(() => {
901
- scope.get('/jobs/some-job-id/ex')
902
- .delay(1100)
903
- .reply(200, {
904
- ex_id: 'example-ex-id',
905
- _status: Teraslice.ExecutionStatusEnum.initializing
906
- });
907
-
908
- scope.get('/jobs/some-job-id/ex')
909
- .reply(200, {
910
- ex_id: 'example-ex-id',
911
- _status: Teraslice.ExecutionStatusEnum.running
912
- });
913
- });
914
-
915
- it('should resolve with the correct status', async () => {
916
- const job = new Job({ baseUrl }, 'some-job-id');
917
- const status = await job.waitForStatus(
918
- Teraslice.ExecutionStatusEnum.running,
919
- 100,
920
- 1500
921
- );
922
- expect(status).toEqual(Teraslice.ExecutionStatusEnum.running);
923
- });
924
- });
925
-
926
- describe('when called and returns a terminal status', () => {
927
- beforeEach(() => {
928
- scope.get('/jobs/other-job-id/ex')
929
- .reply(200, {
930
- ex_id: 'example-ex-id',
931
- _status: Teraslice.ExecutionStatusEnum.failed
932
- });
933
- });
934
-
935
- it('should reject with a terminal status error', async () => {
936
- expect.hasAssertions();
937
- const job = new Job({ baseUrl }, 'other-job-id');
938
- try {
939
- await job.waitForStatus(Teraslice.ExecutionStatusEnum.completed, 100, 1000);
940
- } catch (err) {
941
- const errMsg = 'Job cannot reach the target status, "completed", because it is in the terminal state, "failed"';
942
- expect(err.message).toEqual(errMsg);
943
- }
944
- });
945
- });
946
- });
947
- });