Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


기본 유닛테스트

...

Code Block
themeEmacs
        [Theory(DisplayName = "RoundRobinPoolTest")]
        [InlineData(3,1000)]
        public void RoundRobinPoolTest(int nodeCount, int testCount, bool isPerformTest = false)
        {
            var actorSystem = akkaService.GetActorSystem();

            TestProbe testProbe = this.CreateTestProbe(actorSystem);

            var props = new RoundRobinPool(nodeCount)                
                .Props(Props.Create(() => new BasicActor()));

            var actor = actorSystem.ActorOf(props);

            for (int i = 0; i < nodeCount; i++)
            {
                actor.Tell(testProbe.Ref);
            }

            int cutOff = 3000;

            Within(TimeSpan.FromMilliseconds(cutOff), () =>
            {
                for (int i = 0; i < testCount; i++)
                {
                    actor.Tell("hello" + i);
                }

                for (int i = 0; i < testCount; i++)
                {
                    testProbe.ExpectMsg("world");
                    
                    if (isPerformTest)
                    {
                        _dictionary.Add(_key++, _key);
                        _addCounter.Increment();
                    }
                }
            });
        }

...

유닛테스트가 완료된 로직의 성능테스트가 필요시 Nbench를 활용하여 성능 유닛테스트 검사기를 추가할수 있습니다.

Code Block
themeEmacs
        [NBenchFact]        
        [PerfBenchmark(NumberOfIterations = 3, RunMode = RunMode.Throughput,
        RunTimeMilliseconds = 1000, TestMode = TestMode.Test)]
        [CounterThroughputAssertion("TestCounter", MustBe.GreaterThan, 1000.0d)]
        [CounterTotalAssertion("TestCounter", MustBe.GreaterThan, 1500.0d)]
        [CounterMeasurement("TestCounter")]
        public void RoundRobinPoolTestPerformanceTest()
        {
            RoundRobinPoolTest(5, 3000, true);
        }

...

성능 유닛트세트가 작성되면, VS-IDE가 제공하는 테스트 탐색기를 통해서도 수행할수 있습니다.



성능측정 리포트

...

Code Block
themeEmacs
    [PASS] Expected [Counter] TestCounter to must be greater than 1,000.00 operations; actual value was 94,160.06 operations.
    
    [PASS] Expected [Counter] TestCounter to must be greater than 1,500.00 operations; actual value was 93,000.00 operations.
    
    
    ---------- Measurements ----------
    
    Metric : [Counter] TestCounter
    
    Per Second ( operations )
    Average         : 94160.06329051661
    Max             : 94937.13528317196
    Min             : 93266.78965179897
    Std. Deviation  : 841.2138544819605
    Std. Error      : 485.6750453312026
    
    Per Test ( operations )
    Average         : 93000
    Max             : 93000
    Min             : 93000
    Std. Deviation  : 0
    Std. Error      : 0
    
    ----------

...

이벤트가를 N개 동시 발생하며,  소비가 되는구간에서 성능카운트를 1올려줍니다.

Code Block
themeEmacs
[Theory(DisplayName = "테스트 n초당 1회 호출제약")]
[InlineData(5, 1, false)]
public void ThrottleLimitTest(int givenTestCount, int givenLimitSeconds, bool isPerformTest)
{
.......
  // Create ThrottleLimit Actor
  throttleLimitActor = actorSystem.ActorOf(Props.Create(() => new ThrottleLimitActor(1, givenLimitSeconds, 1000)));
  throttleLimitActor.Tell(new SetTarget(probe))
  
  for (int i = 0; i < givenTestCount; i++)
  {
      throttleLimitActor.Tell(new EventCmd()
      {
          Message = "test",
      });
  }
  
  //Then : Safe processing within N seconds limit
  for (int i = 0; i < givenTestCount; i++)
  {
      probe.ExpectMsg<EventCmd>(message =>
      {
          Assert.Equal("test", message.Message);                        
      });
  
      output.WriteLine($"[{DateTime.Now}] - GTPRequestCmd");
  
      if (isPerformTest)
      {
          _dictionary.Add(_key++, _key);
          _addCounter.Increment();
      }
  }
...........
}  

...

도메인 검증은 발생메시지가 모두 소비되었나를 검증하며 , TPS 1을 유지하였는가 성능검증은 다음과같이 작성합니다.

Code Block
themeEmacs
        [NBenchFact]
        [PerfBenchmark(NumberOfIterations = 3, RunMode = RunMode.Throughput,
        RunTimeMilliseconds = 1000, TestMode = TestMode.Test)]
        [CounterThroughputAssertion("TestCounter", MustBe.LessThanOrEqualTo, 1.0d)]
        [CounterTotalAssertion("TestCounter", MustBe.LessThanOrEqualTo, 1)]
        [CounterMeasurement("TestCounter")]
        public void ThrottleLimitPerformanceTest()
        {
            ThrottleLimitTest(1, 1, true);
        }

...

  • [CounterThroughputAssertion("TestCounter", MustBe.LessThanOrEqualTo, 1.0d)]
  • [CounterTotalAssertion("TestCounter", MustBe.LessThanOrEqualTo, 1)]


성능제약 통과 로그

Code Block
themeEmacs
    [PASS] Expected [Counter] TestCounter to must be less than or equal to 1.00 operations; actual value was 0.98 operations.
    
    [PASS] Expected [Counter] TestCounter to must be less than or equal to 1.00 operations; actual value was 1.00 operations.
    
    
    ---------- Measurements ----------
    
    Metric : [Counter] TestCounter
    
    Per Second ( operations )
    Average         : 0.9802234345891607
    Max             : 0.9823810933292493
    Min             : 0.9787775577268321
    Std. Deviation  : 0.0019042957466220024
    Std. Error      : 0.0010994456619288725
    
    Per Test ( operations )
    Average         : 1
    Max             : 1
    Min             : 1
    Std. Deviation  : 0
    Std. Error      : 0
    

...