MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_race

Method test_race

Lib/test/test_logging.py:688–729  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

686 @threading_helper.requires_working_threading()
687 @support.requires_resource('walltime')
688 def test_race(self):
689 # Issue #14632 refers.
690 def remove_loop(fname, tries):
691 for _ in range(tries):
692 try:
693 os.unlink(fname)
694 self.deletion_time = time.time()
695 except OSError:
696 pass
697 time.sleep(0.004 * random.randint(0, 4))
698
699 del_count = 500
700 log_count = 500
701
702 self.handle_time = None
703 self.deletion_time = None
704
705 for delay in (False, True):
706 fn = make_temp_file('.log', 'test_logging-3-')
707 remover = threading.Thread(target=remove_loop, args=(fn, del_count))
708 remover.daemon = True
709 remover.start()
710 h = logging.handlers.WatchedFileHandler(fn, encoding='utf-8', delay=delay)
711 f = logging.Formatter('%(asctime)s: %(levelname)s: %(message)s')
712 h.setFormatter(f)
713 try:
714 for _ in range(log_count):
715 time.sleep(0.005)
716 r = logging.makeLogRecord({'msg': 'testing' })
717 try:
718 self.handle_time = time.time()
719 h.handle(r)
720 except Exception:
721 print('Deleted at %s, '
722 'opened at %s' % (self.deletion_time,
723 self.handle_time))
724 raise
725 finally:
726 remover.join()
727 h.close()
728 if os.path.exists(fn):
729 os.unlink(fn)
730
731 # The implementation relies on os.register_at_fork existing, but we test
732 # based on os.fork existing because that is what users and this test use.

Callers

nothing calls this directly

Calls 11

startMethod · 0.95
joinMethod · 0.95
make_temp_fileFunction · 0.85
setFormatterMethod · 0.80
printFunction · 0.50
sleepMethod · 0.45
timeMethod · 0.45
handleMethod · 0.45
closeMethod · 0.45
existsMethod · 0.45
unlinkMethod · 0.45

Tested by

no test coverage detected