Skip to content

Commit a019bf7

Browse files
Judy Linsantiago-corellium
authored andcommitted
feat: CORE-13681 - update getInstance to bypass throwing on instance on
1 parent 668ddae commit a019bf7

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@corellium/corellium-api",
3-
"version": "1.9.0",
3+
"version": "1.9.1",
44
"description": "Supported nodejs library for interacting with the Corellium service and VMs",
55
"main": "src/corellium.js",
66
"husky": {

src/corellium.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,21 +468,39 @@ class Corellium {
468468
})
469469
}
470470

471+
/**
472+
* @typedef {Object} GetInstanceOpts
473+
* @property {string} id - instanceId
474+
* @property {boolean} [throwIfNotOn=true] - Optional boolean property to not throw if the instance is off (defaults to true)
475+
*/
476+
471477
/**
472478
* Attempts to retrieve Instance by iterating through all projects until the instance is found.
473479
*
474-
* @param {string} instanceId
480+
* @param {string | GetInstanceOpts} opts - Either an instanceId string or an object with an `id` string and optional `throwIfNotOn` boolean (defaults to true if omitted)
475481
* @returns {Promise<Instance>}
476482
* @example
477483
* await corellium.getInstance('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
484+
* @example
485+
* await corellium.getInstance({ id: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', throwIfNotOn: false })
486+
* @example
487+
* await corellium.getInstance({ id: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' })
478488
*/
479-
async getInstance (instanceId) {
489+
async getInstance (opts) {
480490
let lastError
491+
let id, throwIfNotOn
492+
if (typeof opts === 'string') {
493+
id = opts
494+
throwIfNotOn = true
495+
} else {
496+
({ id, throwIfNotOn = true } = opts)
497+
}
498+
481499
const projects = await this.projects()
482500
for (const project of projects) {
483501
try {
484-
const instance = await project.getInstance(instanceId)
485-
if (instance.info.state !== 'on') {
502+
const instance = await project.getInstance(id)
503+
if (throwIfNotOn && (instance.info.state !== 'on')) {
486504
throw new Error('The instance is not turned on')
487505
}
488506
return instance
@@ -495,7 +513,7 @@ class Corellium {
495513
}
496514
}
497515

498-
throw lastError || new Error(`Could not retrieve instance! instanceId=${instanceId}`)
516+
throw lastError || new Error(`Could not retrieve instance! instanceId=${id}`)
499517
}
500518
}
501519

test/integration-tests.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ describe('Corellium API', function () {
4242
let INSTANCE_VERSIONS = []
4343
if (CONFIGURATION.testFlavor === 'ranchu') {
4444
this.slow(10000)
45-
this.timeout(20000)
45+
this.timeout(60000)
4646

4747
BASE_LIFECYCLE_TIMEOUT = 40000
48-
BASE_SNAPSHOT_TIMEOUT = 20000
48+
BASE_SNAPSHOT_TIMEOUT = 60000
4949
INSTANCE_VERSIONS = ['7.1.2', '8.1.0', '9.0.0', '10.0.0', '11.0.0', '12.0.0']
5050
} else {
5151
this.slow(40000)
@@ -185,6 +185,12 @@ describe('Corellium API', function () {
185185
assert(foundInstance.id === instance.id)
186186
})
187187

188+
it('can get instance and bypass instance on error', async function () {
189+
const instance = instanceMap.get(INSTANCE_VERSIONS[0])
190+
const foundInstance = await corellium.getInstance({ id: instance.id, throwIfNotOn: false })
191+
assert(foundInstance.id === instance.id)
192+
})
193+
188194
// Not visible to cloud users with one project:
189195
it('can add and remove keys', async function () {
190196
const keyInfo = await project

0 commit comments

Comments
 (0)