0

Which is the best way to intentionally add latency to db.collection.save() for unit testing purposes.

Let say, I have function that I need to test:

function() {
  let item = collection.findOne({});
  ...
  collection.save(item);
}

I would like collection.save to be delayed without changing the function code.

Basically I'm looking for something like this express pause middleware but for MongoDB driver.

Kostanos
  • 9,615
  • 4
  • 51
  • 65
  • But the function `findOne` is asynchronous... – stdob-- Dec 08 '17 at 21:37
  • Something like this? https://stackoverflow.com/questions/1447407/whats-the-equivalent-of-javas-thread-sleep-in-javascript – dnickless Dec 09 '17 at 14:46
  • Or this: https://stackoverflow.com/questions/1094760/network-tools-that-simulate-slow-network-connection – dnickless Dec 09 '17 at 14:48
  • Thank you @dnickless but none of these solutions works for me, I mean, as I mentioned in the question, I need to simulate the delay on collection.save without changing the main function that calls it (for unit testing purposes) – Kostanos Dec 10 '17 at 14:20
  • I just added into description the similar library that I'm looking for @dnickless – Kostanos Dec 10 '17 at 14:25

0 Answers0