summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathisbessamdb <mathis.bessa@mongodb.com>2021-12-03 22:36:57 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-03 23:21:13 +0000
commitcc15ce960aa11edea964f4f8eee482649b59ee55 (patch)
tree0442cf9d8cc7dfc89cc4a915c2bdca09d404f695
parent32d5eaacb19f9730a70fea1e1627c2df2fe23265 (diff)
downloadmongo-cc15ce960aa11edea964f4f8eee482649b59ee55.tar.gz
SERVER-61698 adding support of adding and removing entries to config.tenants for serverlesstest
-rw-r--r--jstests/serverless/create_indexes_with_tenant_migration.js2
-rw-r--r--jstests/serverless/findAndModify_with_tenant_migration.js2
-rw-r--r--jstests/serverless/serverlesstest.js (renamed from jstests/serverless/serverless_test.js)34
-rw-r--r--jstests/serverless/serverlesstest_guide.js18
-rw-r--r--jstests/serverless/tenant_migration_concurrent_bulk_writes_against_mongoq.js2
-rw-r--r--jstests/serverless/tenant_migration_count_through_mongoq.js2
-rw-r--r--jstests/serverless/tenant_migration_recipient_bulkclone.js2
7 files changed, 47 insertions, 15 deletions
diff --git a/jstests/serverless/create_indexes_with_tenant_migration.js b/jstests/serverless/create_indexes_with_tenant_migration.js
index 8fde466408d..23fc22f7d8f 100644
--- a/jstests/serverless/create_indexes_with_tenant_migration.js
+++ b/jstests/serverless/create_indexes_with_tenant_migration.js
@@ -9,7 +9,7 @@
"use strict";
load("jstests/libs/fail_point_util.js");
-load("jstests/serverless/serverless_test.js");
+load("jstests/serverless/serverlesstest.js");
load('jstests/concurrency/fsm_libs/worker_thread.js');
// A function, not a constant, to ensure unique UUIDs.
diff --git a/jstests/serverless/findAndModify_with_tenant_migration.js b/jstests/serverless/findAndModify_with_tenant_migration.js
index 1011514576b..b414df1d96f 100644
--- a/jstests/serverless/findAndModify_with_tenant_migration.js
+++ b/jstests/serverless/findAndModify_with_tenant_migration.js
@@ -8,7 +8,7 @@
"use strict";
load("jstests/libs/fail_point_util.js");
-load("jstests/serverless/serverless_test.js");
+load("jstests/serverless/serverlesstest.js");
load('jstests/concurrency/fsm_libs/worker_thread.js');
function donorStartMigrationCmd(tenantID, realConnUrl) {
diff --git a/jstests/serverless/serverless_test.js b/jstests/serverless/serverlesstest.js
index d5e2d0981e3..dc78b848cdb 100644
--- a/jstests/serverless/serverless_test.js
+++ b/jstests/serverless/serverlesstest.js
@@ -21,16 +21,6 @@ class ServerlessTest {
this.configRS.stopSet();
};
- /**
- * Helper method for setting primary shard of a database and making sure that it was
- * successful. Note: first mongoq needs to be up.
- */
- this.ensurePrimaryShard = (dbName, shardName) => {
- var db = this.q.getDB('admin');
- var res = db.adminCommand({movePrimary: dbName, to: shardName});
- assert(res.ok || res.errmsg == "it is already the primary", tojson(res));
- };
-
jsTest.log("Going to create and start config server.");
this.configRS = new ReplSetTest({name: "configRS", nodes: 3, useHostName: true});
this.configRS.startSet({configsvr: '', journal: "", storageEngine: 'wiredTiger'});
@@ -69,4 +59,28 @@ class ServerlessTest {
this.q0 = this.q;
jsTest.log("DefaultServerlessTest is created.");
}
+
+ /**
+ * Helper method for setting primary shard of a database and making sure that it was
+ * successful. Note: first mongoq needs to be up.
+ */
+ ensurePrimaryShard(dbName, shardName) {
+ var db = this.q.getDB('admin');
+ var res = db.adminCommand({movePrimary: dbName, to: shardName});
+ assert(res.ok || res.errmsg == "it is already the primary", tojson(res));
+ }
+
+ addTenant(tenantId, shardId) {
+ return assert.commandWorked(
+ this.configRS.getPrimary()
+ .getCollection('config.tenants')
+ .insert({_id: tenantId, shardId: shardId}, {writeConcern: {w: "majority"}}));
+ }
+
+ removeTenant(tenantId) {
+ return assert.commandWorked(
+ this.configRS.getPrimary().getCollection('config.tenants').remove({_id: tenantId}, {
+ writeConcern: {w: "majority"}
+ }));
+ }
}
diff --git a/jstests/serverless/serverlesstest_guide.js b/jstests/serverless/serverlesstest_guide.js
new file mode 100644
index 00000000000..dfb064049b4
--- /dev/null
+++ b/jstests/serverless/serverlesstest_guide.js
@@ -0,0 +1,18 @@
+(function() {
+"use strict";
+
+load("jstests/serverless/serverlesstest.js");
+
+let st = new ServerlessTest();
+
+(() => {
+ jsTest.log("Test adding and removing tenants to/from config.tenants");
+ const tenantID = ObjectId();
+ assert.eq(0, st.removeTenant(tenantID.str, st.shard0.shardName).nRemoved);
+ assert.eq(1, st.addTenant(tenantID.str, st.shard0.shardName).nInserted);
+ assert.eq(1, st.removeTenant(tenantID.str, st.shard0.shardName).nRemoved);
+ assert.eq(0, st.removeTenant(tenantID.str, st.shard0.shardName).nRemoved);
+})();
+
+st.stop();
+})();
diff --git a/jstests/serverless/tenant_migration_concurrent_bulk_writes_against_mongoq.js b/jstests/serverless/tenant_migration_concurrent_bulk_writes_against_mongoq.js
index 212c9f1afc8..9e5a0fe2438 100644
--- a/jstests/serverless/tenant_migration_concurrent_bulk_writes_against_mongoq.js
+++ b/jstests/serverless/tenant_migration_concurrent_bulk_writes_against_mongoq.js
@@ -8,7 +8,7 @@
"use strict";
load("jstests/libs/fail_point_util.js");
-load("jstests/serverless/serverless_test.js");
+load("jstests/serverless/serverlesstest.js");
load('jstests/concurrency/fsm_libs/worker_thread.js');
function donorStartMigrationCmd(tenantID, realConnUrl) {
diff --git a/jstests/serverless/tenant_migration_count_through_mongoq.js b/jstests/serverless/tenant_migration_count_through_mongoq.js
index d64fae90022..ed8bb285533 100644
--- a/jstests/serverless/tenant_migration_count_through_mongoq.js
+++ b/jstests/serverless/tenant_migration_count_through_mongoq.js
@@ -8,7 +8,7 @@
"use strict";
load("jstests/libs/fail_point_util.js");
-load("jstests/serverless/serverless_test.js");
+load("jstests/serverless/serverlesstest.js");
function donorStartMigrationCmd(tenantID, realConnUrl) {
return {
diff --git a/jstests/serverless/tenant_migration_recipient_bulkclone.js b/jstests/serverless/tenant_migration_recipient_bulkclone.js
index fe01c5c3393..4f169110661 100644
--- a/jstests/serverless/tenant_migration_recipient_bulkclone.js
+++ b/jstests/serverless/tenant_migration_recipient_bulkclone.js
@@ -7,7 +7,7 @@
(function() {
"use strict";
-load("jstests/serverless/serverless_test.js");
+load("jstests/serverless/serverlesstest.js");
let st = new ServerlessTest();