def run_test2(n, r, i): """ Run thread safety test to make sure the cache statistics are correct.""" fib.cache_clear() setinterval(i) threads = [Thread(target=run_fib_with_stats, args=(r, )) for _ in range(n)] run_threads(threads) hits, misses, maxsize, currsize = fib.cache_info() if misses != CACHE_SIZE: raise ValueError("Expected %d misses, Got %d" % (CACHE_SIZE, misses)) if maxsize != CACHE_SIZE: raise ValueError("Expected %d maxsize, Got %d" % (CACHE_SIZE, maxsize)) if currsize != CACHE_SIZE: raise ValueError("Expected %d currsize, Got %d" % (CACHE_SIZE, currsize))
def setUp(self): setinterval(1e-6) self.numthreads = 4 self.repeat = 1000
def run_test(n, r, i): """ Run thread safety test with n threads r times using interval i. """ setinterval(i) threads = [Thread(target=run_fib_with_clear, args=(r, )) for _ in range(n)] run_threads(threads)