Skip to content

Commit

Permalink
Add rate test, flesh out state for other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strazzere committed Aug 24, 2021
1 parent 5f56994 commit 66b1394
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -264,8 +264,8 @@ Example:
let rateInfo = await instance.rate();
// dollars = rate * seconds / microcents / cents
console.log(`instance on for 24 hours: $${(rateInfo.on * (60 * 60 * 24) / 1000000 / 100).toFixed(2)} USD`)
console.log(`instance off for 24 hours: $${(rateInfo.off * (60 * 60 * 24) / 1000000 / 100).toFixed(2)} USD`)
console.log(`instance on for 24 hours: $${(rateInfo.onRateMicrocents * (60 * 60 * 24) / 1000000 / 100).toFixed(2)} USD`)
console.log(`instance off for 24 hours: $${(rateInfo.offRateMicrocents * (60 * 60 * 24) / 1000000 / 100).toFixed(2)} USD`)
```

Output:
Expand Down
33 changes: 29 additions & 4 deletions test/integration-tests.js
Expand Up @@ -347,6 +347,24 @@ describe("Corellium API", function () {
}),
);

describe(`billing ${instanceVersion}`, function () {
it("can get rate information", async function () {
const instance = instanceMap.get(instanceVersion);
const rate = await instance.rate();

assert.strictEqual(
((rate.onRateMicrocents * (60 * 60 * 24)) / 1000000 / 100).toFixed(2) > 0,
true,
`'On' rate should be larger than 0`,
);
assert.strictEqual(
((rate.offRateMicrocents * (60 * 60 * 24)) / 1000000 / 100).toFixed(2) > 0,
true,
`'Off' rate should be larger than 0`,
);
});
});

describe(`device lifecycle ${instanceVersion}`, function () {
this.slow(BASE_LIFECYCLE_TIMEOUT / 2);
this.timeout(BASE_LIFECYCLE_TIMEOUT);
Expand Down Expand Up @@ -403,8 +421,8 @@ describe("Corellium API", function () {
});

describe(`snapshots ${instanceVersion}`, function () {
this.slow(BASE_SNAPSHOT_TIMEOUT / 2);
this.timeout(BASE_SNAPSHOT_TIMEOUT);
this.slow(BASE_SNAPSHOT_TIMEOUT);
this.timeout(BASE_SNAPSHOT_TIMEOUT * 2);

before(
"should have an up-to-date instance",
Expand Down Expand Up @@ -442,6 +460,8 @@ describe("Corellium API", function () {
while (latestSnapshot.status.created !== true) {
await latestSnapshot.update();
}

await turnOn(instance);
});
} else {
it("can take snapshot if instance is on", async function () {
Expand All @@ -461,11 +481,12 @@ describe("Corellium API", function () {
);
const instance = instanceMap.get(instanceVersion);
if (CONFIGURATION.testFlavor === "ranchu") {
if (instance.state !== "off") {
await turnOff(instance);
if (instance.state !== "on") {
await turnOn(instance);
}

await latestSnapshot.restore();
await instance.waitForAgentReady();
} else {
await instance.pause();
await instance.waitForState("paused");
Expand All @@ -487,6 +508,10 @@ describe("Corellium API", function () {
),
);

if (instance.state !== "on") {
await turnOn(instance);
}

await latestSnapshot.delete();

while (
Expand Down

0 comments on commit 66b1394

Please sign in to comment.