(writer)
| 51 | |
| 52 | |
| 53 | def test_safe_adding_while_logging(writer): |
| 54 | barrier = Barrier(2) |
| 55 | counter = itertools.count() |
| 56 | |
| 57 | sink_1 = NonSafeSink(1) |
| 58 | sink_2 = NonSafeSink(1) |
| 59 | logger.add(sink_1, format="{message}", catch=False) |
| 60 | |
| 61 | def thread_1(): |
| 62 | barrier.wait() |
| 63 | logger.info("aaa{}bbb", next(counter)) |
| 64 | |
| 65 | def thread_2(): |
| 66 | barrier.wait() |
| 67 | time.sleep(0.5) |
| 68 | logger.add(sink_2, format="{message}", catch=False) |
| 69 | logger.info("ccc{}ddd", next(counter)) |
| 70 | |
| 71 | threads = [Thread(target=thread_1), Thread(target=thread_2)] |
| 72 | |
| 73 | for thread in threads: |
| 74 | thread.start() |
| 75 | |
| 76 | for thread in threads: |
| 77 | thread.join() |
| 78 | |
| 79 | logger.remove() |
| 80 | |
| 81 | assert sink_1.written == "aaa0bbb\nccc1ddd\n" |
| 82 | assert sink_2.written == "ccc1ddd\n" |
| 83 | |
| 84 | |
| 85 | def test_safe_removing_while_logging(capsys): |
nothing calls this directly
no test coverage detected