Skip to content

Commit

Permalink
test(NODE-3187): port unified test runner (#2783)
Browse files Browse the repository at this point in the history
Adds typescript compilation for unified runner.
Modified package scripts to align with 4.0 branch.
CI steps needed to compile the runner.
Fixes to bulk result to conform to spec.
  • Loading branch information
nbbeeken committed May 17, 2021
1 parent 5d8f649 commit 1967515
Show file tree
Hide file tree
Showing 320 changed files with 14,377 additions and 1,627 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test/functional/unified-spec-runner/*.js
!test/functional/unified-spec-runner/unified-runner.test.js
docs
3 changes: 3 additions & 0 deletions .evergreen/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ if [[ "$OS" == "Windows_NT" ]]; then
root: $NVM_HOME
path: $NVM_SYMLINK
EOT
nvm install 12
nvm install $NODE_VERSION
nvm use $NODE_VERSION
which node || echo "node not found, PATH=$PATH"
Expand All @@ -86,7 +87,9 @@ EOT
else
curl -o- $NVM_URL | bash
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"
nvm install --no-progress 12
nvm install --no-progress $NODE_VERSION
nvm use $NODE_VERSION

# setup npm cache in a local directory
cat <<EOT > .npmrc
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/run-atlas-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

npm run atlas
npm run check:atlas
2 changes: 1 addition & 1 deletion .evergreen/run-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

npm run lint
npm run check:lint
8 changes: 6 additions & 2 deletions .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ set -o errexit # Exit the script with error if any of the commands fail
# UNIFIED Set to enable the Unified SDAM topology for the node driver
# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info)
# MARCH Machine Architecture. Defaults to lowercase uname -m
# TEST_NPM_SCRIPT Script to npm run. Defaults to "test-nolint"
# TEST_NPM_SCRIPT Script to npm run. Defaults to "check:test"
# SKIP_DEPS Skip installing dependencies
# NO_EXIT Don't exit early from tests that leak resources

AUTH=${AUTH:-noauth}
UNIFIED=${UNIFIED:-0}
MONGODB_URI=${MONGODB_URI:-}
TEST_NPM_SCRIPT=${TEST_NPM_SCRIPT:-test-nolint}
TEST_NPM_SCRIPT=${TEST_NPM_SCRIPT:-"check:test"}
if [[ -z "${NO_EXIT}" ]]; then
TEST_NPM_SCRIPT="$TEST_NPM_SCRIPT -- --exit"
fi
Expand Down Expand Up @@ -55,4 +55,8 @@ else
npm install mongodb-client-encryption@latest
fi

nvm use 12
npm run build:unified
nvm use "$NODE_VERSION"

MONGODB_UNIFIED_TOPOLOGY=${UNIFIED} MONGODB_URI=${MONGODB_URI} npm run ${TEST_NPM_SCRIPT}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ yarn.lock

.vscode
output

# Unified Runner
test/functional/unified-spec-runner/*.js
!test/functional/unified-spec-runner/unified-runner.test.js
68 changes: 68 additions & 0 deletions lib/bulk/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,45 @@ class BulkWriteResult {
this.result = bulkResult;
}

/** Number of documents inserted. */
get insertedCount() {
return typeof this.result.nInserted !== 'number' ? 0 : this.result.nInserted;
}
/** Number of documents matched for update. */
get matchedCount() {
return typeof this.result.nMatched !== 'number' ? 0 : this.result.nMatched;
}
/** Number of documents modified. */
get modifiedCount() {
return typeof this.result.nModified !== 'number' ? 0 : this.result.nModified;
}
/** Number of documents deleted. */
get deletedCount() {
return typeof this.result.nRemoved !== 'number' ? 0 : this.result.nRemoved;
}
/** Number of documents upserted. */
get upsertedCount() {
return !this.result.upserted ? 0 : this.result.upserted.length;
}

/** Upserted document generated Id's, hash key is the index of the originating operation */
get upsertedIds() {
const upserted = {};
for (const doc of !this.result.upserted ? [] : this.result.upserted) {
upserted[doc.index] = doc._id;
}
return upserted;
}

/** Inserted document generated Id's, hash key is the index of the originating operation */
get insertedIds() {
const inserted = {};
for (const doc of !this.result.insertedIds ? [] : this.result.insertedIds) {
inserted[doc.index] = doc._id;
}
return inserted;
}

/**
* Evaluates to true if the bulk operation correctly executes
* @type {boolean}
Expand Down Expand Up @@ -572,6 +611,35 @@ class BulkWriteError extends MongoError {
this.name = 'BulkWriteError';
this.result = result;
}

/** Number of documents inserted. */
get insertedCount() {
return this.result.insertedCount;
}
/** Number of documents matched for update. */
get matchedCount() {
return this.result.matchedCount;
}
/** Number of documents modified. */
get modifiedCount() {
return this.result.modifiedCount;
}
/** Number of documents deleted. */
get deletedCount() {
return this.result.deletedCount;
}
/** Number of documents upserted. */
get upsertedCount() {
return this.result.upsertedCount;
}
/** Inserted document generated Id's, hash key is the index of the originating operation */
get insertedIds() {
return this.result.insertedIds;
}
/** Upserted document generated Id's, hash key is the index of the originating operation */
get upsertedIds() {
return this.result.upsertedIds;
}
}

/**
Expand Down
Loading

0 comments on commit 1967515

Please sign in to comment.