コード例 #1
0
 static void HitIndex(object index)
 {
     int hitIndex = (int)index;
     for (int i = 0; i <= hitIndex; ++i)
     {
         ModuleTrackerTemplate.RecordHit(i);
     }
 }
コード例 #2
0
        private void RecordHits(params int[] hitCounts)
        {
            // Since the hit array is held in a thread local member that is
            // then dropped by UnloadModule the hit counting must be done
            // in a new thread for each test

            Assert.Equal(ModuleTrackerTemplate.HitsArray.Length, hitCounts.Length + ModuleTrackerTemplate.HitsResultHeaderSize);

            var thread = new Thread(() =>
            {
                for (var i = 0; i < hitCounts.Length; i++)
                {
                    var count = hitCounts[i];
                    while (count-- > 0)
                    {
                        ModuleTrackerTemplate.RecordHit(i);
                    }
                }
            });

            thread.Start();
            thread.Join();
        }
コード例 #3
0
        public void HitsOnMultipleThreadsCorrectlyCounted()
        {
            ModuleTrackerTemplate.HitsArray = new[] { 0, 0, 0, 0 };
            for (int i = 0; i < ModuleTrackerTemplate.HitsArray.Length; ++i)
            {
                var t = new Thread(HitIndex);
                t.Start(i);
            }

            ModuleTrackerTemplate.UnloadModule(null, null);
            var expectedHitsArray = new[] { 4, 3, 2, 1 };

            Assert.Equal(expectedHitsArray, ReadHitsFile());

            void HitIndex(object index)
            {
                var hitIndex = (int)index;

                for (int i = 0; i <= hitIndex; ++i)
                {
                    ModuleTrackerTemplate.RecordHit(i);
                }
            }
        }