Skip to content

Commit 0e28547

Browse files
authored
Device Advisor Test Samples (#226)
*Description of changes:* Added test samples for device advisor tests. The samples are based on our current samples. Sample Name | Description and sample workflow | Test Cases -- | -- | -- MQTT Connection | The sample will be used to test MQTT connection feature. It will 1. open a MQTT connection 2.wait for callback 3.Then close the connection. | MQTT- Connection MQTT Subscribe | The sample will be used to test MQTT connection feature. It will 1. open a MQTT connection 2.subscribe for a topic 3. wait for callback 4. close the connection. | MQTT- Subscribe MQTT Publish | The sample will be used to test MQTT connection feature. It will 1. open a MQTT connection 2.publish to a topic 3. wait for callback 4. close the connection. | MQTT- Publish Shadow Update | The sample will be used to test MQTT connection feature. It will 1. open a MQTT connection 2. update shadow field 3.close the connection. | Shadow-Shadow Publish, Shadow Update By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent ddc962d commit 0e28547

File tree

13 files changed

+605
-0
lines changed

13 files changed

+605
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
import { TestType } from '../utils/datest_utils'
7+
8+
const datest_utils = require('../utils/datest_utils');
9+
10+
async function main() {
11+
// validate environment variables set for testing
12+
if(!datest_utils.validate_vars(TestType.CONNECT))
13+
{
14+
process.exit(-1)
15+
}
16+
const connection = datest_utils.build_direct_mqtt_connection();
17+
18+
// force node to wait 60 seconds before killing itself, promises do not keep node alive
19+
// ToDo: we can get rid of this but it requires a refactor of the native connection binding that includes
20+
// pinning the libuv event loop while the connection is active or potentially active.
21+
const timer = setInterval(() => { }, 60 * 1000);
22+
23+
await connection.connect();
24+
await connection.disconnect();
25+
26+
// Allow node to die if the promise above resolved
27+
clearTimeout(timer);
28+
29+
process.exit(0);
30+
}
31+
32+
33+
main();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "mqtt_connect",
3+
"version": "1.0.0",
4+
"description": "NodeJS IoT SDK v2 Pub Sub Sample",
5+
"homepage": "https://github.com/aws/aws-iot-device-sdk-js-v2",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/aws/aws-iot-device-sdk-js-v2.git"
9+
},
10+
"contributors": [
11+
"AWS SDK Common Runtime Team <[email protected]>"
12+
],
13+
"license": "Apache-2.0",
14+
"main": "./dist/index.ts",
15+
"scripts": {
16+
"tsc": "tsc",
17+
"prepare": "npm run tsc"
18+
},
19+
"devDependencies": {
20+
"@types/node": "^10.17.50",
21+
"typescript": "^3.9.7"
22+
},
23+
"dependencies": {
24+
"aws-iot-device-sdk-v2": "../../../"
25+
}
26+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
5+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6+
// "lib": [], /* Specify library files to be included in the compilation. */
7+
// "allowJs": true, /* Allow javascript files to be compiled. */
8+
// "checkJs": true, /* Report errors in .js files. */
9+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
10+
"declaration": true, /* Generates corresponding '.d.ts' file. */
11+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
12+
"sourceMap": true, /* Generates corresponding '.map' file. */
13+
// "outFile": "./", /* Concatenate and emit output to single file. */
14+
"outDir": "./dist", /* Redirect output structure to the directory. */
15+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
16+
// "composite": true, /* Enable project compilation */
17+
// "removeComments": false, /* Do not emit comments to output. */
18+
// "noEmit": true, /* Do not emit outputs. */
19+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
20+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
21+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
22+
/* Strict Type-Checking Options */
23+
"strict": true, /* Enable all strict type-checking options. */
24+
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
25+
"strictNullChecks": true, /* Enable strict null checks. */
26+
"strictFunctionTypes": true, /* Enable strict checking of function types. */
27+
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
28+
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
29+
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
30+
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
31+
/* Additional Checks */
32+
"noUnusedLocals": true, /* Report errors on unused locals. */
33+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
34+
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
35+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
36+
/* Module Resolution Options */
37+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
38+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
39+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
40+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
41+
// "typeRoots": [], /* List of folders to include type definitions from. */
42+
// "types": [], /* Type declaration files to be included in compilation. */
43+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
44+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
45+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
46+
/* Source Map Options */
47+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
48+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
49+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
50+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
51+
/* Experimental Options */
52+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
53+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
54+
},
55+
"include": [
56+
"*.ts"
57+
],
58+
"exclude": [
59+
"node_modules",
60+
"dist"
61+
]
62+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
import { mqtt } from 'aws-iot-device-sdk-v2';
6+
import { TestType } from '../utils/datest_utils'
7+
8+
const datest_utils = require('../utils/datest_utils');
9+
10+
11+
async function main() {
12+
if(!datest_utils.validate_vars(TestType.SUB_PUB))
13+
{
14+
process.exit(-1)
15+
}
16+
const connection = datest_utils.build_direct_mqtt_connection();
17+
18+
// force node to wait 60 seconds before killing itself, promises do not keep node alive
19+
// ToDo: we can get rid of this but it requires a refactor of the native connection binding that includes
20+
// pinning the libuv event loop while the connection is active or potentially active.
21+
const timer = setInterval(() => { }, 60 * 1000);
22+
23+
// connect to mqtt
24+
await connection.connect();
25+
26+
// publish message to topic
27+
const msg = {
28+
message: "Device Advisor Test"
29+
};
30+
const json_msg = JSON.stringify(msg);
31+
await connection.publish(datest_utils.topic, json_msg, mqtt.QoS.AtLeastOnce);
32+
33+
// disconnect
34+
await connection.disconnect();
35+
36+
// Allow node to die if the promise above resolved
37+
clearTimeout(timer);
38+
process.exit(0);
39+
}
40+
41+
42+
main();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "mqtt_publish",
3+
"version": "1.0.0",
4+
"description": "NodeJS IoT SDK v2 Devcie Advisor MQTT Publish Test",
5+
"homepage": "https://github.com/aws/aws-iot-device-sdk-js-v2",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/aws/aws-iot-device-sdk-js-v2.git"
9+
},
10+
"contributors": [
11+
"AWS SDK Common Runtime Team <[email protected]>"
12+
],
13+
"license": "Apache-2.0",
14+
"main": "./dist/index.ts",
15+
"scripts": {
16+
"tsc": "tsc",
17+
"prepare": "npm run tsc"
18+
},
19+
"devDependencies": {
20+
"@types/node": "^10.17.50",
21+
"typescript": "^3.9.7"
22+
},
23+
"dependencies": {
24+
"aws-iot-device-sdk-v2": "../../../"
25+
}
26+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
5+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6+
// "lib": [], /* Specify library files to be included in the compilation. */
7+
// "allowJs": true, /* Allow javascript files to be compiled. */
8+
// "checkJs": true, /* Report errors in .js files. */
9+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
10+
"declaration": true, /* Generates corresponding '.d.ts' file. */
11+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
12+
"sourceMap": true, /* Generates corresponding '.map' file. */
13+
// "outFile": "./", /* Concatenate and emit output to single file. */
14+
"outDir": "./dist", /* Redirect output structure to the directory. */
15+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
16+
// "composite": true, /* Enable project compilation */
17+
// "removeComments": false, /* Do not emit comments to output. */
18+
// "noEmit": true, /* Do not emit outputs. */
19+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
20+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
21+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
22+
/* Strict Type-Checking Options */
23+
"strict": true, /* Enable all strict type-checking options. */
24+
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
25+
"strictNullChecks": true, /* Enable strict null checks. */
26+
"strictFunctionTypes": true, /* Enable strict checking of function types. */
27+
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
28+
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
29+
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
30+
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
31+
/* Additional Checks */
32+
"noUnusedLocals": true, /* Report errors on unused locals. */
33+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
34+
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
35+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
36+
/* Module Resolution Options */
37+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
38+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
39+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
40+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
41+
// "typeRoots": [], /* List of folders to include type definitions from. */
42+
// "types": [], /* Type declaration files to be included in compilation. */
43+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
44+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
45+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
46+
/* Source Map Options */
47+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
48+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
49+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
50+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
51+
/* Experimental Options */
52+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
53+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
54+
},
55+
"include": [
56+
"*.ts"
57+
],
58+
"exclude": [
59+
"node_modules",
60+
"dist"
61+
]
62+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
import { mqtt } from 'aws-iot-device-sdk-v2';
6+
import { TestType } from '../utils/datest_utils'
7+
8+
const datest_utils = require('../utils/datest_utils');
9+
10+
11+
async function main() {
12+
if(!datest_utils.validate_vars(TestType.SUB_PUB))
13+
{
14+
process.exit(-1)
15+
}
16+
const connection = datest_utils.build_direct_mqtt_connection();
17+
18+
// force node to wait 60 seconds before killing itself, promises do not keep node alive
19+
// ToDo: we can get rid of this but it requires a refactor of the native connection binding that includes
20+
// pinning the libuv event loop while the connection is active or potentially active.
21+
const timer = setInterval(() => { }, 60 * 1000);
22+
23+
// connect to mqtt
24+
await connection.connect();
25+
26+
// subscribe message to topic
27+
await connection.subscribe(datest_utils.topic, mqtt.QoS.AtMostOnce);
28+
29+
// disconnect
30+
await connection.disconnect();
31+
32+
// Allow node to die if the promise above resolved
33+
clearTimeout(timer);
34+
process.exit(0);
35+
}
36+
37+
38+
main();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "mqtt_subscribe",
3+
"version": "1.0.0",
4+
"description": "NodeJS IoT SDK v2 Devcie Advisor MQTT Subscribe Test",
5+
"homepage": "https://github.com/aws/aws-iot-device-sdk-js-v2",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/aws/aws-iot-device-sdk-js-v2.git"
9+
},
10+
"contributors": [
11+
"AWS SDK Common Runtime Team <[email protected]>"
12+
],
13+
"license": "Apache-2.0",
14+
"main": "./dist/index.ts",
15+
"scripts": {
16+
"tsc": "tsc",
17+
"prepare": "npm run tsc"
18+
},
19+
"devDependencies": {
20+
"@types/node": "^10.17.50",
21+
"typescript": "^3.9.7"
22+
},
23+
"dependencies": {
24+
"aws-iot-device-sdk-v2": "../../../"
25+
}
26+
}

0 commit comments

Comments
 (0)