Skip to content

Commit

Permalink
TIG-1334 Fix segfault in test_gennylib_with_server (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaimano authored Jan 8, 2019
1 parent 660073d commit cff7571
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 51 deletions.
43 changes: 6 additions & 37 deletions evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,46 +244,15 @@ functions:
# Requires f_compile to have been run first.
##
f_resmoke_test:
- command: shell.exec
- command: subprocess.exec
params:
continue_on_err: true
working_dir: src
script: |
set -o errexit
set -o pipefail
# set -o nounset # the "activate" script has an unbound variable
source build/venv/bin/activate
# We rely on catch2 to report test failures, but it doesn't always do so.
# See https://github.com/catchorg/Catch2/issues/1210
# As a workaround, we generate a dummy report with a failed test that is deleted if resmoke
# succeeds.
cat << EOF >> "build/sentinel.junit.xml"
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="resmoke_failure_sentinel" errors="0" failures="1" tests="1" hostname="tbd" time="1.0" timestamp="2019-01-01T00:00:00Z">
<testcase classname="resmoke_failure_sentinel" name="Dummy testcase to signal that resmoke failed because a report may not be generated" time="1.0">
<failure message="resmoke did not exit cleanly, see task log for detail" type="">
</failure>
</testcase>
<system-out/>
<system-err/>
</testsuite>
</testsuites>
EOF
# The tests themselves do the reporting instead of using resmoke.
python build/mongo/buildscripts/resmoke.py \
--suite src/resmokeconfig/${resmoke_suite} \
--mongod mongod \
--mongo mongo \
--mongos mongos
# Remove the sentinel report if resmoke succeeds. This line won't be executed if
# resmoke fails because we've set errexit on this shell.
rm build/sentinel.junit.xml
binary: /bin/bash
args:
- ${workdir}/src/scripts/run-resmoke.sh
env:
RESMOKE_SUITE: ${resmoke_suite}

##
# Runs python nosetests.
Expand Down
55 changes: 55 additions & 0 deletions scripts/run-resmoke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

set -o errexit
set -o pipefail
# set -o nounset # the "activate" script has an unbound variable

SCRIPTS_DIR="$(dirname "${BASH_SOURCE[0]}")"
ROOT_DIR="$(cd "${SCRIPTS_DIR}/.." && pwd)"
BUILD_DIR="${ROOT_DIR}/build"

VENV_DIR="${VENV_DIR:-${BUILD_DIR}/venv}"
MONGO_DIR="${MONGO_DIR:-${BUILD_DIR}/mongo}"
RESMOKE_SUITE="${RESMOKE_SUITE:-genny_standalone.yml}"
SENTINEL_XML="${BUILD_DIR}/sentinel.junit.xml"

if [[ -z $VIRTUAL_ENV ]]; then
# shellcheck disable=SC1090
. "${VENV_DIR}/bin/activate"
fi

# Move to the root dir because of how resmoke paths
cd "${ROOT_DIR}"

# We rely on catch2 to report test failures, but it doesn't always do so.
# See https://github.com/catchorg/Catch2/issues/1210
# As a workaround, we generate a dummy report with a failed test that is deleted if resmoke
# succeeds.

cat << EOF >> "${SENTINEL_XML}"
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="resmoke_failure_sentinel" errors="0" failures="1" tests="1" hostname="tbd" time="1.0" timestamp="2019-01-01T00:00:00Z">
<testcase classname="resmoke_failure_sentinel" name="Dummy testcase to signal that resmoke failed because a report may not be generated" time="1.0">
<failure message="resmoke did not exit cleanly, see task log for detail" type="">
</failure>
</testcase>
<system-out/>
<system-err/>
</testsuite>
</testsuites>
EOF

# Add the mongo dir to the end of the path so we can find mongo executables
export PATH="${PATH}:${MONGO_DIR}"

# The tests themselves do the reporting instead of using resmoke.
python2 "${MONGO_DIR}/buildscripts/resmoke.py" \
--suite "${ROOT_DIR}/src/resmokeconfig/${RESMOKE_SUITE}" \
--mongod mongod \
--mongo mongo \
--mongos mongos

# Remove the sentinel report if resmoke succeeds. This line won't be executed if
# resmoke fails because we've set errexit on this shell.
rm "${SENTINEL_XML}"
18 changes: 8 additions & 10 deletions src/gennylib/test/MongoTestFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@

namespace genny::testing {

const mongocxx::uri MongoTestFixture::kConnectionString = []() {
mongocxx::uri MongoTestFixture::connectionUri() {
const char* connChar = getenv("MONGO_CONNECTION_STRING");
std::string connStr;

if (!connChar) {
connStr = mongocxx::uri::k_default_uri;
BOOST_LOG_TRIVIAL(info) << "MONGO_CONNECTION_STRING not set, using default value: "
<< connStr;
} else {
connStr = connChar;

if (connChar != nullptr) {
return mongocxx::uri(connChar);
}

auto& connStr = mongocxx::uri::k_default_uri;
BOOST_LOG_TRIVIAL(info) << "MONGO_CONNECTION_STRING not set, using default value: " << connStr;
return mongocxx::uri(connStr);
}();
};

void MongoTestFixture::dropAllDatabases() {
for (auto&& dbDoc : client.list_databases()) {
Expand All @@ -33,4 +30,5 @@ void MongoTestFixture::dropAllDatabases() {
}
}
}

} // namespace genny::testing
6 changes: 4 additions & 2 deletions src/gennylib/test/MongoTestFixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
#define HEADER_D9091084_CB09_4108_A553_5D0EC18C132F_INCLUDED

#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>

namespace genny::testing {

class MongoTestFixture {
public:
MongoTestFixture() : client(kConnectionString) {}
MongoTestFixture() : instance(mongocxx::instance::current()), client(connectionUri()) {}

protected:
void dropAllDatabases();

mongocxx::instance & instance;
mongocxx::client client;

static const mongocxx::uri kConnectionString;
static mongocxx::uri connectionUri();
};
} // namespace genny::testing

Expand Down
5 changes: 3 additions & 2 deletions src/gennylib/test/RunCommandActor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>

#include <MongoTestFixture.hpp>
#include <cast_core/actors/RunCommand.hpp>
#include <gennylib/MongoException.hpp>

#include "MongoTestFixture.hpp"

namespace genny {
namespace {

Expand All @@ -35,7 +36,7 @@ TEST_CASE_METHOD(MongoTestFixture,
OperationCommand: {someKey: 1}
)");

ActorHelper ah(config, 1, MongoTestFixture::kConnectionString.to_string());
ActorHelper ah(config, 1, MongoTestFixture::connectionUri().to_string());

SECTION("throws error with full context on operation_exception") {
bool has_exception = true;
Expand Down

0 comments on commit cff7571

Please sign in to comment.