Exemplo n.º 1
0
        public static void CheckLoggedValues(
            ITestLoggerFactory loggerFactory,
            LogLevel minLogLevel,
            IReadOnlyCollection <string> expectedLoggedValues)
        {
            var infoOrHigherEntries =
                loggerFactory.Sink.LogEntries.Where(x => x.LogLevel >= minLogLevel);

            var assertions = expectedLoggedValues.Select(
                expected =>
            {
                return(new Action <LogEntry>(
                           entry =>
                {
                    var actual = SpaceCompressor.CompressSpaces(entry.Message !);
                    var expected2 = SpaceCompressor.CompressSpaces(expected);

                    actual.Should().Be(expected2);
                }
                           ));
            }
                );

            if (expectedLoggedValues.IsNullOrEmpty())
            {
                infoOrHigherEntries.Should().BeEmpty("Log values should be empty");
            }
            else
            {
                infoOrHigherEntries.Should()
                .SatisfyRespectively(assertions, "Log value should match expected");
            }
        }
Exemplo n.º 2
0
 public static IStateMonad GetStateMonad(
     IExternalProcessRunner externalProcessRunner,
     ITestLoggerFactory testLoggerFactory) => GetStateMonad(
     testLoggerFactory,
     externalProcessRunner,
     ConsoleAdapter.Instance
     );
Exemplo n.º 3
0
 public virtual void CheckLoggedValues(ITestLoggerFactory loggerFactory)
 {
     if (!IgnoreLoggedValues)
     {
         LogChecker.CheckLoggedValues(
             loggerFactory,
             CheckLogLevel,
             ExpectedLoggedValues
             );
     }
 }
Exemplo n.º 4
0
        public static IStateMonad GetStateMonad(
            ITestLoggerFactory testLoggerFactory,
            IExternalProcessRunner externalProcessRunner,
            IConsole console)
        {
            var sclSettings = SettingsHelpers.CreateSCLSettings(
                new NuixSettings(
                    Constants.NuixConsoleExe,
                    new Version(8, 0),
                    true,
                    Constants.AllNuixFeatures
                    )
                );

            var sfs = StepFactoryStore.Create(
                sclSettings,
                Assembly.GetAssembly(typeof(IRubyScriptStep)) !
                );

            var fileSystem = new MockFileSystem(
                new Dictionary <string, MockFileData>()
            {
                { NuixConnectionHelper.NuixGeneralScriptName, "Ultimate Nuix Script" }
            },
                AppContext.BaseDirectory
                );

            var monad = new StateMonad(
                testLoggerFactory.CreateLogger("Test"),
                sclSettings,
                sfs,
                new ExternalContext(
                    externalProcessRunner,
                    console,
                    (ConnectorInjection.FileSystemKey, fileSystem)
                    ),
                new Dictionary <string, object>()
                );

            return(monad);
        }
 public UsuarioControllerTests(WebApplicationFactory <Startup> factory, ITestOutputHelper output)
 {
     _factory    = factory;
     _output     = new TestLoggerFactory(output);
     _httpClient = _factory.CreateClient();
 }
Exemplo n.º 6
0
        private static async Task TestRandomInner(HybridCache cache, TestParams options, ITestLoggerFactory loggerFactory, CancellationToken cancellationToken)
        {
            var data        = new byte[options.FileSize];
            var dataSegment = new ArraySegment <byte>(data);
            var contentType = "application/octet-stream";

            async Task <Tuple <string, ArraySegment <byte> > > DataProvider(CancellationToken token)
            {
                if (options.CreationTaskDelay.Ticks > 0)
                {
                    await Task.Delay(options.CreationTaskDelay, cancellationToken);
                }
                if (options.CreationThreadSleep.Ticks > 0)
                {
                    Thread.Sleep(options.CreationThreadSleep);
                }
                return(new Tuple <string, ArraySegment <byte> >(contentType, dataSegment));
            }

            var random = new Random(options.Seed);
            var tasks  = new List <Task <Tuple <TimeSpan, string> > >();


            var swTotal = Stopwatch.StartNew();

            for (var wave = 0; wave < options.RequestWaves; wave++)
            {
                if (wave != 0)
                {
                    Thread.Sleep(options.RequestWavesIntermission);
                }
                Console.Write("Wave {0}, {1} requests...", wave + 1, options.RequestCountPerWave);
                var sw = Stopwatch.StartNew();
                var memoryStreamManager =
                    new RecyclableMemoryStreamManager(Math.Max(2, options.FileSize), 2, options.FileSize * 2 + 2);
                for (var ix = 0; ix < options.RequestCountPerWave; ix++)
                {
                    Func <Task <Tuple <TimeSpan, string> > > task = async() =>
                    {
                        var whichFile   = random.Next(options.FileCount);
                        var key         = BitConverter.GetBytes(whichFile);
                        var itemSw      = Stopwatch.StartNew();
                        var cacheResult = await cache.GetOrCreateBytes(key, DataProvider, cancellationToken,
                                                                       options.RetrieveContentType);

                        if (cacheResult.Data != null)
                        {
                            await using (cacheResult.Data)
                            {
                                await using var ms = memoryStreamManager.GetStream();
                                await cacheResult.Data.CopyToAsync(ms, cancellationToken);
                            }
                        }

                        itemSw.Stop();
                        return(new Tuple <TimeSpan, string>(itemSw.Elapsed, cacheResult.Status));
                    };
                    if (options.Synchronous)
                    {
                        var result = await task();

                        tasks.Add(Task.FromResult(result));
                    }
                    else
                    {
                        tasks.Add(Task.Run(task, cancellationToken));
                    }
                }

                await Task.WhenAll(tasks);

                sw.Stop();
                var swAsync = Stopwatch.StartNew();
                await cache.AwaitEnqueuedTasks();

                swAsync.Stop();
                Console.WriteLine("completed in {0}, plus {1} for async tasks. ", sw.Elapsed, swAsync.Elapsed);
                PrintDiskUtilization(options);
            }

            swTotal.Stop();

            Console.WriteLine("Completed all waves in {0}", swTotal.Elapsed);
            Console.WriteLine();

            // Accumulate results
            var resultCounts = new Dictionary <string, int>();
            var resultTimes  = new Dictionary <string, List <TimeSpan> >();

            foreach (var t in tasks)
            {
                var key = t.Result.Item2;
                if (resultCounts.TryGetValue(key, out var value))
                {
                    resultCounts[key] = value + 1;
                }
                else
                {
                    resultCounts[key] = 1;
                    resultTimes[key]  = new List <TimeSpan>();
                }
                resultTimes[key].Add(t.Result.Item1);
            }

            foreach (var pair in resultCounts.OrderByDescending(p => p.Value))
            {
                Console.WriteLine("{0} - {1} occurrences - {2}kb - 1st percentile {3} 5th percentile = {4} 50th percentile = {5} 95th percentile = {6} 99th percentile = {7}",
                                  pair.Key, pair.Value,
                                  pair.Value * options.FileSize / 1000,
                                  GetPercentile(resultTimes[pair.Key], 0.01f),
                                  GetPercentile(resultTimes[pair.Key], 0.05f),
                                  GetPercentile(resultTimes[pair.Key], 0.5f),
                                  GetPercentile(resultTimes[pair.Key], 0.95f),
                                  GetPercentile(resultTimes[pair.Key], 0.99f));
            }

            var logCounts     = new Dictionary <string, int>();
            var logEntryCount = 0;

            foreach (var e in loggerFactory.Sink.LogEntries)
            {
                logEntryCount++;
                var key = e.OriginalFormat;
                if (logCounts.TryGetValue(key, out var value))
                {
                    logCounts[key] = value + 1;
                }
                else
                {
                    logCounts[key] = 1;
                }
            }

            foreach (var pair in logCounts)
            {
                var percent = pair.Value * 100.0 / logEntryCount;
                Console.WriteLine("{0:00.00}% ({1} of {2}) log entries were {3}", percent, pair.Value, logEntryCount, pair.Key);
            }
        }
Exemplo n.º 7
0
 public static IStateMonad GetStateMonadForProcess(ITestLoggerFactory testLoggerFactory) =>