Skip to content

Commit

Permalink
more e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
busma13 committed Sep 6, 2024
1 parent 26b2349 commit dab1481
Showing 1 changed file with 68 additions and 27 deletions.
95 changes: 68 additions & 27 deletions e2e/test/cases/cluster/api-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { cloneDeep, pDelay } from '@terascope/utils';
import { JobConfig } from '@terascope/types';
import { TerasliceHarness } from '../../teraslice-harness.js';
import { TEST_PLATFORM } from '../../config.js';
import { Ex, Job } from 'teraslice-client-js';

describe('cluster api', () => {
let terasliceHarness: TerasliceHarness;
Expand Down Expand Up @@ -104,33 +105,6 @@ describe('cluster api', () => {
expect(result).toEqual([true, true, true, true]);
});

it('will not delete a job until stopped', async () => {
const jobSpec = terasliceHarness.newJob('generator');
const deletedJobProperties = {
_deleted: true,
_deleted_on: expect.anything(),
active: false
};

// Set resource constraints on workers within CI
if (TEST_PLATFORM === 'kubernetes' || TEST_PLATFORM === 'kubernetesV2') {
jobSpec.resources_requests_cpu = 0.05;
}

const job = await terasliceHarness.teraslice.jobs.submit(jobSpec, false);
const jobId = job.id();
const { ex_id: exId } = await job.execution();
const ex = terasliceHarness.teraslice.executions.wrap(exId);
await terasliceHarness.waitForExStatus(ex, 'running', 100, 1000);

await expect(terasliceHarness.teraslice.jobs.delete(`/jobs/${jobId}`)).rejects.toThrow();

await terasliceHarness.teraslice.jobs.post(`/jobs/${jobId}/_stop`);
await terasliceHarness.waitForExStatus(ex, 'stopped', 100, 1000);

await expect(terasliceHarness.teraslice.jobs.delete(`/jobs/${jobId}`)).resolves.toMatchObject(deletedJobProperties);
});

it('api end point /assets should return an array of json objects of asset metadata', async () => {
const response = await terasliceHarness.teraslice.cluster.get('/assets');

Expand Down Expand Up @@ -175,4 +149,71 @@ describe('cluster api', () => {
const response = await terasliceHarness.teraslice.cluster.txt('assets/ex1/0.0.1');
expect(response).toBeString();
});

describe('DELETE /jobs/<jobId>', () => {
// NOTE: every test in this section will use a single job

const deletedJobProperties = {
_deleted: true,
_deleted_on: expect.anything(),
active: false
};

let job: Job;
let jobId: string;
let ex: Ex;
let jobSpec: JobConfig;

beforeAll(async () => {
jobSpec = terasliceHarness.newJob('generator');
// Set resource constraints on workers within CI
if (TEST_PLATFORM === 'kubernetes' || TEST_PLATFORM === 'kubernetesV2') {
jobSpec.resources_requests_cpu = 0.05;
}

job = await terasliceHarness.teraslice.jobs.submit(jobSpec, false);
jobId = job.id();
const { ex_id: exId } = await job.execution();
ex = terasliceHarness.teraslice.executions.wrap(exId);
})

it('will not delete a running job', async () => {
await terasliceHarness.waitForExStatus(ex, 'running', 100, 1000);

await expect(terasliceHarness.teraslice.jobs.delete(`/jobs/${jobId}`)).rejects.toThrow();
});

it('will delete a stopped job', async () => {
await terasliceHarness.teraslice.jobs.post(`/jobs/${jobId}/_stop`);
await terasliceHarness.waitForExStatus(ex, 'stopped', 100, 1000);

await expect(terasliceHarness.teraslice.jobs.delete(`/jobs/${jobId}`)).resolves.toMatchObject(deletedJobProperties);
});

it('will not list a deleted job by default', async () => {
const list = await terasliceHarness.teraslice.jobs.list();
const jobIds = list.map((job) => job.job_id);
expect(jobIds).toEqual(expect.arrayContaining([expect.not.stringMatching(jobId)]));
});

it('will list a deleted job when passed "{ deleted: true }"', async () => {
const list = await terasliceHarness.teraslice.jobs.list({ deleted: true });
expect(list).toEqual(expect.arrayContaining([expect.objectContaining({ ...jobSpec, job_id: jobId })]));
});

it('will not start a deleted job', async () => {
await expect(terasliceHarness.teraslice.jobs.post(`/jobs/${jobId}/_start`)).rejects.toThrow(`Job ${jobId} has been deleted and cannot be started.`);

});

it('will not update a deleted job', async () => {
await expect(terasliceHarness.teraslice.jobs.put(`/jobs/${jobId}`, { workers: 1 })).rejects.toThrow(`Job ${jobId} has been deleted and cannot be updated.`);

});

it('will not recover a deleted job', async () => {
await expect(terasliceHarness.teraslice.jobs.post(`/jobs/${jobId}/_recover`)).rejects.toThrow(`Job ${jobId} has been deleted and cannot be recovered.`);

});
});
});

0 comments on commit dab1481

Please sign in to comment.