P213 · Workflow control

Manage helper process lifetime

Start dependencies, wait for readiness, execute the task and always clean up owned processes.

Editorially reviewed

These examples and illustrative results are independently authored teaching materials, not measured model results.

Use case

Browser tests need frontend/backend services, possibly alongside user-owned listeners. Teaching scope permits owned test processes, not termination of existing services. Test/readiness failures must also clean up owned resources.

Mechanism

Inspect listeners/ownership before starting; reused services are not cleanup targets. Track newly started identities, wait for application readiness within a bound and preserve test results. Finally clean owned processes/necessary children. Report startup/test/cleanup outcomes separately so successful cleanup does not erase failure.

Bad example

Start duplicate services, leave them after failed tests, then kill everything on those ports without ownership checks.

Good example

Check existing services first. Start permitted test processes only as needed and retain identities. Wait for bounded application readiness, not merely open ports. Run tests and preserve exit/output; finally clean owned processes/children only. Keep reused user services running, report cleanup gaps and retain test failure as the test verdict.

Why the change matters

Failure skips ordinary success-path steps; finally makes cleanup unconditional. Ownership records prevent it from targeting unrelated user processes.

Observable expectation

Simulate success, test failure and second-service startup failure: already started owned processes are cleaned while user services remain. Preserve original failure and cleanup status.

Terminate returning does not prove child cleanup, and listening does not prove health.

Limits

The source uses shell processes/port checks; stronger application/process-tree checks are teaching improvements, not upstream guarantees. Platform startup, log consumption and termination differ. No real processes are started/stopped here.

Sources and evidence

Read the editorial criteria