Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
test(e2e): make iot parts more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Sep 13, 2019
1 parent 00dabb9 commit 921ce96
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 18 additions & 5 deletions feature-runner/steps/bifravst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export const bifravstStepRunners = ({
deviceId: catName,
certsDir: path.resolve(process.cwd(), 'certificates'),
caCert: path.resolve(process.cwd(), 'data', 'AmazonRootCA1.pem'),
log: (...message: any[]) => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
runner.progress('IoT (cert)', ...message)
},
debug: (...message: any[]) => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
runner.progress('IoT (cert)', ...message)
},
})

// eslint-disable-next-line require-atomic-updates
Expand Down Expand Up @@ -54,10 +62,9 @@ export const bifravstStepRunners = ({
// eslint-disable-next-line require-atomic-updates
runner.store[`cat:connection:${catId}`] = connection

await new Promise(resolve => {
connection.on('connect', async () => {
resolve()
})
await new Promise((resolve, reject) => {
connection.on('connect', resolve)
connection.on('error', reject)
})
}
return [catId, mqttEndpoint]
Expand All @@ -74,7 +81,8 @@ export const bifravstStepRunners = ({
const reported = JSON.parse(step.interpolatedArgument)
const catId = deviceId || runner.store['cat:id']
const connection = runner.store[`cat:connection:${catId}`]
const updatePromise = await new Promise(resolve => {
const updatePromise = await new Promise((resolve, reject) => {
const timeout = setTimeout(reject, 10 * 1000)
connection.on(
'status',
async (
Expand All @@ -86,10 +94,15 @@ export const bifravstStepRunners = ({
await runner.progress('IoT < status', stat)
await runner.progress('IoT < status', JSON.stringify(stateObject))
if (stat === 'accepted') {
clearTimeout(timeout)
resolve(stateObject)
}
},
)
connection.on('error', () => {
clearTimeout(timeout)
reject()
})
connection.register(catId, {}, async () => {
await runner.progress('IoT > reported', catId)
await runner.progress('IoT > reported', JSON.stringify(reported))
Expand Down
8 changes: 8 additions & 0 deletions features/DeviceUpdateShadow.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ Feature: Device: Update Shadow
"bat": {
"v": 3781,
"ts": 1567942204010
},
"cfg": {
"act": false,
"actwt": 60,
"mvres": 60,
"mvt": 3600,
"gpst": 1000,
"acct": 5
}
}
"""

0 comments on commit 921ce96

Please sign in to comment.