summaryrefslogtreecommitdiff
path: root/jstests/parallel
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2018-09-18 21:10:36 -0400
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2018-09-18 21:10:36 -0400
commitf43ea7a6bb2a6c44f91506c32004241d3cbb24ae (patch)
tree1dff1f481a3439045f0de84a242e1ac33f201249 /jstests/parallel
parent78112be586c67efa877636d596b194650e90cbed (diff)
downloadmongo-f43ea7a6bb2a6c44f91506c32004241d3cbb24ae.tar.gz
SERVER-35154 Propagate JS exceptions through ScopedThread#join().
This makes it so that if the ScopedThread exited due to an uncaught JavaScript exception, then calling .join() or .returnData() on it throws a JavaScript exception with the error message and stacktrace intact.
Diffstat (limited to 'jstests/parallel')
-rw-r--r--jstests/parallel/del.js111
1 files changed, 71 insertions, 40 deletions
diff --git a/jstests/parallel/del.js b/jstests/parallel/del.js
index 3128f89d05e..903bb983d1f 100644
--- a/jstests/parallel/del.js
+++ b/jstests/parallel/del.js
@@ -8,54 +8,84 @@ b = db.getSisterDB("foob");
a.dropDatabase();
b.dropDatabase();
-function del1(dbname, host, max) {
- var m = new Mongo(host);
- var db = m.getDB("foo" + dbname);
- var t = db.del;
-
- while (!db.del_parallel.count()) {
- var r = Math.random();
- var n = Math.floor(Math.random() * max);
- if (r < .9) {
- t.insert({x: n});
- } else if (r < .98) {
- t.remove({x: n});
- } else if (r < .99) {
- t.remove({x: {$lt: n}});
- } else {
- t.remove({x: {$gt: n}});
+var kCursorKilledErrorCodes = [
+ ErrorCodes.OperationFailed,
+ ErrorCodes.QueryPlanKilled,
+ ErrorCodes.CursorNotFound,
+];
+
+function del1(dbname, host, max, kCursorKilledErrorCodes) {
+ try {
+ var m = new Mongo(host);
+ var db = m.getDB("foo" + dbname);
+ var t = db.del;
+
+ while (!db.del_parallel.count()) {
+ var r = Math.random();
+ var n = Math.floor(Math.random() * max);
+ if (r < .9) {
+ t.insert({x: n});
+ } else if (r < .98) {
+ t.remove({x: n});
+ } else if (r < .99) {
+ t.remove({x: {$lt: n}});
+ } else {
+ t.remove({x: {$gt: n}});
+ }
+ if (r > .9999)
+ print(t.count());
+ }
+
+ return {ok: 1};
+ } catch (e) {
+ if (kCursorKilledErrorCodes.includes(e.code)) {
+ // It is expected that the cursor may have been killed due to the database being
+ // dropped concurrently.
+ return {ok: 1};
}
- if (r > .9999)
- print(t.count());
+
+ throw e;
}
}
-function del2(dbname, host, max) {
- var m = new Mongo(host);
- var db = m.getDB("foo" + dbname);
- var t = db.del;
-
- while (!db.del_parallel.count()) {
- var r = Math.random();
- var n = Math.floor(Math.random() * max);
- var s = Math.random() > .5 ? 1 : -1;
-
- if (r < .5) {
- t.findOne({x: n});
- } else if (r < .75) {
- t.find({x: {$lt: n}}).sort({x: s}).itcount();
- } else {
- t.find({x: {$gt: n}}).sort({x: s}).itcount();
+function del2(dbname, host, max, kCursorKilledErrorCodes) {
+ try {
+ var m = new Mongo(host);
+ var db = m.getDB("foo" + dbname);
+ var t = db.del;
+
+ while (!db.del_parallel.count()) {
+ var r = Math.random();
+ var n = Math.floor(Math.random() * max);
+ var s = Math.random() > .5 ? 1 : -1;
+
+ if (r < .5) {
+ t.findOne({x: n});
+ } else if (r < .75) {
+ t.find({x: {$lt: n}}).sort({x: s}).itcount();
+ } else {
+ t.find({x: {$gt: n}}).sort({x: s}).itcount();
+ }
+ }
+
+ return {ok: 1};
+ } catch (e) {
+ if (kCursorKilledErrorCodes.includes(e.code)) {
+ // It is expected that the cursor may have been killed due to the database being
+ // dropped concurrently.
+ return {ok: 1};
}
+
+ throw e;
}
}
all = [];
-all.push(fork(del1, "a", HOST, N));
-all.push(fork(del2, "a", HOST, N));
-all.push(fork(del1, "b", HOST, N));
-all.push(fork(del2, "b", HOST, N));
+all.push(fork(del1, "a", HOST, N, kCursorKilledErrorCodes));
+all.push(fork(del2, "a", HOST, N, kCursorKilledErrorCodes));
+all.push(fork(del1, "b", HOST, N, kCursorKilledErrorCodes));
+all.push(fork(del2, "b", HOST, N, kCursorKilledErrorCodes));
for (i = 0; i < all.length; i++)
all[i].start();
@@ -70,5 +100,6 @@ for (i = 0; i < 10; i++) {
a.del_parallel.save({done: 1});
b.del_parallel.save({done: 1});
-for (i = 0; i < all.length; i++)
- all[i].join();
+for (i = 0; i < all.length; i++) {
+ assert.commandWorked(all[i].returnData());
+}