Skip to content

Commit

Permalink
✅ Remove environment variables that are likely to be different across…
Browse files Browse the repository at this point in the history
… runs

The tests failed because we now print all environment variables, and the
`hostname` changes between runs. So comparing the output with the known good
output always fails. We strip out variables that are likely to change over
time (hostname, conda version...) to make this test more robust.

1. We technically only need the hostname right now, but will add the conda
version as well so that we don't get spurious failures when the versions
change
2. this was not an issue earlier because we read the values from the config
file. We now read environment variables, but that brings in variables that we
did not set. So this is a new issue that we need to resolve by stripping them
out for the baseline comparison.

```
$ ./e-mission-py.bash emission/tests/storageTests/TestTokenQueries.py
----------------------------------------------------------------------
Ran 21 tests in 23.591s

OK
```
  • Loading branch information
shankari committed Aug 12, 2024
1 parent b6f59b0 commit ec38835
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions emission/tests/storageTests/TestTokenQueries.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,34 @@ def test_run_script_show(self):
sp = subprocess.run(["python3", "bin/auth/insert_tokens.py", "--show"], capture_output=True)
# The first message is displayed when we run tests locally
# The second is displayed when we run in the docker CI, since the `DB_HOST` is set to `db`
self.assertIn(sp.stdout,
stripped_out_stdout = sp.stdout\
.replace(b"\'CONDA_EXE\': \'/root/miniconda-23.5.2/bin/conda\', ",b"")\
.replace(b"\'HOSTNAME\': \'78346225cfef\', ",b"")\
.replace(b"\'EXP_CONDA_VER\': \'23.5.2\', ",b"")\
.replace(b"\'CONDA_PREFIX\': \'/root/miniconda-23.5.2/envs/emissiontest\', ",b"")\
.replace(b"\'CONDA_PYTHON_EXE\': \'/root/miniconda-23.5.2/bin/python\', ",b"")\
.replace(b"\'PATH\': \'/root/miniconda-23.5.2/envs/emissiontest/bin:/root/miniconda-23.5.2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\', ",b"")\
.replace(b"\'_\': \'/root/miniconda-23.5.2/envs/emissiontest/bin/python\'",b"")
self.assertIn(stripped_out_stdout,
[b'Retrieved config {\'DB_HOST\': \'localhost\', \'DB_RESULT_LIMIT\': 250000}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL localhost\nx\ny\nz\n',
b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'PYTHONPATH\': \'.\', \'CONDA_EXE\': \'/root/miniconda-23.5.2/bin/conda\', \'_CE_M\': \'\', \'HOSTNAME\': \'a846a70e9205\', \'EXP_CONDA_VER\': \'23.5.2\', \'PWD\': \'/src/e-mission-server\', \'CONDA_PREFIX\': \'/root/miniconda-23.5.2/envs/emissiontest\', \'WEB_SERVER_HOST\': \'0.0.0.0\', \'HOME\': \'/root\', \'CONDA_PROMPT_MODIFIER\': \'(emissiontest) \', \'_CE_CONDA\': \'\', \'DB_HOST\': \'db\', \'CONDA_SHLVL\': \'1\', \'SHLVL\': \'2\', \'CONDA_PYTHON_EXE\': \'/root/miniconda-23.5.2/bin/python\', \'CONDA_DEFAULT_ENV\': \'emissiontest\', \'PATH\': \'/root/miniconda-23.5.2/envs/emissiontest/bin:/root/miniconda-23.5.2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\', \'EXP_CONDA_VER_SUFFIX\': \'0\', \'OLDPWD\': \'/\', \'_\': \'/root/miniconda-23.5.2/envs/emissiontest/bin/python\', \'LC_CTYPE\': \'C.UTF-8\', \'KMP_DUPLICATE_LIB_OK\': \'True\', \'KMP_INIT_AT_FORK\': \'FALSE\'}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nx\ny\nz\n'
b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'PYTHONPATH\': \'.\', \'_CE_M\': \'\', \'PWD\': \'/src/e-mission-server\', \'WEB_SERVER_HOST\': \'0.0.0.0\', \'HOME\': \'/root\', \'CONDA_PROMPT_MODIFIER\': \'(emissiontest) \', \'_CE_CONDA\': \'\', \'DB_HOST\': \'db\', \'CONDA_SHLVL\': \'1\', \'SHLVL\': \'2\', \'CONDA_DEFAULT_ENV\': \'emissiontest\', \'EXP_CONDA_VER_SUFFIX\': \'0\', \'OLDPWD\': \'/\', \'LC_CTYPE\': \'C.UTF-8\', \'KMP_DUPLICATE_LIB_OK\': \'True\', \'KMP_INIT_AT_FORK\': \'FALSE\'}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nx\ny\nz\n'
])

def test_run_script_empty(self):
sp = subprocess.run(["python3", "bin/auth/insert_tokens.py"], capture_output=True)
# The first message is displayed when we run tests locally
# The second is displayed when we run in the docker CI, since the `DB_HOST` is set to `db`
self.assertIn(sp.stdout,
stripped_out_stdout = sp.stdout\
.replace(b"\'CONDA_EXE\': \'/root/miniconda-23.5.2/bin/conda\', ",b"")\
.replace(b"\'HOSTNAME\': \'78346225cfef\', ",b"")\
.replace(b"\'EXP_CONDA_VER\': \'23.5.2\', ",b"")\
.replace(b"\'CONDA_PREFIX\': \'/root/miniconda-23.5.2/envs/emissiontest\', ",b"")\
.replace(b"\'CONDA_PYTHON_EXE\': \'/root/miniconda-23.5.2/bin/python\', ",b"")\
.replace(b"\'PATH\': \'/root/miniconda-23.5.2/envs/emissiontest/bin:/root/miniconda-23.5.2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\', ",b"")\
.replace(b"\'_\': \'/root/miniconda-23.5.2/envs/emissiontest/bin/python\'",b"")
self.assertIn(stripped_out_stdout,
[b'Retrieved config {\'DB_HOST\': \'localhost\', \'DB_RESULT_LIMIT\': 250000}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL localhost\nPlease provide the script with an argument. Use the "--help" option for more details\n',
b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'PYTHONPATH\': \'.\', \'CONDA_EXE\': \'/root/miniconda-23.5.2/bin/conda\', \'_CE_M\': \'\', \'HOSTNAME\': \'a846a70e9205\', \'EXP_CONDA_VER\': \'23.5.2\', \'PWD\': \'/src/e-mission-server\', \'CONDA_PREFIX\': \'/root/miniconda-23.5.2/envs/emissiontest\', \'WEB_SERVER_HOST\': \'0.0.0.0\', \'HOME\': \'/root\', \'CONDA_PROMPT_MODIFIER\': \'(emissiontest) \', \'_CE_CONDA\': \'\', \'DB_HOST\': \'db\', \'CONDA_SHLVL\': \'1\', \'SHLVL\': \'2\', \'CONDA_PYTHON_EXE\': \'/root/miniconda-23.5.2/bin/python\', \'CONDA_DEFAULT_ENV\': \'emissiontest\', \'PATH\': \'/root/miniconda-23.5.2/envs/emissiontest/bin:/root/miniconda-23.5.2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\', \'EXP_CONDA_VER_SUFFIX\': \'0\', \'OLDPWD\': \'/\', \'_\': \'/root/miniconda-23.5.2/envs/emissiontest/bin/python\', \'LC_CTYPE\': \'C.UTF-8\', \'KMP_DUPLICATE_LIB_OK\': \'True\', \'KMP_INIT_AT_FORK\': \'FALSE\'}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nPlease provide the script with an argument. Use the "--help" option for more details\n'
b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'PYTHONPATH\': \'.\', \'_CE_M\': \'\', \'PWD\': \'/src/e-mission-server\', \'WEB_SERVER_HOST\': \'0.0.0.0\', \'HOME\': \'/root\', \'CONDA_PROMPT_MODIFIER\': \'(emissiontest) \', \'_CE_CONDA\': \'\', \'DB_HOST\': \'db\', \'CONDA_SHLVL\': \'1\', \'SHLVL\': \'2\', \'CONDA_DEFAULT_ENV\': \'emissiontest\', \'EXP_CONDA_VER_SUFFIX\': \'0\', \'OLDPWD\': \'/\', \'LC_CTYPE\': \'C.UTF-8\', \'KMP_DUPLICATE_LIB_OK\': \'True\', \'KMP_INIT_AT_FORK\': \'FALSE\'}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nPlease provide the script with an argument. Use the "--help" option for more details\n'
])

#test that no two options can be used together
Expand Down

0 comments on commit ec38835

Please sign in to comment.