public void Test_UpdateSendSeq_MultiThread() { uint minValue = 0; uint maxValue = 65535; var result = new List <uint>(); uint singleCount = 100; var mgr = new SeqNoManager(minValue, maxValue, 1); var job = new Action(() => { for (var i = mgr.MinSendSeq; i <= singleCount; i++) { var value = mgr.GetAndUpdateSendSeq(); result.Add(value); } }); var jobCount = 5; var jobs = new List <Task>(); for (int i = 0; i < jobCount; i++) { var task1 = Task.Factory.StartNew(job); jobs.Add(task1); } jobs.ForEach(p => p.Wait()); Assert.AreEqual(jobCount * singleCount + jobCount - 1, result.Last()); }
public void Test_UpdateSendSeq() { uint number = 3; uint initialValue = 0; uint maxValue = 255; var mgr = new SeqNoManager(initialValue, maxValue, 3); for (uint i = initialValue; i < number * maxValue; i++) { var seqNo = mgr.GetAndUpdateSendSeq(); var expectedValue = i % (maxValue - initialValue + 1) + initialValue; Assert.AreEqual(expectedValue, seqNo); } }
uint ISaiFrameTransport.NextSendSeq() { return(_seqNoManager.GetAndUpdateSendSeq()); }