Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/units/device/plugins/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default syrup.serial()

group.on('join', () => {
service.freezeRotation(0)
service.wake()
service.sendCommand('input keyevent 224') // KEYCODE_WAKEUP
service.acquireWakeLock()
})

Expand All @@ -54,7 +54,7 @@ export default syrup.serial()
service.sendCommand('settings put system screen_brightness_mode 0'),
service.sendCommand('settings put system screen_brightness 0'),
service.setMasterMute(true),
service.sendCommand('input keyevent 26'),
service.sendCommand('input keyevent 223'), // KEYCODE_SLEEP
service.sendCommand('settings put global http_proxy :0'),
service.sendCommand('pm clear com.android.chrome'),
service.sendCommand('pm clear com.chrome.beta'),
Expand Down
14 changes: 9 additions & 5 deletions lib/units/device/resources/minitouch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ export default syrup.serial()
}

const checkExecutable = async (res: Resource) => {
const stats = await adb.getDevice(options.serial).stat(res.dest)
return (stats.mode & fs.constants.S_IXUSR) === fs.constants.S_IXUSR
try {
const stats = await adb.getDevice(options.serial).stat(res.dest)
return (stats.mode & fs.constants.S_IXUSR) === fs.constants.S_IXUSR
} catch (err: any) {
return false
}
}

const installResource = async (res: Resource): Promise<void> => {
Expand All @@ -65,7 +69,7 @@ export default syrup.serial()
await removeResource(res)
await pushResource(res)
const ok = await checkExecutable(res)

if (!ok) {
log.error('Pushed "%s" not executable, attempting fallback location', res.comm)
res.shift()
Expand All @@ -75,7 +79,7 @@ export default syrup.serial()

const plugin = {
bin: resources.bin.dest,
run: (cmd?: string) =>
run: (cmd?: string) =>
adb.getDevice(options.serial).shell(`exec ${resources.bin.dest} ${cmd || ''}`),

stop: async () => {
Expand All @@ -93,4 +97,4 @@ export default syrup.serial()
await installResource(resources.bin)

return plugin
})
})
33 changes: 20 additions & 13 deletions lib/units/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface DeviceWorker {
resolveRegister?: () => void
register: Promise<void>
waitingTimeoutTimer?: NodeJS.Timeout
ports: number[]
delete: () => void
}

export interface Options {
Expand Down Expand Up @@ -145,16 +147,17 @@ export default (async function(options: Options) {
return
}

let allocatedPorts = ports.splice(0, 4)

const proc = options.fork(device, allocatedPorts)
const proc = options.fork(device, workers[device.serial].ports)
log.info('Spawned a device worker')

const exitListener = (code?: number, signal?: string) => {
ports.push(...allocatedPorts)
const cleanup = () => {
proc.removeAllListeners('exit')
proc.removeAllListeners('error')
proc.removeAllListeners('message')
}

const exitListener = (code?: number, signal?: string) => {
cleanup()

if (signal) {
log.warn('Device worker "%s" was killed with signal %s, assuming deliberate action and not restarting', device.serial, signal)
Expand All @@ -175,6 +178,7 @@ export default (async function(options: Options) {
if (!workers[device.serial]) {
procutil.gracefullyKill(proc, options.killTimeout)
onError(new Error('Device has been killed'))
cleanup()
}
workers[device.serial].terminate = () => exitListener(0)

Expand All @@ -199,11 +203,7 @@ export default (async function(options: Options) {

return {
kill: () => {
// Return used ports to the main pool
ports.push(...allocatedPorts)
proc.removeAllListeners('exit')
proc.removeAllListeners('error')
proc.removeAllListeners('message')
cleanup()

log.info('Gracefully killing device worker "%s"', device.serial)
return procutil.gracefullyKill(proc, options.killTimeout)
Expand Down Expand Up @@ -269,7 +269,8 @@ export default (async function(options: Options) {
// Worker stop
workers[device.serial].terminate = async() => {
resolveRegister()
delete workers[device.serial]

workers[device.serial].delete()

await worker?.kill?.() // if process exited - no effect
log.info('Cleaning up device worker "%s"', device.serial)
Expand Down Expand Up @@ -317,7 +318,12 @@ export default (async function(options: Options) {
state: 'waiting',
time: Date.now(),
terminate: () => {},
register: register(device) // Register device immediately, before 'running' state
register: register(device), // Register device immediately, before 'running' state
ports: ports.splice(0, 2),
delete: () => {
ports.push(...workers[device.serial].ports)
delete workers[device.serial]
}
}

stats()
Expand Down Expand Up @@ -357,7 +363,8 @@ export default (async function(options: Options) {
log.info('Disconnect device "%s" [%s]', device.serial, device.type)
clearTimeout(workers[device.serial]?.waitingTimeoutTimer)
await stop(device)
delete workers[device.serial]

workers[device.serial].delete()
}))

tracker.start()
Expand Down
72 changes: 4 additions & 68 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"express-validator": "4.3.0",
"fast-printf": "^1.6.10",
"file-saver": "1.3.3",
"follow-redirects": "1.15.5",
"follow-redirects": "1.15.6",
"formidable": "1.2.6",
"gm": "1.25.1",
"http-proxy": "1.18.1",
Expand Down Expand Up @@ -135,7 +135,6 @@
"devDependencies": {
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.33.0",
"@playwright/test": "^1.52.0",
"@types/bluebird": "^3.5.42",
"@types/chalk": "^0.4.31",
"@types/eventemitter3": "^1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/playwright:v1.52.0-noble
FROM mcr.microsoft.com/playwright:v1.55.1-noble

WORKDIR /tests

Expand Down
24 changes: 12 additions & 12 deletions test/e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
},
"dependencies": {
"@playwright/test": "^1.52.0",
"@playwright/test": "^1.55.1",
"typescript": "^5.5.3"
},
"devDependencies": {
Expand Down
Loading
Loading