Skip to content

Commit a77bf2a

Browse files
author
Joanna Grycz
committed
Reorder imports and throw job deleting error
1 parent ab105d9 commit a77bf2a

15 files changed

+49
-79
lines changed

batch/test/advanced_creation.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@ const path = require('path');
1818
const cp = require('child_process');
1919
const {describe, it, before} = require('mocha');
2020
const {BatchServiceClient} = require('@google-cloud/batch').v1;
21-
const batchClient = new BatchServiceClient();
2221
const {Storage} = require('@google-cloud/storage');
23-
const storage = new Storage();
2422
const {ProjectsClient} = require('@google-cloud/resource-manager').v3;
25-
const resourcemanagerClient = new ProjectsClient();
2623
const compute = require('@google-cloud/compute');
27-
const instanceTemplatesClient = new compute.InstanceTemplatesClient();
28-
2924
// get a short ID for this test run that only contains characters that are valid in UUID
3025
// (a plain UUID won't do because we want the "test-job-js" prefix and that would exceed the length limit)
3126
const {customAlphabet} = require('nanoid');
@@ -36,6 +31,11 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
3631

3732
const cwd = path.join(__dirname, '..');
3833

34+
const batchClient = new BatchServiceClient();
35+
const storage = new Storage();
36+
const resourcemanagerClient = new ProjectsClient();
37+
const instanceTemplatesClient = new compute.InstanceTemplatesClient();
38+
3939
describe('Create jobs with container, template and bucket', () => {
4040
let projectId;
4141
let bucketName;

batch/test/batchClient_operations.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616

1717
async function deleteJob(batchClient, projectId, region, jobId) {
1818
const request = {
19-
name: `projects/${projectId}/locations/${region}/jobs/${jobId}`,
19+
name: `projects/${projectId}/locations/${region}/jobs/${jobId}666`,
2020
};
2121
try {
2222
await batchClient.deleteJob(request);
2323
} catch (err) {
2424
console.error('Deleting job failed: ', err);
25+
throw new Error(err);
2526
}
2627
}
2728

batch/test/create_batch_custom_events.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
const path = require('path');
2020
const assert = require('node:assert/strict');
2121
const {describe, it} = require('mocha');
22-
const cp = require('child_process');
23-
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2422
const cwd = path.join(__dirname, '..');
2523
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2624
const {deleteJob} = require('./batchClient_operations');
25+
26+
const cp = require('child_process');
27+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2728
const batchClient = new BatchServiceClient();
2829

2930
describe('Create batch custom events job', async () => {

batch/test/create_batch_custom_network.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ const path = require('path');
2020
const assert = require('node:assert/strict');
2121
const {describe, it} = require('mocha');
2222
const cp = require('child_process');
23-
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24-
const cwd = path.join(__dirname, '..');
2523
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2624
const {deleteJob} = require('./batchClient_operations');
25+
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
2728
const batchClient = new BatchServiceClient();
2829

2930
describe('Create batch custom network', async () => {

batch/test/create_batch_labels_allocation.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ const path = require('path');
2020
const assert = require('node:assert/strict');
2121
const {describe, it} = require('mocha');
2222
const cp = require('child_process');
23-
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24-
const cwd = path.join(__dirname, '..');
2523
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2624
const {deleteJob} = require('./batchClient_operations');
25+
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
2728
const batchClient = new BatchServiceClient();
2829

2930
describe('Create batch labels allocation', async () => {

batch/test/create_batch_labels_job.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ const path = require('path');
2020
const assert = require('node:assert/strict');
2121
const {describe, it} = require('mocha');
2222
const cp = require('child_process');
23-
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24-
const cwd = path.join(__dirname, '..');
2523
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2624
const {deleteJob} = require('./batchClient_operations');
25+
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
2728
const batchClient = new BatchServiceClient();
2829

2930
describe('Create batch labels for job', async () => {

batch/test/create_batch_labels_runnable.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ const path = require('path');
2020
const assert = require('assert');
2121
const {describe, it} = require('mocha');
2222
const cp = require('child_process');
23-
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24-
const cwd = path.join(__dirname, '..');
2523
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2624
const {deleteJob} = require('./batchClient_operations');
25+
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
2728
const batchClient = new BatchServiceClient();
2829

2930
describe('Create batch labels runnable', async () => {

batch/test/create_batch_notifications.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ const path = require('path');
2020
const assert = require('node:assert/strict');
2121
const {describe, it} = require('mocha');
2222
const cp = require('child_process');
23+
const {BatchServiceClient} = require('@google-cloud/batch').v1;
24+
2325
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2426
const cwd = path.join(__dirname, '..');
25-
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2627
const batchClient = new BatchServiceClient();
2728

2829
async function deleteJob(projectId, region, jobId) {

batch/test/create_batch_using_service_account.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ const path = require('path');
2020
const assert = require('node:assert/strict');
2121
const {describe, it} = require('mocha');
2222
const cp = require('child_process');
23-
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24-
const cwd = path.join(__dirname, '..');
2523
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2624
const {ProjectsClient} = require('@google-cloud/resource-manager').v3;
2725
const {deleteJob} = require('./batchClient_operations');
26+
27+
const cwd = path.join(__dirname, '..');
28+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2829
const batchClient = new BatchServiceClient();
2930
const resourceManagerClient = new ProjectsClient();
3031

batch/test/create_gpu_job.test.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,13 @@ const path = require('path');
2020
const assert = require('node:assert/strict');
2121
const {describe, it} = require('mocha');
2222
const cp = require('child_process');
23+
const {BatchServiceClient} = require('@google-cloud/batch').v1;
24+
const {deleteJob} = require('./batchClient_operations');
25+
2326
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2427
const cwd = path.join(__dirname, '..');
25-
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2628
const batchClient = new BatchServiceClient();
2729

28-
async function deleteJob(projectId, region, jobId) {
29-
const request = {
30-
name: `projects/${projectId}/locations/${region}/jobs/${jobId}`,
31-
};
32-
try {
33-
await batchClient.deleteJob(request);
34-
} catch (err) {
35-
console.error('Error deleting job:', err);
36-
}
37-
}
38-
3930
describe('Create batch GPU job', async () => {
4031
const jobName = 'batch-gpu-job';
4132
const region = 'europe-central2';
@@ -46,7 +37,7 @@ describe('Create batch GPU job', async () => {
4637
});
4738

4839
after(async () => {
49-
await deleteJob(projectId, region, jobName);
40+
await deleteJob(batchClient, projectId, region, jobName);
5041
});
5142

5243
it('should create a new job with GPU', async () => {

batch/test/create_gpu_job_n1.test.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,13 @@ const path = require('path');
2020
const assert = require('node:assert/strict');
2121
const {describe, it} = require('mocha');
2222
const cp = require('child_process');
23+
const {BatchServiceClient} = require('@google-cloud/batch').v1;
24+
const {deleteJob} = require('./batchClient_operations');
25+
2326
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2427
const cwd = path.join(__dirname, '..');
25-
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2628
const batchClient = new BatchServiceClient();
2729

28-
async function deleteJob(projectId, region, jobId) {
29-
const request = {
30-
name: `projects/${projectId}/locations/${region}/jobs/${jobId}`,
31-
};
32-
try {
33-
await batchClient.deleteJob(request);
34-
} catch (err) {
35-
console.error('Error deleting job:', err);
36-
}
37-
}
38-
3930
describe('Create batch GPU job on N1', async () => {
4031
const jobName = 'batch-gpu-job-n1';
4132
const region = 'europe-central2';
@@ -46,7 +37,7 @@ describe('Create batch GPU job on N1', async () => {
4637
});
4738

4839
after(async () => {
49-
await deleteJob(projectId, region, jobName);
40+
await deleteJob(batchClient, projectId, region, jobName);
5041
});
5142

5243
it('should create a new job with GPU on N1', async () => {

batch/test/create_local_ssd_job.test.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,24 @@ const path = require('path');
2020
const assert = require('node:assert/strict');
2121
const {describe, it} = require('mocha');
2222
const cp = require('child_process');
23+
const {BatchServiceClient} = require('@google-cloud/batch').v1;
24+
const {deleteJob} = require('./batchClient_operations');
25+
2326
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2427
const cwd = path.join(__dirname, '..');
25-
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2628
const batchClient = new BatchServiceClient();
2729

28-
async function deleteJob(projectId, region, jobId) {
29-
const request = {
30-
name: `projects/${projectId}/locations/${region}/jobs/${jobId}`,
31-
};
32-
try {
33-
await batchClient.deleteJob(request);
34-
} catch (err) {
35-
console.error('Error deleting job:', err);
36-
}
37-
}
38-
3930
describe('Create batch local ssd job', async () => {
4031
const jobName = 'batch-local-ssd-job';
4132
const region = 'europe-central2';
42-
4333
let projectId;
4434

4535
before(async () => {
4636
projectId = await batchClient.getProjectId();
4737
});
4838

4939
after(async () => {
50-
await deleteJob(projectId, region, jobName);
40+
await deleteJob(batchClient, projectId, region, jobName);
5141
});
5242

5343
it('should create a new job with local ssd', async () => {

batch/test/create_nfs_job.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ const path = require('path');
2020
const assert = require('node:assert/strict');
2121
const {describe, it} = require('mocha');
2222
const cp = require('child_process');
23-
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24-
const cwd = path.join(__dirname, '..');
2523
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2624
const {deleteJob} = require('./batchClient_operations');
25+
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
2728
const batchClient = new BatchServiceClient();
2829

2930
describe('Create batch NFS job', async () => {
3031
const jobName = 'batch-nfs-job';
3132
const region = 'europe-central2';
32-
3333
let projectId;
3434

3535
before(async () => {

batch/test/create_persistent_disk_job.test.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,24 @@ const path = require('path');
2020
const assert = require('node:assert/strict');
2121
const {describe, it} = require('mocha');
2222
const cp = require('child_process');
23+
const {BatchServiceClient} = require('@google-cloud/batch').v1;
24+
const {deleteJob} = require('./batchClient_operations');
25+
2326
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2427
const cwd = path.join(__dirname, '..');
25-
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2628
const batchClient = new BatchServiceClient();
2729

28-
async function deleteJob(projectId, region, jobId) {
29-
const request = {
30-
name: `projects/${projectId}/locations/${region}/jobs/${jobId}`,
31-
};
32-
try {
33-
await batchClient.deleteJob(request);
34-
} catch (err) {
35-
console.error('Error deleting job:', err);
36-
}
37-
}
38-
3930
describe('Create batch job with persistent disk', async () => {
4031
const jobName = 'batch-create-persistent-disk-job';
4132
const region = 'europe-central2';
42-
4333
let projectId;
4434

4535
before(async () => {
4636
projectId = await batchClient.getProjectId();
4737
});
4838

4939
after(async () => {
50-
await deleteJob(projectId, region, jobName);
40+
await deleteJob(batchClient, projectId, region, jobName);
5141
});
5242

5343
it('should create a new job with persistent disk', async () => {

batch/test/create_using_secret_manager.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ const path = require('path');
2020
const assert = require('node:assert/strict');
2121
const {describe, it} = require('mocha');
2222
const cp = require('child_process');
23-
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24-
const cwd = path.join(__dirname, '..');
2523
const {BatchServiceClient} = require('@google-cloud/batch').v1;
2624
const {deleteJob} = require('./batchClient_operations');
25+
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
2728
const batchClient = new BatchServiceClient();
2829

2930
describe('Create batch using secret manager', async () => {
3031
const jobName = 'batch-job-secret-manager';
3132
const region = 'europe-central2';
32-
3333
let projectId;
3434

3535
before(async () => {

0 commit comments

Comments
 (0)