Connection timing out - Mongoclint.spec.js test failing

I tried to run the first test and I keep getting two errors, i’m assuming my connection isn’t so great so that’s the reason for the error? i’m really not sure how to resolve this.

I have set the connectTimeoutMS: 20000 which seems to help, but I am now getting “Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.” as an error.

How do I set the global timeout value higher? there does not seem to be a jest.setup.js file and i don’t want to mess with this core of the application to much to resolve this.

  testClient = await MongoClient.connect(
    process.env.MFLIX_DB_URI, // initial mongoClient with URI string with different parameters (options)
    { connectTimeoutMS: 20000, retryWrites: true, useNewUrlParser: true },
  )

All the tests are passing now played with the timeout fields, but i would still love some help with how to increase the jest.setTimeout globally.

Globally you can create a jest.setup.js within the project root ( same place as package.json ) and include a:

jest.setTimeout(30000)

Or appropriate number, as the sole content of that file. Jest will look for this file on startup and apply this. If you find you need such a thing, then this is preferable to altering every test file.

NOTE: This is somewhat a sledgehammer and whilst fine for basic verification tests, this should NOT be considered a “cure all” for similar errors in the remaining course material.

If any of the exercise tickets display similar long timeouts, this is more likely the result of returning too much data, and you should review the API usage accordingly.

Thank you this fixed it :smiley:

I concur. To fix this I modified the timeout value in test/lessons/mongoclient.spec.js. I changed from “connectTimeoutMS: 200” to “connectTimeoutMS: 30000” in all the places. Since I was relying on a phone tethered to my laptop for my internet (and sitting far away from the city) the connection was slow I guess.