mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-21 12:39:08 +01:00
SERVER-80377 Use hashed jsTestName in multitenancy suites
This commit is contained in:
parent
41c0530618
commit
c8778bfa3b
@ -144,6 +144,7 @@ globals:
|
||||
_getEnv: true
|
||||
indentStr: true
|
||||
_forgetReplSet: true
|
||||
_fnvHashToHexString: true
|
||||
|
||||
# likely could be replaced with `path`
|
||||
_copyFileRange: true
|
||||
|
@ -13,6 +13,12 @@ f63255ee677ecae5896d6f35dd712ed60ae8c39a
|
||||
# SERVER-22470 Format JS code with approved style
|
||||
f5a6c794a0af1a5d57db2617c2e9464eaad9f221
|
||||
|
||||
# SERVER-22469 Format JS code with approved style in src/mongo/shell & src/mongo/scripting
|
||||
a025d43f3ce2efc1fb1282a718f5d286fa0a4dc1
|
||||
|
||||
# SERVER-22340 Fix JS lint errors in src/mongo/shell & src/mongo/scripting with ESLint --fix
|
||||
c3996780b76316793758b43fa1fca5b9d0857b6c
|
||||
|
||||
# SERVER-18579: Clang-Format - reformat code
|
||||
9c2ed42daa8fbbef4a919c21ec564e2db55e8d60
|
||||
|
||||
|
@ -65,6 +65,7 @@ executor:
|
||||
global_vars:
|
||||
TestData: &TestData
|
||||
tenantId: "636d957b2646ddfaf9b5e13f"
|
||||
hashTestNamesForMultitenancy: true
|
||||
hooks:
|
||||
- class: CheckReplOplogs
|
||||
- class: CheckReplDBHash
|
||||
|
@ -2,9 +2,10 @@
|
||||
* Test that a db does not exist after it is dropped.
|
||||
*
|
||||
* @tags: [
|
||||
* # listDatabases with explicit filter on db names doesn't work on tenant migrations suites
|
||||
* tenant_migration_incompatible,
|
||||
* ]
|
||||
* # listDatabases with explicit filter on db names doesn't work with the simulate_atlas_proxy
|
||||
* # override.
|
||||
* simulate_atlas_proxy_incompatible,
|
||||
* ]
|
||||
*/
|
||||
|
||||
function listDatabases(options) {
|
||||
@ -37,4 +38,4 @@ for (var i = 0; i < 3; i++) {
|
||||
}
|
||||
|
||||
assert.commandWorked(ddb.dropDatabase());
|
||||
assertDatabaseDoesNotExist(dbName);
|
||||
assertDatabaseDoesNotExist(dbName);
|
||||
|
@ -7,7 +7,7 @@ const conn = MongoRunner.runMongod(mongodOptions);
|
||||
assert.neq(null, conn, "mongod failed to start with options " + tojson(mongodOptions));
|
||||
|
||||
const testDB = conn.getDB("test");
|
||||
const coll = testDB[jsTest.name];
|
||||
const coll = testDB[jsTest.name()];
|
||||
coll.drop();
|
||||
|
||||
// Test that an aggregate is successful on a non-existent collection.
|
||||
@ -81,4 +81,4 @@ assert.commandWorked(
|
||||
assert.throws(() => cursor.itcount(), [], "expected getMore to fail");
|
||||
assertNumOpenCursors(0);
|
||||
|
||||
MongoRunner.stopMongod(conn);
|
||||
MongoRunner.stopMongod(conn);
|
||||
|
@ -728,6 +728,33 @@ BSONObj _buildBsonObj(const BSONObj& args, void*) {
|
||||
return BSON("" << builder.obj());
|
||||
}
|
||||
|
||||
/*
|
||||
* The following code has been updated to remove unnecessary content and better comply
|
||||
* with MongoDB coding standards. The original source code can be found at:
|
||||
* FNV 1a 64 bit: http://www.isthe.com/chongo/src/fnv/hash_64a.c
|
||||
*/
|
||||
#define FNV1A_64_INIT ((uint64_t)0xcbf29ce484222325ULL)
|
||||
static inline uint64_t fnv_64a_buf(const void* buf, size_t len, uint64_t hval) {
|
||||
const unsigned char* bp = (const unsigned char*)buf; /* start of buffer */
|
||||
const unsigned char* be = bp + len; /* beyond end of buffer */
|
||||
while (bp < be) {
|
||||
hval ^= (uint64_t)*bp++;
|
||||
hval += (hval << 1) + (hval << 4) + (hval << 5) + (hval << 7) + (hval << 8) + (hval << 40);
|
||||
}
|
||||
|
||||
return (hval);
|
||||
}
|
||||
|
||||
BSONObj _fnvHashToHexString(const BSONObj& args, void*) {
|
||||
uassert(8423397,
|
||||
"_fnvHashToHexString expects one string argument",
|
||||
args.nFields() == 1 && args.firstElement().type() == String);
|
||||
|
||||
auto input = args.firstElement().str();
|
||||
auto hashed = fnv_64a_buf(input.c_str(), input.size(), FNV1A_64_INIT);
|
||||
return BSON("" << fmt::format("{0:x}", hashed));
|
||||
}
|
||||
|
||||
void installShellUtils(Scope& scope) {
|
||||
scope.injectNative("getMemInfo", JSGetMemInfo);
|
||||
scope.injectNative("_createSecurityToken", _createSecurityToken);
|
||||
@ -748,6 +775,7 @@ void installShellUtils(Scope& scope) {
|
||||
scope.injectNative("_writeGoldenData", _writeGoldenData);
|
||||
scope.injectNative("_closeGoldenData", _closeGoldenData);
|
||||
scope.injectNative("_buildBsonObj", _buildBsonObj);
|
||||
scope.injectNative("_fnvHashToHexString", _fnvHashToHexString);
|
||||
|
||||
installShellUtilsLauncher(scope);
|
||||
installShellUtilsExtended(scope);
|
||||
|
@ -357,8 +357,17 @@ function _isUndefinedBehaviorSanitizerActive() {
|
||||
}
|
||||
|
||||
jsTestName = function() {
|
||||
if (TestData)
|
||||
if (TestData) {
|
||||
// If we are using the jsTestName as a database name and performing tenant prefixing
|
||||
// then it's possible that the prefixed database name will exceed the server's dbName
|
||||
// length. In these cases, hashing the test name improves our chances of success. FNV-1a
|
||||
// hashes are maximum 16 characters, so don't hash dbNames that are up to 16 characters.
|
||||
if (TestData.testName.length > 16 && TestData.hashTestNamesForMultitenancy) {
|
||||
return _fnvHashToHexString(TestData.testName);
|
||||
}
|
||||
return TestData.testName;
|
||||
}
|
||||
|
||||
return "__unknown_name__";
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user