summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authorKevin Cherkauer <kevin.cherkauer@mongodb.com>2022-12-13 17:04:36 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-12-13 18:01:24 +0000
commitdd42ea7c86b637f683b058bdd4d52e17904a3502 (patch)
treed0141b44e298e893724e05146f7adb0827280f3a /src/mongo/shell
parent21a03e441d6c36265d0b35d2ac80a9202665262b (diff)
downloadmongo-dd42ea7c86b637f683b058bdd4d52e17904a3502.tar.gz
SERVER-72059 Named Pipes _writeTestPipeBsonFileSync() test shell func
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/named_pipe_test_helper.h18
-rw-r--r--src/mongo/shell/shell_utils_launcher.cpp34
2 files changed, 39 insertions, 13 deletions
diff --git a/src/mongo/shell/named_pipe_test_helper.h b/src/mongo/shell/named_pipe_test_helper.h
index 81f14751dd1..1d3c9f87499 100644
--- a/src/mongo/shell/named_pipe_test_helper.h
+++ b/src/mongo/shell/named_pipe_test_helper.h
@@ -40,11 +40,20 @@ namespace mongo {
class NamedPipeHelper {
public:
static BSONObj readFromPipes(const std::vector<std::string>& pipeRelativePaths);
+ static void writeToPipe(std::string pipeDir,
+ std::string pipeRelativePath,
+ long objects,
+ long stringMinSize,
+ long stringMaxSize) noexcept;
static void writeToPipeAsync(std::string pipeDir,
std::string pipeRelativePath,
long objects,
long stringMinSize,
long stringMaxSize);
+ static void writeToPipeObjects(std::string pipeDir,
+ std::string pipeRelativePath,
+ long objects,
+ std::vector<BSONObj> bsonObjs) noexcept;
static void writeToPipeObjectsAsync(std::string pipeDir,
std::string pipeRelativePath,
long objects,
@@ -52,14 +61,5 @@ public:
private:
static std::string getString(int length);
- static void writeToPipe(std::string pipeDir,
- std::string pipeRelativePath,
- long objects,
- long stringMinSize,
- long stringMaxSize) noexcept;
- static void writeToPipeObjects(std::string pipeDir,
- std::string pipeRelativePath,
- long objects,
- std::vector<BSONObj> bsonObjs) noexcept;
};
} // namespace mongo
diff --git a/src/mongo/shell/shell_utils_launcher.cpp b/src/mongo/shell/shell_utils_launcher.cpp
index 75d7682c155..456039eba7a 100644
--- a/src/mongo/shell/shell_utils_launcher.cpp
+++ b/src/mongo/shell/shell_utils_launcher.cpp
@@ -1383,13 +1383,17 @@ int32_t readBytes(char* buf, int32_t count, std::ifstream& ifs) {
* Writes a test named pipe of BSONobj's that are first read into memory from a BSON file, then
* round-robinned into the pipe up to the requested number of objects. This is the same as function
* WriteTestPipeObjects except the objects are read from a file instead of passed in as a BSONArray.
+ *
+ * args:
* "0": string; relative path of the pipe
* "1": number; number of BSON objects to write to the pipe
* "2": string; relative path to the file of BSON objects; these must fit in memory
* "3": OPTIONAL string; absolute path to the directory where named pipes exist. If not given,
* 'kDefaultPipePath' is used.
+ *
+ * async: true, write asynchronously; false, write synchronously
*/
-BSONObj WriteTestPipeBsonFile(const BSONObj& args, void* unused) {
+BSONObj writeTestPipeBsonFileHelper(const BSONObj& args, bool async) {
int nFields = args.nFields();
uassert(ErrorCodes::FailedToParse,
"Function requires 3 or 4 arguments but {} were given"_format(nFields),
@@ -1461,14 +1465,35 @@ BSONObj WriteTestPipeBsonFile(const BSONObj& args, void* unused) {
}
} // while !eof
- // Write the pipe asynchronously.
- NamedPipeHelper::writeToPipeObjectsAsync(
- std::move(pipeDir), pipePathElem.str(), objectsElem.numberLong(), bsonObjs);
+ // Write the pipe.
+ if (async) {
+ NamedPipeHelper::writeToPipeObjectsAsync(
+ std::move(pipeDir), pipePathElem.str(), objectsElem.numberLong(), std::move(bsonObjs));
+ } else {
+ NamedPipeHelper::writeToPipeObjects(
+ std::move(pipeDir), pipePathElem.str(), objectsElem.numberLong(), std::move(bsonObjs));
+ }
return {};
}
/**
+ * Asynchronously writes a test named pipe of BSONobj's that are first read into memory from a BSON
+ * file. See writeTestPipeBsonFileHelper() header for more info.
+ */
+BSONObj WriteTestPipeBsonFile(const BSONObj& args, void* unused) {
+ return writeTestPipeBsonFileHelper(args, true);
+}
+
+/**
+ * Synchronously writes a test named pipe of BSONobj's that are first read into memory from a BSON
+ * file. See writeTestPipeBsonFileHelper() header for more info.
+ */
+BSONObj WriteTestPipeBsonFileSync(const BSONObj& args, void* unused) {
+ return writeTestPipeBsonFileHelper(args, false);
+}
+
+/**
* Writes a test named pipe by round-robinning caller-provided objects to the pipe. 'args' BSONObj
* should contain fields:
* "0": string; relative path of the pipe
@@ -1612,6 +1637,7 @@ void installShellUtilsLauncher(Scope& scope) {
scope.injectNative("_readTestPipes", ReadTestPipes);
scope.injectNative("_writeTestPipe", WriteTestPipe);
scope.injectNative("_writeTestPipeBsonFile", WriteTestPipeBsonFile);
+ scope.injectNative("_writeTestPipeBsonFileSync", WriteTestPipeBsonFileSync);
scope.injectNative("_writeTestPipeObjects", WriteTestPipeObjects);
}
} // namespace shell_utils