configparser: avoid environment race in configparser tests

Summary:
The configparser tests `hg::tests::test_basic_hgplain` and
`hg::tests::test_hgplainexcept` set different values for `HGPLAIN` and
`HGPLAINEXCEPT`.  Since the tests run in parallel and use the same environment,
one of the tests may fail if they run at the same time.

For these tests, create a mutex for the environment and lock it for the
duration of the test, ensuring these tests do not interfere with each other.

Reviewed By: jsgf

Differential Revision: D14615394

fbshipit-source-id: 9f123668d93223655514db2ae34b05354a6b578c
This commit is contained in:
Mark Thomas 2019-03-26 07:30:25 -07:00 committed by Facebook Github Bot
parent 73683c048e
commit fdd103b31b
2 changed files with 12 additions and 0 deletions

View File

@ -14,6 +14,7 @@ pest_derive = "2.1.0"
shellexpand = "1.0.0"
[dev-dependencies]
lazy_static = "1.3.0"
minibench = { path = "../minibench" }
tempdir = "0.3.7"

View File

@ -514,8 +514,18 @@ mod tests {
use crate::config::tests::write_file;
use lazy_static::lazy_static;
use std::sync::Mutex;
lazy_static! {
/// Lock for the environment. This should be acquired by tests that rely on particular
/// environment variable values that might be overwritten by other tests.
static ref ENV_LOCK: Mutex<()> = Mutex::new(());
}
#[test]
fn test_basic_hgplain() {
let _guard = ENV_LOCK.lock().unwrap();
env::set_var(HGPLAIN, "1");
env::remove_var(HGPLAINEXCEPT);
@ -540,6 +550,7 @@ mod tests {
#[test]
fn test_hgplainexcept() {
let _guard = ENV_LOCK.lock().unwrap();
env::remove_var(HGPLAIN);
env::set_var(HGPLAINEXCEPT, "alias,revsetalias");