Skip to content

Commit

Permalink
Fix samples and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gryczj committed Oct 21, 2024
1 parent bf5bab3 commit a1b33bf
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 40 deletions.
18 changes: 0 additions & 18 deletions tpu/queuedResource/createQueuedResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,6 @@ async function main(
await operation.promise();

console.log(`Queued resource ${queuedResourceName} created.`);

const getNodeRequest = {
name: `projects/${projectId}/locations/${zone}/nodes/${nodeName}`,
};

console.log(`Waiting for TPU node ${nodeName} to become ready...`);

// Poll for TPU node state every 30 seconds
const intervalId = setInterval(async () => {
const [node] = await tpuClient.getNode(getNodeRequest);

if (node.state === 'READY') {
clearInterval(intervalId);
console.log(`TPU node ${nodeName} is ready.`);
} else {
console.log(`TPU node ${nodeName} is in state: ${node.state}`);
}
}, 30000);
}
await callCreateQueuedResource();
// [END tpu_queued_resources_create]
Expand Down
20 changes: 0 additions & 20 deletions tpu/queuedResource/deleteQueuedResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,11 @@ async function main(queuedResourceName, zone) {
// The zone of your queued resource.
// zone = 'europe-west4-a';

async function callDeleteTpuVM(nodeName) {
const request = {
name: `projects/${projectId}/locations/${zone}/nodes/${nodeName}`,
};

const [operation] = await tpuClient.deleteNode(request);

// Wait for the delete operation to complete.
await operation.promise();

console.log(`Node: ${nodeName} deleted.`);
}

async function callDeleteQueuedResource() {
const request = {
name: `projects/${projectId}/locations/${zone}/queuedResources/${queuedResourceName}`,
};

// Retrive node name
const [response] = await tpuClient.getQueuedResource(request);
const nodeName = response.tpu.nodeSpec[0].nodeId;

// Before deleting the queued resource it is required to delete the TPU VM.
await callDeleteTpuVM(nodeName);

const [operation] = await tpuClient.deleteQueuedResource(request);

// Wait for the delete operation to complete.
Expand Down
4 changes: 2 additions & 2 deletions tpu/test/queuedResource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ const cp = require('child_process');
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
const cwd = path.join(__dirname, '..');

describe('TPU queued resource', async () => {
describe('TPU queued resource', () => {
const queuedResourceName = `queued-resource-name-1a2sdf${Math.floor(Math.random() * 1000 + 1)}`;
const nodePrefix = 'node-name-2a2b3c';
const nodeName = `${nodePrefix}${Math.floor(Math.random() * 1000 + 1)}`;
const zone = 'europe-west4-a';
const tpuType = 'v2-8';
const tpuSoftwareVersion = 'tpu-vm-tf-2.14.1';

it('should create a new queued resource', () => {
it('should create a new queued resource', async () => {
const response = execSync(
`node ./queuedResource/createQueuedResource.js ${nodeName} ${queuedResourceName} ${zone} ${tpuType} ${tpuSoftwareVersion}`,
{
Expand Down

0 comments on commit a1b33bf

Please sign in to comment.