Dvc: Investigate flaky logger tests

Created on 11 Apr 2019  路  5Comments  路  Source: iterative/dvc

Sometimes, upon running parallel tests, test_logger fails.
Chance for failing seems to increase upon running
python -m tests -n={X}
where X > num_cpu
and inserting sleep for 1 second before assertion in one of the test_logger.py tests.

Running with X < num_cpu seems to decrease chance of failing

self = <tests.unit.test_logger.TestColorFormatter object at 0x7efcf95d3c88>, caplog = <_pytest.logging.LogCaptureFixture object at 0x7efcf95f0908>

    def test_exception(self, caplog):
        try:
            raise ValueError
        except Exception:
            logger.exception("message")

        expected = (
            "{red}ERROR{nc}: message\n"
            "\n"
            "{footer}".format(footer=formatter.footer, **colors)
        )

        with caplog.at_level(logging.INFO, logger="dvc"):
>           assert expected == formatter.format(caplog.records[0])
E           IndexError: list index out of range

tests/unit/test_logger.py:70: IndexError

bug c3-small-fix p2-medium

All 5 comments

might be usefult to reproduce:

#! /bin/bash
for i in {1..10}
do
  python -m tests -n=24 >> test_result.log
done

@pared , this is interesting, caplog is missing to capture some logs, but it only happens on the test_logger.py :thinking: , also, what's up with the sleep(1), how did you discover that?

By the way, I was able to reproduce this.

To be honest I just had suspicion that we have some kind race condition and assumed that there will be higher chance of "test overlapping" if one is too slow. Tried it and it seems to work.

Fixed by #1875

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mdscruggs picture mdscruggs  路  3Comments

mfrata picture mfrata  路  3Comments

dmpetrov picture dmpetrov  路  3Comments

shcheklein picture shcheklein  路  3Comments

shcheklein picture shcheklein  路  3Comments