Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
QA interview question
ProgrammingMiddleOccasionalScenario

How would you approach asynchronous code with inputs from an untrusted API?

Answer

Start by making inputs, outputs, ownership and failure behavior explicit before choosing an implementation. Focus on asynchronous code with inputs from an untrusted API. Use small deterministic units plus integration behavior at real boundaries as the oracle. Cover normal flow, invalid inputs, exceptions, concurrency and resource cleanup. Keep data and dependencies controlled enough to reproduce failures. Release only when tests fail for one understandable reason and the code remains easy to change.

Strong answer includes

  • explicit risk and test oracle for asynchronous code
  • controls side effects and dependencies
  • designs for deterministic tests
  • measurable evidence and residual-risk statement

Practical example

An async handler awaited a third-party webhook payload and passed a field straight into a database query without validation, and once the partner sent a payload missing that field entirely, the awaited call threw inside a fire-and-forget promise that nobody was listening to. The approach was to validate the payload synchronously before entering any async chain, and to make sure every async chain has an explicit rejection handler.

#programming#test-code#asynchronous-code

Sources

Git referenceGit Project · Version control concepts and commandsPlaywright best practicesMicrosoft · Reliable modern browser automationMDN JavaScript GuideMozilla · Functions, closures, objects, classes, error handling and asynchronous programming (promises, async/await)