Chapter 4: Resiliency -- Ticket: Timeouts

I added the option for the write timeout. The tieouts test failed. I can’t. figure the reason why.
Note, the connection pool successfully passed.

this.global.mflixClient = await MongoClient.connect(
process.env.MFLIX_DB_URI,
// TODO: Connection Pooling
// Set the connection pool size to 50 for the testing environment.
{ poolSize: 50,
// TODO: Timeouts
// Set the write timeout limit to 2500 milliseconds for the testing environment.
wtimeout: 2500,
useNewUrlParser: true }
)

1 Like

Hi @Chris_Job1,
Your configuration looks good to me. If this is logging an error in the terminal/command-prompt, can you please error message with us?

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

Hey @SourabhBagrecha
This is the error I’m getting

MLrbqy24J70MD6M:mflix-js p40000x$ npm test -t timeouts

server@1.0.0 test /Users/p40000x/rbs/mongodb/m220/mflix-js
jest --passWithNoTests “timeouts”

Determining test suites to run…Setup Mongo Connection
(node:60639) [MONGODB DRIVER] Warning: Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead.
(Use node --trace-warnings ... to show where the warning was created)
(node:60639) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
FAIL test/timeouts.test.js
Timeouts
✕ Timeout is set to 2500 milliseconds (43ms)

● Timeouts › Timeout is set to 2500 milliseconds

expect(received).toBe(expected) // Object.is equality

Expected: 2500
Received: undefined

   8 |   test("Timeout is set to 2500 milliseconds", async () => {
   9 |     const { wtimeout } = await MoviesDAO.getConfiguration()
> 10 |     expect(wtimeout).toBe(2500)
     |                      ^
  11 |   })
  12 | })
  13 | 

  at toBe (test/timeouts.test.js:10:22)
  at tryCatch (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:86:17)
  at Generator._invoke (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:66:24)
  at Generator.next (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:117:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)

Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 0.908s, estimated 1s
Ran all test suites matching /timeouts/i.
Teardown Mongo Connection
npm ERR! Test failed. See above for more details.

Hi @Chris_Job1, please take a look at the discussions below:

All you have to do is replace the following:

with:

writeConcern: {wtimeout: 2500}

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

Hey @SourabhBagrecha,
I updated both the src/index.js and the test/config/mongoEnvironment.js files.
Sadly, I’m getting the same error when I run the timeouts unit test

I’ve completed all the tickets and the final questions.