diff options
author | rsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-08 17:45:44 +0000 |
---|---|---|
committer | rsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-08 17:45:44 +0000 |
commit | 90c5f4777fc3a4c90ef7c1783d7cfee4f7a2cff3 (patch) | |
tree | 366f85bb78d4180934116927958932f1cbf30204 /net/test | |
parent | e6ff9116ad6375e83aac9c0d1447cf7122caee28 (diff) | |
download | chromium_src-90c5f4777fc3a4c90ef7c1783d7cfee4f7a2cff3.zip chromium_src-90c5f4777fc3a4c90ef7c1783d7cfee4f7a2cff3.tar.gz chromium_src-90c5f4777fc3a4c90ef7c1783d7cfee4f7a2cff3.tar.bz2 |
Force python test server output to be unbuffered, so it doesn't mix with gtest output
In browser tests that use a local python server, the python output in the test logs sometimes overlaps with gtest output, resulting in gtest falsely detecting passing tests as incomplete. This is a result of python's default use of buffered output, which gets written to the log file out of order.
This patch forces the python process for local test servers to use unbuffered mode. This way, by the time gtest is ready to log a passing test, all testserver output is already written to the log file.
BUG=147368
TEST= See sync integration test output when it is redirected to a log file, and make sure there are no false negatives.
Review URL: https://chromiumcodereview.appspot.com/10919165
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155587 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/test')
-rw-r--r-- | net/test/local_test_server.cc | 4 | ||||
-rw-r--r-- | net/test/python_utils.cc | 8 | ||||
-rw-r--r-- | net/test/python_utils.h | 8 |
3 files changed, 20 insertions, 0 deletions
diff --git a/net/test/local_test_server.cc b/net/test/local_test_server.cc index af94a50..8bddbc3a 100644 --- a/net/test/local_test_server.cc +++ b/net/test/local_test_server.cc @@ -105,6 +105,10 @@ bool LocalTestServer::Start() { if (!SetPythonPath()) return false; + // Ensures that python testserver output, if any, will not clash with + // post-test gtest output. + EnablePythonUnbufferedMode(); + if (!LaunchPython(testserver_path)) return false; diff --git a/net/test/python_utils.cc b/net/test/python_utils.cc index 0eec816..7e0e79a 100644 --- a/net/test/python_utils.cc +++ b/net/test/python_utils.cc @@ -14,6 +14,7 @@ #include "base/utf_string_conversions.h" const char kPythonPathEnv[] = "PYTHONPATH"; +const char kPythonUnbufferedEnv[] = "PYTHONUNBUFFERED"; void AppendToPythonPath(const FilePath& dir) { scoped_ptr<base::Environment> env(base::Environment::Create()); @@ -115,3 +116,10 @@ bool GetPythonRunTime(FilePath* dir) { #endif return true; } + +void EnablePythonUnbufferedMode() { + // Python output will be unbuffered if kPythonUnbufferedEnv is set to any + // non-empty string. + scoped_ptr<base::Environment> env(base::Environment::Create()); + env->SetVar(kPythonUnbufferedEnv, "true"); +} diff --git a/net/test/python_utils.h b/net/test/python_utils.h index 583fb27..377a3ec 100644 --- a/net/test/python_utils.h +++ b/net/test/python_utils.h @@ -12,6 +12,9 @@ class FilePath; // This is the python path variable name. extern const char kPythonPathEnv[]; +// This is the python unbuffered variable name. +extern const char kPythonUnbufferedEnv[]; + // Appends the dir to python path environment variable. void AppendToPythonPath(const FilePath& dir); @@ -21,4 +24,9 @@ bool GetPyProtoPath(FilePath* dir); // Returns the path that should be used to launch Python. bool GetPythonRunTime(FilePath* path) WARN_UNUSED_RESULT; +// Sets the environment variable that forces python console output to be +// unbuffered. Used so that buffered logs don't interfere with gtest logs after +// a test has been run. +void EnablePythonUnbufferedMode(); + #endif // NET_TEST_PYTHON_UTILS_H_ |