Why does adding console.log statements prevent test timeouts?

Viewed 97

I've got some code that works fine running locally, tested using Supertest, but when the same test runs on CircleCI it fails due to time-outs.

The code in question is

for (const id of ids) {
  const urls = await scrapeLinks(id) // invokes puppeteer on a dockerised mock server
  await connectUrls(fbId, urls) // updates database using sequelize
}

Running locally this works fine.

Running the same tests on CircleCI this code takes too long to complete and the test times out.

But if I add a couple of console.log lines, then the tests do not time out

for (const id of ids) {
  console.log('start', id)
  const urls = await scrapeLinks(id) // invokes puppeteer on a dockerised mock server
  console.log('urls', urls)
  await connectUrls(fbId, urls) // updates database using sequelize
  console.log('end', id)
}

Running the tests on that works fine both locally, and on CircleCI.

My simple fix was of course simply to extend the timeout on my tests from 2 seconds to 5 seconds.

But my question is, why does the addition of console.log lines after each step make the code complete more quickly?

1 Answers

This is likely due to CircleCI's no_output_timeout property, which is defined as:

Elapsed time the command can run without output. The string is a decimal with unit suffix, such as “20m”, “1.25h”, “5s” (default: 10 minutes)

Therefore, if your program exceeds the given time set by this property without providing output, your program will timeout.

Related