MCPcopy Index your code
hub / github.com/python/cpython / test_lru_cache_threaded2

Method test_lru_cache_threaded2

Lib/test/test_functools.py:2001–2026  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1999
2000 @threading_helper.requires_working_threading()
2001 def test_lru_cache_threaded2(self):
2002 # Simultaneous call with the same arguments
2003 n, m = 5, 7
2004 start = threading.Barrier(n+1)
2005 pause = threading.Barrier(n+1)
2006 stop = threading.Barrier(n+1)
2007 @self.module.lru_cache(maxsize=m*n)
2008 def f(x):
2009 pause.wait(10)
2010 return 3 * x
2011 self.assertEqual(f.cache_info(), (0, 0, m*n, 0))
2012 def test():
2013 for i in range(m):
2014 start.wait(10)
2015 self.assertEqual(f(i), 3 * i)
2016 stop.wait(10)
2017 threads = [threading.Thread(target=test) for k in range(n)]
2018 with threading_helper.start_threads(threads):
2019 for i in range(m):
2020 start.wait(10)
2021 stop.reset()
2022 pause.wait(10)
2023 start.reset()
2024 stop.wait(10)
2025 pause.reset()
2026 self.assertEqual(f.cache_info(), (0, (i+1)*n, m*n, i+1))
2027
2028 @threading_helper.requires_working_threading()
2029 def test_lru_cache_threaded3(self):

Callers

nothing calls this directly

Calls 4

waitMethod · 0.95
resetMethod · 0.95
BarrierMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected