public void TestMultithreaded(int threadCount) { var source = new ThreadIdModule(); var cache = new Cache { Source0 = source }; var threadArray = new Thread[threadCount]; bool startFlag = false; for (int i = 0; i < threadArray.Length; i++) { threadArray[i] = new Thread(() => { for (int k = 0; k < 500; k++) { SpinWait.SpinUntil(() => startFlag); var sourceValue = source.GetValue(0, 0, 0); Assert.Equal(sourceValue, cache.GetValue(0, 0, 0)); Assert.Equal(sourceValue, cache.GetValue(0, 0, 0)); } }); } for (int i = 0; i < threadArray.Length; i++) threadArray[i].Start(); startFlag = true; for (int i = 0; i < threadArray.Length; i++) threadArray[i].Join(); }
public void TestGetValueCalledOnce(double x, double y, double z) { var testModule = new CounterModule(); var cache = new Cache { Source0 = testModule }; var cachedValue = cache.GetValue(x, y, z); // Make sure repeated calls do not reach the test module's counter Assert.Equal(cachedValue, cache.GetValue(x, y, z)); Assert.Equal(cachedValue, cache.GetValue(x, y, z)); }