Skip to content

question, test: best way to retry async task #13346

Closed
@refack

Description

@refack
  • Version: master
  • Platform: *
  • Subsystem: test

In some tests we want to delay or retry an async task whose exact timing for success is indeterminable.
A few option come to mind:

  1. setTimeout(task, n) where n is an arbitrary number that's empirically proven to be sufficient.
  2. const interval = setInterval(() => {const ret = task(); if (ret) clearInterval(interval);}), 1)
  3. do { const ret = await task()} while (ret != true)

Any other ideas or preferences?
Ref: #13252
Ref: #13312

/cc @nodejs/testing

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues that look for answers.testIssues and PRs related to the tests.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions