diff options
author | David Percy <david.percy@mongodb.com> | 2019-12-13 20:11:41 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-12-13 20:11:41 +0000 |
commit | 299369cafdebe49a4222f481159dcf915eba71ba (patch) | |
tree | fa15adea207f5b201946467c186af6cbffb2347b /jstests | |
parent | 1af1d190cb53ea5b7624904dceed7a6a24804b3e (diff) | |
download | mongo-299369cafdebe49a4222f481159dcf915eba71ba.tar.gz |
SERVER-44743 Clean up invalid view name even when the test throws
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/views/view_with_invalid_dbname.js | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/jstests/core/views/view_with_invalid_dbname.js b/jstests/core/views/view_with_invalid_dbname.js index 8305c9970f4..76812670b98 100644 --- a/jstests/core/views/view_with_invalid_dbname.js +++ b/jstests/core/views/view_with_invalid_dbname.js @@ -18,16 +18,21 @@ const viewDef = { viewOn: collName, pipeline: [] }; -assert.commandWorked(db.system.views.insert(viewDef)); -// If the reinitialization of the durable view catalog tries to create a NamespaceString using -// the 'viewName' field, it will throw an exception in a place that is not exception safe, -// resulting in an invariant failure. This previously occurred because validation was only -// checking the collection part of the namespace, not the dbname part. With correct validation -// in place, reinitialization succeeds despite the invalid name. -assert.commandWorked(db.adminCommand({restartCatalog: 1})); +try { + assert.commandWorked(db.system.views.insert(viewDef)); -// Don't let the bogus view stick around, or else it will cause an error in validation. -const res = db.system.views.deleteOne({_id: viewName}); -assert.eq(1, res.deletedCount); + // If the reinitialization of the durable view catalog tries to create a NamespaceString using + // the 'viewName' field, it will throw an exception in a place that is not exception safe, + // resulting in an invariant failure. This previously occurred because validation was only + // checking the collection part of the namespace, not the dbname part. With correct validation + // in place, reinitialization succeeds despite the invalid name. + assert.commandWorked(db.adminCommand({restartCatalog: 1})); +} finally { + // Don't let the bogus view stick around, or else it will cause an error in validation. + var result = db.system.views.deleteOne({_id: viewName}); +} +// If this test otherwise succeeded, assert cleaning up succeeded. +// Skip this assertion if the test otherwise failed, to avoid masking the original error. +assert.eq(1, result.deletedCount); }()); |