Changeset 6547 for trunk/sources/HeuristicLab/3.3/Tests
- Timestamp:
- 07/08/11 01:26:46 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab/3.3/Tests/ThreadSafeLogTest.cs
r6545 r6547 20 20 #endregion 21 21 22 using System;23 22 using System.Linq; 24 23 using System.Threading.Tasks; … … 32 31 [TestMethod] 33 32 public void ThreadSafeLogThreadSavetyTest() { 34 int count = 100000; 35 if (Environment.ProcessorCount > 2) { 36 Log l = new Log(); 37 AddMessagesInParallel(count, l); 38 // with a normal log there are race conditions which should cause problems 39 // actually we might geht lucky here but this should happen only seldomly 40 Assert.AreNotEqual(count, l.Messages.Count()); 41 } 33 int count = 10000; 34 ThreadSafeLog log = new ThreadSafeLog(); 42 35 43 ThreadSafeLog safeLog = new ThreadSafeLog(); 44 AddMessagesInParallel(count, safeLog); 45 // the thread safe log should work like a charm 46 Assert.AreEqual(count, safeLog.Messages.Count()); 47 } 36 Parallel.For(0, count, (i) => { 37 log.LogMessage("Message " + i); // write something 38 log.Messages.Count(); // iterate over all messages 39 }); 48 40 49 private void AddMessagesInParallel(int count, ILog l) { 50 Parallel.For(0, count, (i) => { 51 l.LogMessage("Message " + i); // write something 52 l.Messages.Count(); // iterate over all messages 53 }); 41 Assert.AreEqual(count, log.Messages.Count()); 54 42 } 55 43 }
Note: See TracChangeset
for help on using the changeset viewer.