public void Test() { var store = new FileStore(_rootPath); var tasks = new List <Task>(); HttpResponseMessage responseMessage = null; for (var i = 0; i < ConcurrencyLevel; i++) { var message = GetMessage(i % ConcurrencyLevel); var cacheKey = new CacheKey(message.RequestUri.ToString(), new string[0]); tasks.Add(new Task( () => store.AddOrUpdate(cacheKey, _responseBuilder.Send(message)))); tasks.Add(new Task( () => store.TryGetValue(cacheKey, out responseMessage))); tasks.Add(new Task( () => store.TryRemove(cacheKey))); } var randomisedList = new List <Task>(); //while (tasks.Count>0) //{ // var i = _random.Next(tasks.Count); // randomisedList.Add(tasks[i]); // tasks.RemoveAt(i); //} //tasks = randomisedList; foreach (var task in tasks) { task.ContinueWith(t => { if (t.IsFaulted) { Assert.Fail(t.Exception.ToString()); } }); task.Start(); } var tt = DateTime.Now; var waited = Task.WaitAll(tasks.ToArray(), WaitTimeOut); // Console.WriteLine("Total milliseconds " + (DateTime.Now - tt).TotalMilliseconds); if (!waited) { Assert.Fail("Timed out"); } }
public void Test() { var store = new FileStore(_rootPath); List<Task> tasks = new List<Task>(); HttpResponseMessage responseMessage = null; for (int i = 0; i < ConcurrencyLevel; i++) { var message = GetMessage(i % ConcurrencyLevel); var cacheKey = new CacheKey(message.RequestUri.ToString(), new string[0]); tasks.Add(new Task( () => store.AddOrUpdate(cacheKey, _responseBuilder.Send(message)))); tasks.Add(new Task( () => store.TryGetValue(cacheKey, out responseMessage))); tasks.Add(new Task( () => store.TryRemove(cacheKey))); } var randomisedList = new List<Task>(); //while (tasks.Count>0) //{ // var i = _random.Next(tasks.Count); // randomisedList.Add(tasks[i]); // tasks.RemoveAt(i); //} //tasks = randomisedList; foreach (var task in tasks) { task.ContinueWith(t => { if (t.IsFaulted) Assert.Fail(t.Exception.ToString()); }); task. Start(); } DateTime tt = DateTime.Now; var waited = Task.WaitAll(tasks.ToArray(), WaitTimeOut); // Console.WriteLine("Total milliseconds " + (DateTime.Now - tt).TotalMilliseconds); if(!waited) Assert.Fail("Timed out"); }