Skip to content

Commit 8f0ea59

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

15 files changed

+65
-106
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
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');
27-
const batchClient = new BatchServiceClient();
25+
26+
const cp = require('child_process');
27+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2828

2929
describe('Create batch custom events job', async () => {
3030
const jobName = 'batch-custom-events-job';
3131
const region = 'europe-central2';
32+
const batchClient = new BatchServiceClient();
3233
let projectId;
3334

3435
before(async () => {

batch/test/create_batch_custom_network.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +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');
27-
const batchClient = new BatchServiceClient();
25+
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
2828

2929
describe('Create batch custom network', async () => {
3030
const jobName = 'example-job';
3131
const region = 'europe-central2';
32+
const batchClient = new BatchServiceClient();
3233
let projectId;
3334

3435
before(async () => {

batch/test/create_batch_labels_allocation.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +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');
27-
const batchClient = new BatchServiceClient();
25+
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
2828

2929
describe('Create batch labels allocation', async () => {
3030
const jobName = 'batch-labels-allocation-job';
3131
const region = 'europe-central2';
32+
const batchClient = new BatchServiceClient();
3233
let projectId;
3334

3435
before(async () => {

batch/test/create_batch_labels_job.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +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');
27-
const batchClient = new BatchServiceClient();
25+
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
2828

2929
describe('Create batch labels for job', async () => {
3030
const jobName = 'batch-labels-job';
3131
const region = 'europe-central2';
32+
const batchClient = new BatchServiceClient();
3233
let projectId;
3334

3435
before(async () => {

batch/test/create_batch_labels_runnable.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ 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');
27-
const batchClient = new BatchServiceClient();
25+
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
2828

2929
describe('Create batch labels runnable', async () => {
3030
const jobName = 'example-job';
3131
const region = 'us-central1';
32+
const batchClient = new BatchServiceClient();
3233
let projectId;
3334

3435
before(async () => {

batch/test/create_batch_notifications.test.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,25 @@ 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;
26-
const batchClient = new BatchServiceClient();
24+
const {deleteJob} = require('./batchClient_operations');
2725

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-
}
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
3828

3929
describe('Create batch notifications', async () => {
4030
const jobName = 'job-name-batch-notifications';
4131
const region = 'europe-central2';
4232
const topicId = 'topic-id';
43-
33+
const batchClient = new BatchServiceClient();
4434
let projectId;
4535

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

5040
after(async () => {
51-
await deleteJob(projectId, region, jobName);
41+
await deleteJob(batchClient, projectId, region, jobName);
5242
});
5343

5444
it('should create a new job with batch notifications', async () => {

batch/test/create_batch_using_service_account.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ 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');
28-
const batchClient = new BatchServiceClient();
29-
const resourceManagerClient = new ProjectsClient();
26+
27+
const cwd = path.join(__dirname, '..');
28+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
3029

3130
async function getProjectNumber(projectId) {
31+
const resourceManagerClient = new ProjectsClient();
3232
// Construct request
3333
const request = {
3434
name: `projects/${projectId}`,
@@ -42,6 +42,7 @@ async function getProjectNumber(projectId) {
4242
describe('Create batch job using service account', async () => {
4343
const jobName = 'batch-service-account-job';
4444
const region = 'europe-central2';
45+
const batchClient = new BatchServiceClient();
4546
let projectId, serviceAccountEmail;
4647

4748
before(async () => {

batch/test/create_gpu_job.test.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +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 execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24-
const cwd = path.join(__dirname, '..');
2523
const {BatchServiceClient} = require('@google-cloud/batch').v1;
26-
const batchClient = new BatchServiceClient();
24+
const {deleteJob} = require('./batchClient_operations');
2725

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-
}
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
3828

3929
describe('Create batch GPU job', async () => {
4030
const jobName = 'batch-gpu-job';
4131
const region = 'europe-central2';
32+
const batchClient = new BatchServiceClient();
4233
let projectId;
4334

4435
before(async () => {
4536
projectId = await batchClient.getProjectId();
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: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +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 execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24-
const cwd = path.join(__dirname, '..');
2523
const {BatchServiceClient} = require('@google-cloud/batch').v1;
26-
const batchClient = new BatchServiceClient();
24+
const {deleteJob} = require('./batchClient_operations');
2725

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-
}
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
3828

3929
describe('Create batch GPU job on N1', async () => {
4030
const jobName = 'batch-gpu-job-n1';
4131
const region = 'europe-central2';
32+
const batchClient = new BatchServiceClient();
4233
let projectId;
4334

4435
before(async () => {
4536
projectId = await batchClient.getProjectId();
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: 5 additions & 15 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 execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24-
const cwd = path.join(__dirname, '..');
2523
const {BatchServiceClient} = require('@google-cloud/batch').v1;
26-
const batchClient = new BatchServiceClient();
24+
const {deleteJob} = require('./batchClient_operations');
2725

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-
}
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
3828

3929
describe('Create batch local ssd job', async () => {
4030
const jobName = 'batch-local-ssd-job';
4131
const region = 'europe-central2';
42-
32+
const batchClient = new BatchServiceClient();
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: 4 additions & 4 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');
27-
const batchClient = new BatchServiceClient();
25+
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
2828

2929
describe('Create batch NFS job', async () => {
3030
const jobName = 'batch-nfs-job';
3131
const region = 'europe-central2';
32-
32+
const batchClient = new BatchServiceClient();
3333
let projectId;
3434

3535
before(async () => {

batch/test/create_persistent_disk_job.test.js

Lines changed: 5 additions & 15 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 execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24-
const cwd = path.join(__dirname, '..');
2523
const {BatchServiceClient} = require('@google-cloud/batch').v1;
26-
const batchClient = new BatchServiceClient();
24+
const {deleteJob} = require('./batchClient_operations');
2725

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-
}
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
3828

3929
describe('Create batch job with persistent disk', async () => {
4030
const jobName = 'batch-create-persistent-disk-job';
4131
const region = 'europe-central2';
42-
32+
const batchClient = new BatchServiceClient();
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 () => {

0 commit comments

Comments
 (0)