[SERVER-78457] Remove assert.commandFailed() and assert.throws() Created: 26/Jun/23  Updated: 10/Oct/23

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Engineering Test Priority: Major - P3
Reporter: Judah Schvimer Assignee: Backlog - Service Architecture
Resolution: Unresolved Votes: 0
Labels: make-server-testing-joyful
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-78791 x509_client.js must define SERVER_USER Closed
Assigned Teams:
Service Arch
Participants:

 Description   

As max.hirschhorn@mongodb.com said well, "assert.commandFailedWithCode() should always be preferred over assert.commandFailed() because it is possible to write the input parameters to a command incorrectly where it fails with BadValue/TypeMismatch/FailedToParse/etc. and means the test isn't exercising what it intended".

assert.throws has the same problem and assert.throwsWithCode should be used instead.



 Comments   
Comment by Judah Schvimer [ 11/Jul/23 ]

matt.broadstone@mongodb.com said he can easily automate this with his javascript modernization efforts.

Comment by David Storch [ 06/Jul/23 ]

There are quite a few callers of these two functions in the code base:

$ git grep -w "assert.commandFailed" | wc -l
826
$ git grep -w "assert.throws" | wc -l
1340

judah.schvimer@mongodb.com do you know why this was assigned to the Query Optimization team? If we want to tackle this across core server contributors, I think it would be best to divide and conquer. Each team could be responsible for fixing the tests that they own.

CC joseph.kanaan@mongodb.com

Comment by Max Hirschhorn [ 26/Jun/23 ]

assert.throws has the same problem and assert.throwsWithCode should be used instead.

I believe there are cases where the generated Error object won't have a .code property (SERVER-54026). And so using the Error object return value from the assert.throws() function and checking its .message or equivalent property is also another option (for example).

Generated at Thu Feb 08 06:38:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.