forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request taskcluster#1414 from ededals/built-in/succeed
Built in/succeed smoketest
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const taskcluster = require('taskcluster-client'); | ||
|
||
exports.tasks = []; | ||
exports.tasks.push({ | ||
title: 'Built-in/succeed task check', | ||
requires: [], | ||
provides: [ | ||
'built-in/succeed', | ||
], | ||
run: async (requirements, utils) => { | ||
let task = { | ||
provisionerId: 'built-in', | ||
workerType: 'succeed', | ||
created: (new Date()).toJSON(), | ||
deadline: taskcluster.fromNowJSON('2 minutes'), | ||
metadata: { | ||
name: "Smoketest built-in/succeed", | ||
description: "built-in/succeed task created during smoketest", | ||
owner: "smoketest@taskcluster.net", | ||
source: "https://taskcluster.net", | ||
}, | ||
payload: {}, | ||
}; | ||
let taskId = taskcluster.slugid(); | ||
utils.status({message: 'built-in/succeed taskId: ' + taskId}); | ||
let queue = new taskcluster.Queue(taskcluster.fromEnvVars()); | ||
await queue.createTask(taskId, task); | ||
let pollForStatusStart = new Date(); | ||
while((new Date() - pollForStatusStart) < 120000){ | ||
let status = await queue.status(taskId); | ||
if (status.status.state === 'pending' || status.status.state === 'running'){ | ||
utils.status({ | ||
message: 'Polling built-in/succeed task. Current status: ' + status.status.state, | ||
}); | ||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
} else if (status.status.state === 'completed') { | ||
return { | ||
['built-in/succeed']: status.status.state, | ||
}; | ||
} else { | ||
throw new Error('Task finished with status ' + status.status.state); | ||
} | ||
} | ||
throw new Error('Deadline exceeded'); | ||
}, | ||
}); |