Skip to content

Commit da2c3e1

Browse files
committed
refactor: keep ios runner status off main thread
1 parent 0469f3c commit da2c3e1

3 files changed

Lines changed: 25 additions & 11 deletions

File tree

ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extension RunnerTests {
2727

2828
func execute(command: Command) throws -> Response {
2929
if command.command == .status {
30-
return try executeDispatched(command: command)
30+
return executeStatus(command: command)
3131
}
3232
commandJournal.accept(command: command)
3333
commandJournal.start(command: command)
@@ -41,6 +41,17 @@ extension RunnerTests {
4141
}
4242
}
4343

44+
private func executeStatus(command: Command) -> Response {
45+
guard
46+
let statusCommandId = command.statusCommandId?
47+
.trimmingCharacters(in: .whitespacesAndNewlines),
48+
!statusCommandId.isEmpty
49+
else {
50+
return Response(ok: false, error: ErrorPayload(message: "status requires statusCommandId"))
51+
}
52+
return Response(ok: true, data: commandJournal.status(commandId: statusCommandId))
53+
}
54+
4455
private func executeDispatched(command: Command) throws -> Response {
4556
if Thread.isMainThread {
4657
return try executeOnMainSafely(command: command)
@@ -200,14 +211,7 @@ extension RunnerTests {
200211

201212
switch command.command {
202213
case .status:
203-
guard
204-
let statusCommandId = command.statusCommandId?
205-
.trimmingCharacters(in: .whitespacesAndNewlines),
206-
!statusCommandId.isEmpty
207-
else {
208-
return Response(ok: false, error: ErrorPayload(message: "status requires statusCommandId"))
209-
}
210-
return Response(ok: true, data: commandJournal.status(commandId: statusCommandId))
214+
return executeStatus(command: command)
211215
case .shutdown:
212216
stopRecordingIfNeeded()
213217
return Response(ok: true, data: DataPayload(message: "shutdown"))

ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22

33
enum RunnerCommandLifecycleState: String {
4+
case notAccepted
45
case accepted
56
case started
67
case completed
@@ -66,13 +67,16 @@ final class RunnerCommandJournal {
6667

6768
func status(commandId: String) -> DataPayload {
6869
guard let normalized = normalizedCommandId(commandId) else {
69-
return DataPayload(lifecycleState: "notAccepted")
70+
return DataPayload(lifecycleState: RunnerCommandLifecycleState.notAccepted.rawValue)
7071
}
7172
lock.lock()
7273
let entry = entries[normalized]
7374
lock.unlock()
7475
guard let entry else {
75-
return DataPayload(commandId: normalized, lifecycleState: "notAccepted")
76+
return DataPayload(
77+
commandId: normalized,
78+
lifecycleState: RunnerCommandLifecycleState.notAccepted.rawValue
79+
)
7680
}
7781
return DataPayload(
7882
commandId: entry.commandId,

src/platforms/ios/__tests__/runner-client.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@ test('withRunnerCommandId replaces blank command ids', () => {
389389
assert.match(command.commandId ?? '', /^runner-/);
390390
});
391391

392+
test('withRunnerCommandId preserves existing command ids', () => {
393+
const command = withRunnerCommandId({ command: 'uptime', commandId: 'runner-existing' });
394+
395+
assert.deepEqual(command, { command: 'uptime', commandId: 'runner-existing' });
396+
});
397+
392398
test('withRunnerCommandId does not add command ids to status probes', () => {
393399
const command = withRunnerCommandId({
394400
command: 'status',

0 commit comments

Comments
 (0)