Exemplo n.º 1
0
        // tests for race conditions to outbox
        public void TestInboxConcurrency()
        {
            int threadCount = 100;
            var threadList  = new List <Thread>();

            // init and start threads to add messages
            for (int i = 0; i < testMessages.Count * threadCount; i += testMessages.Count)
            {
                var thread = new Thread(() =>
                {
                    trader.AddMessage(testMessages.ToArray());
                });
                threadList.Add(thread);
                thread.Start();
            }

            // join threads
            foreach (var thread in threadList)
            {
                thread.Join();
            }

            // check messages in order
            var messages = trader.GetMessages();

            for (int i = 0; i < messages.Count; ++i)
            {
                Assert.AreEqual(testMessages[i % 3], messages[i % 3]);
            }
        }
Exemplo n.º 2
0
 public void init()
 {
     trader = new Trader("1");
     foreach (var message in testMessages)
     {
         trader.AddMessage(message);
     }
 }