diff --git a/tools/tests/apps/once/once.js b/tools/tests/apps/once/once.js index 2eb842d08a..57dbcefbcd 100644 --- a/tools/tests/apps/once/once.js +++ b/tools/tests/apps/once/once.js @@ -14,8 +14,23 @@ if (process.env.RUN_ONCE_OUTCOME === "hang") { if (process.env.RUN_ONCE_OUTCOME === "mongo") { var test = new Mongo.Collection('test'); - Meteor.startup(function () { - test.insert({ value: 86 }); + var triesLeft = 10; + + function tryInsert() { + try { + test.insert({ value: 86 }); + } catch (e) { + if (--triesLeft <= 0) { + throw e; + } + + console.log("insert failed; retrying:", String(e.stack || e)); + setTimeout(tryInsert, 1000); + return; + } + process.exit(test.findOne().value); - }); + } + + Meteor.startup(tryInsert); }