예제 #1
0
        static void Main(string[] args)
        {
            CultureInfo.DefaultThreadCurrentCulture   = CultureInfo.InvariantCulture;
            CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;

            PerformanceCollectorOptions.Default.Writer = PerformanceCollectorOptions.Disabled.Writer = new OutputWriter();

            Parser.Default.ParseArguments <Options>(args)
            .MapResult(options =>
            {
                if (Enum.IsDefined(typeof(VerbosityLevel), options.Verbosity))
                {
                    verbosityLevel = verbosityLevels[(VerbosityLevel)options.Verbosity];
                }
                else
                {
                    Console.WriteLine("Invalid verbosity level");
                    return(1);
                }

                Console.WriteLine($"Using these options: {JsonConvert.SerializeObject(options, Formatting.Indented)}");

                RunApplication(options);
                return(0);
            },
                       _ => 1);
        }
예제 #2
0
        public TestBase(MethodToTest methodToTest)
        {
            this.MethodToTest = methodToTest;

            this.DefaultRequest = new Dictionary <IRpcService, TestRequest>();
            foreach (var service in TestExecutor.Services)
            {
                this.DefaultRequest.Add(service, TestRequestFactory.CreateRequestFor(methodToTest, TestExecutor.TestData[service]));
            }

            this.options = PerformanceCollectorOptions.Default;
            this.Enabled = true;
        }
예제 #3
0
 public T SetOptions(PerformanceCollectorOptions options)
 {
     this.options = options;
     return((T)this);
 }
예제 #4
0
 protected List <TestResult> CallBatch(Func <IRpcService, TestRequest> requestFactory, int batchSize, PerformanceCollectorOptions options, TestResultCollector testResultCollector = null)
 {
     return(TestExecutor.CallBatch(requestFactory, batchSize, options, testResultCollector));
 }
예제 #5
0
 protected void CallNTimes(Func <IRpcService, TestRequest> requestFactory, int count, PerformanceCollectorOptions options, TestResultCollector testResultCollector = null)
 {
     TestExecutor.CallNTimes(requestFactory, count, options, testResultCollector);
 }
예제 #6
0
        public static void CallNTimes(Func <IRpcService, TestRequest> requestFactory, int count, PerformanceCollectorOptions options, TestResultCollector testResultCollector = null)
        {
            string requestMethodName = null;

            List <TestResult>[] testResults = Enumerable.Range(0, count).Select((i) => new List <TestResult>()).ToArray();

            foreach (var service in TestExecutor.Services)
            {
                var request = requestFactory(service);
                if (requestMethodName == null)
                {
                    requestMethodName = request.MethodName;
                }

                if (options.Enabled)
                {
                    options?.Writer?
                    .WriteLine()
                    .WriteLine($"Calling {requestMethodName} {count} times".Center(80, '~'))
                    .WriteLine(request.ToString())
                    .DrawLine('~');
                }

                using (PerformanceCollector performanceCollector = new PerformanceCollector(service.GetServiceDescription(), options))
                {
                    for (int i = 0; i < count; i++)
                    {
                        int retries = 0;
                        while (retries < MAX_RETRY)
                        {
                            try
                            {
                                PerformanceEntry performance = performanceCollector.Measure(() => service.CallSingle(request));
                                testResults[i].Add(new TestResult(service, count, performance));
                                AddSingleCallResult(service, requestMethodName, performance.Elapsed);
                                break;
                            }
                            catch (System.Exception ex)
                            {
                                Thread.Sleep(200); //introduces a wait between calls because of intermittent problem with "The server returned an invalid or unrecognized response" error
                                retries++;
                            }
                        }
                    }
                }
            }

            if (testResultCollector != null)
            {
                for (int i = 0; i < testResults.Length; i++)
                {
                    testResultCollector.Collect($"t-{i + 1}", testResults[i]);
                }
            }
            else
            {
                using (testResultCollector = new TestResultCollector($"{requestMethodName} repeated calls ({count})."))
                {
                    for (int i = 0; i < testResults.Length; i++)
                    {
                        testResultCollector.Collect($"t-{i + 1}", testResults[i]);
                    }
                }
            }
        }
예제 #7
0
        public static List <TestResult> CallBatch(Func <IRpcService, TestRequest> requestFactory, int batchSize, PerformanceCollectorOptions options, TestResultCollector testResultCollector = null)
        {
            string requestMethodName = null;
            var    testResults       = new List <TestResult>();

            foreach (var service in TestExecutor.Services)
            {
                var request = requestFactory(service);
                if (requestMethodName == null)
                {
                    requestMethodName = request.MethodName;
                }

                if (options.Enabled)
                {
                    options?.Writer?
                    .WriteLine()
                    .WriteLine($"Calling batch of {batchSize} {requestMethodName}".Center(80, '~'))
                    .WriteLine(request.ToString())
                    .DrawLine('~');
                }

                using (PerformanceCollector performanceCollector = new PerformanceCollector(service.GetServiceDescription(), options))
                {
                    PerformanceEntry performance = performanceCollector.Measure(() => service.CallBatch(Enumerable.Range(0, batchSize).Select(n => request).ToList()));
                    testResults.Add(new TestResult(service, batchSize, performance));
                    AddBatchCallResult(service, requestMethodName, batchSize, performance.Elapsed);
                }
            }

            if (testResultCollector != null)
            {
                testResultCollector.Collect(batchSize.ToString(), testResults);
            }
            else
            {
                using (testResultCollector = new TestResultCollector($"{requestMethodName} BATCH calls"))
                {
                    testResultCollector.Collect(batchSize.ToString(), testResults);
                }
            }

            return(testResults);
        }