mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
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:
parent
73683c048e
commit
fdd103b31b
@ -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"
|
||||
|
||||
|
@ -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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user