Skip to content

Commit 0f3be94

Browse files
committed
[Testing]Add e2e test for multi connect
Add multi_connection_test to ensure that the code logic can still connect normally in the case of multiple connections.
1 parent e1d58ec commit 0f3be94

File tree

2 files changed

+92
-3
lines changed

2 files changed

+92
-3
lines changed

test/connect_test/check_android_connection_ci.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,21 @@ def TestAndroidCon(args):
7979
if (args.conection_type == "websocket"):
8080
print('start: websocket common test.')
8181
command_run = "../../../buildtools/node/bin/npm install && ../../../buildtools/node/bin/node websocket.js"
82+
CheckExecute(command_run)
83+
print('start: websocket multi connection test')
84+
command_run = "../../../buildtools/node/bin/npm install && ../../../buildtools/node/bin/node multi_connection_test.js"
85+
CheckExecute(command_run)
8286
else:
8387
if(args.conection_type == "usb"):
84-
print('start: usb common test and large message test.')
85-
command_run = "../../../buildtools/node/bin/npm install && ../../../buildtools/node/bin/node usb.js && ../../../buildtools/node/bin/node large_message_test.js"
86-
CheckExecute(command_run)
88+
print('start: usb common test.')
89+
command_run = "../../../buildtools/node/bin/npm install && ../../../buildtools/node/bin/node usb.js"
90+
CheckExecute(command_run)
91+
print('start: usb large message test')
92+
command_run = "../../../buildtools/node/bin/npm install && ../../../buildtools/node/bin/node large_message_test.js"
93+
CheckExecute(command_run)
94+
print('start: usb multi connection test')
95+
command_run = "../../../buildtools/node/bin/npm install && ../../../buildtools/node/bin/node multi_connection_test.js"
96+
CheckExecute(command_run)
8797

8898
def CheckBuildDebugRouterTestApk(args):
8999
command = './gradlew clean'
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const DebugRouterConnector = require("@lynx-js/debug-router-connector").DebugRouterConnector;
2+
3+
const util = require('./util.js');
4+
5+
function sleep(ms) {
6+
return new Promise(resolve => setTimeout(resolve, ms));
7+
}
8+
9+
10+
async function TryConnect(driver, serial, num) {
11+
console.log('TryConnect start: ', num);
12+
await sleep(3000);
13+
const clients = await driver.connectUsbClients(serial, 5000);
14+
if (clients && clients.length > 0) {
15+
console.log(clients[0].info.query.raw_info);
16+
if (num < 10) {
17+
return;
18+
}
19+
sleep(3000);
20+
console.log('TryConnect check the last connect start: ', num);
21+
const message = 'a'.repeat(20);
22+
const result = await clients[0].sendCustomizedMessage("App.GetCloseCoverageUploadSwitch", { message: message }, -1, "App");
23+
console.log(result);
24+
if (!result) {
25+
console.error('sendCustomizedMessage failed');
26+
process.exit(-1);
27+
} else {
28+
console.log('sendCustomizedMessage success');
29+
}
30+
} else {
31+
console.error('no clients connected');
32+
}
33+
console.log('TryConnect end: ', num);
34+
}
35+
36+
async function main() {
37+
const startActivity = 'adb shell am start -n com.lynx.debugrouter.testapp/com.lynx.debugrouter.testapp.MainActivity'
38+
util.exec(startActivity, 10000).then((data) => {
39+
console.log("startActivity:" + data);
40+
}).catch((reason) => {
41+
console.log("startActivity FAILED:" + reason);
42+
process.exit(-1);
43+
});
44+
45+
const driver = new DebugRouterConnector({
46+
manualConnect: true,
47+
enableWebSocket: false,
48+
enableAndroid: true,
49+
enableIOS: true,
50+
enableDesktop: false,
51+
websocketOption: {}
52+
});
53+
54+
try {
55+
const devicesArray = await driver.connectDevices(5000);
56+
if (devicesArray.length === 0) {
57+
console.error('no devices connected');
58+
return;
59+
}
60+
var serial = devicesArray[0].serial;
61+
const Connect0 = TryConnect(driver, serial, 1);
62+
const Connect1 = TryConnect(driver, serial, 2);
63+
const Connect2 = TryConnect(driver, serial, 3);
64+
const Connect3 = TryConnect(driver, serial, 4);
65+
const Connect4 = TryConnect(driver, serial, 5);
66+
const Connect5 = TryConnect(driver, serial, 6);
67+
const Connect6 = TryConnect(driver, serial, 7);
68+
const Connect7 = TryConnect(driver, serial, 8);
69+
const Connect8 = TryConnect(driver, serial, 9);
70+
const Connect9 = TryConnect(driver, serial, 10);
71+
await Promise.all([Connect0, Connect1, Connect2, Connect3, Connect4, Connect5, Connect6, Connect7, Connect8, Connect9]);
72+
console.log('TryConnect test end.');
73+
} catch (error) {
74+
console.error('Call tryConnect error: ', error);
75+
}
76+
process.exit(0);
77+
}
78+
79+
main();

0 commit comments

Comments
 (0)