[SERVER-26503] Fix incorrect uses of assert.throws() Created: 06/Oct/16  Updated: 19/Nov/16  Resolved: 13/Oct/16

Status: Closed
Project: Core Server
Component/s: Testing Infrastructure
Affects Version/s: 3.3.15
Fix Version/s: 3.4.0-rc1

Type: Bug Priority: Major - P3
Reporter: Robert Guo (Inactive) Assignee: Robert Guo (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-21087 Some uses of assert.throws() always pass Closed
is depended on by SERVER-21089 assert.throws() doesn't check 2nd arg... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: TIG 2016-10-10, TIG 2016-10-31
Participants:
Linked BF Score: 0

 Description   

Some tests use assert.throws() incorrectly. They need to be fixed before the changes in SERVER-21087 and SERVER-21089 can be made.



 Comments   
Comment by Githook User [ 31/Oct/16 ]

Author:

{u'username': u'guoyr', u'name': u'Robert Guo', u'email': u'robert.guo@10gen.com'}

Message: SERVER-26503 call hasNext() in assert.throws
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/e06c31e852fc62dd0cb58e8faa9df003cdbb9713

Comment by Githook User [ 28/Oct/16 ]

Author:

{u'username': u'guoyr', u'name': u'Robert Guo', u'email': u'robert.guo@10gen.com'}

Message: SERVER-26503 fix incorrect uses of assert.throw
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/122ebcd2b0486892277dd0733fb5429a8e641f60

Comment by Githook User [ 13/Oct/16 ]

Author:

{u'username': u'guoyr', u'name': u'Robert Guo', u'email': u'robert.guo@10gen.com'}

Message: SERVER-26503 fix incorrect uses of assert.throws()
Branch: master
https://github.com/mongodb/mongo/commit/32bd5fcc91071b45173d7fbbdb541f562c767f5f

Comment by Max Hirschhorn [ 12/Oct/16 ]

Reverted due to task failures that these changes were causing in Evergreen.

https://evergreen.mongodb.com/task/mongodb_mongo_master_enterprise_rhel_62_64_bit_jsCore_compatibility_1126f5411b19c87b3447ada413f11bfb0b466908_16_10_11_21_06_38

[js_test:fts_mix] 2016-10-11T22:01:53.058+0000 2016-10-11T22:01:53.058+0000 E QUERY    [main] Error: did not throw exception: undefined :
[js_test:fts_mix] 2016-10-11T22:01:53.058+0000 doassert@src/mongo/shell/assert.js:18:14
[js_test:fts_mix] 2016-10-11T22:01:53.058+0000 assert.throws@src/mongo/shell/assert.js:235:5
[js_test:fts_mix] 2016-10-11T22:01:53.058+0000 @jstests/core/fts_mix.js:123:1
[js_test:fts_mix] 2016-10-11T22:01:53.059+0000 failed to load: jstests/core/fts_mix.js

[js_test:fts_partition1] 2016-10-11T21:59:09.331+0000 2016-10-11T21:59:09.331+0000 E QUERY    [main] Error: did not throw exception: undefined :
[js_test:fts_partition1] 2016-10-11T21:59:09.332+0000 doassert@src/mongo/shell/assert.js:18:14
[js_test:fts_partition1] 2016-10-11T21:59:09.332+0000 assert.throws@src/mongo/shell/assert.js:235:5
[js_test:fts_partition1] 2016-10-11T21:59:09.332+0000 @jstests/core/fts_partition1.js:13:1
[js_test:fts_partition1] 2016-10-11T21:59:09.332+0000 failed to load: jstests/core/fts_partition1.js

The mongo shell will send a find as an OP_QUERY message on the collection when using the "legacy" read mode in the mongo shell, rather than as an OP_QUERY or OP_COMMAND message on the $cmd namespace (i.e. as a "find" command). An error is returned to the client as a single document from the cursor with a special $err field.

DBQuery.prototype.next = function() {
    ...
    var ret = this._cursor.next();
    if (ret.$err) {
        throw _getErrorWithCode(ret, "error: " + tojson(ret));
    }
    ...
};

We should instead assert that calling next() on the cursor throws an error. It may be useful to only do so when using "legacy" read mode to avoid masking an issue because the collection is empty.

https://evergreen.mongodb.com/task/mongodb_mongo_master_enterprise_rhel_62_64_bit_parallel_1126f5411b19c87b3447ada413f11bfb0b466908_16_10_11_21_06_38

[js_test:basic] 2016-10-11T22:11:32.478+0000 2016-10-11T22:11:32.477+0000 E QUERY    [thread3] [jstests/core/capped.js:4:1] TypeError: invalid assignment to const `t'
[js_test:basic] 2016-10-11T22:11:32.478+0000 Stack trace:
[js_test:basic] 2016-10-11T22:11:32.478+0000 @jstests/core/capped.js:4:1
[js_test:basic] 2016-10-11T22:11:32.478+0000 __parallelTests__fun/</time<@<unknown> line 6 > eval:19:17
[js_test:basic] 2016-10-11T22:11:32.478+0000 Date.timeFunc@src/mongo/shell/types.js:26:1
[js_test:basic] 2016-10-11T22:11:32.479+0000 __parallelTests__fun/<@<unknown> line 6 > eval:18:24
[js_test:basic] 2016-10-11T22:11:32.479+0000 __parallelTests__fun@<unknown> line 6 > eval:16:9
[js_test:basic] 2016-10-11T22:11:32.479+0000 @<unknown> line 6 > eval:231:44
[js_test:basic] 2016-10-11T22:11:32.479+0000 _threadStartWrapper@:24:16
[js_test:basic] 2016-10-11T22:11:32.479+0000 ----------
[js_test:basic] 2016-10-11T22:11:32.479+0000 
[js_test:basic] 2016-10-11T22:11:32.480+0000 ********** Parallel Test FAILED: Error: error loading js file: jstests/core/capped.js

The contents of the jstests/core/ord.js test likely needs to be wrapped in an IIFE to avoid declaring the variables t and c in the global scope.

Comment by Githook User [ 12/Oct/16 ]

Author:

{u'username': u'visemet', u'name': u'Max Hirschhorn', u'email': u'max.hirschhorn@mongodb.com'}

Message: Revert "SERVER-26503 fix incorrect uses of assert.throws()"

This reverts commit 1126f5411b19c87b3447ada413f11bfb0b466908.
Branch: master
https://github.com/mongodb/mongo/commit/350c0382b170c8cc97caddd586110fbd509543f1

Comment by Githook User [ 11/Oct/16 ]

Author:

{u'username': u'guoyr', u'name': u'Robert Guo', u'email': u'robert.guo@10gen.com'}

Message: SERVER-26503 fix incorrect uses of assert.throws()
Branch: master
https://github.com/mongodb/mongo/commit/1126f5411b19c87b3447ada413f11bfb0b466908

Generated at Thu Feb 08 04:12:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.