Exemple #1
0
        private void InternalTestWithException <TException>(Delegate test, Configuration configuration = null, bool replay = false)
            where TException : Exception
        {
            configuration = configuration ?? GetConfiguration();

            Type exceptionType = typeof(TException);

            Assert.True(exceptionType.IsSubclassOf(typeof(Exception)), "Please configure the test correctly. " +
                        $"Type '{exceptionType}' is not an exception type.");

            TextWriter logger;

            if (configuration.IsVerbose)
            {
                logger = new TestOutputLogger(this.TestOutput, true);
            }
            else
            {
                logger = TextWriter.Null;
            }

            try
            {
                var engine = RunTest(test, configuration, logger);

                CheckErrors(engine, exceptionType);

                if (replay)
                {
                    configuration.SchedulingStrategy = "replay";
                    configuration.ScheduleTrace      = engine.ReproducableTrace;

                    engine = RunTest(test, configuration, logger);

                    string replayError = (engine.Strategy as ReplayStrategy).ErrorText;
                    Assert.True(replayError.Length == 0, replayError);
                    CheckErrors(engine, exceptionType);
                }
            }
            catch (Exception ex)
            {
                Assert.False(true, ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                logger.Dispose();
            }
        }
Exemple #2
0
        protected async Task RunAsync(Func <IActorRuntime, Task> test, Configuration configuration = null, bool handleFailures = true)
        {
            configuration = configuration ?? GetConfiguration();

            TextWriter logger;

            if (configuration.IsVerbose)
            {
                logger = new TestOutputLogger(this.TestOutput, true);
            }
            else
            {
                logger = TextWriter.Null;
            }

            try
            {
                configuration.IsMonitoringEnabledInInProduction = true;
                var runtime = RuntimeFactory.Create(configuration);
                runtime.SetLogger(logger);

                var errorTask = TaskCompletionSource.Create <Exception>();
                if (handleFailures)
                {
                    runtime.OnFailure += (e) =>
                    {
                        errorTask.SetResult(Unwrap(e));
                    };
                }

                await Task.WhenAny(test(runtime), errorTask.Task);

                if (handleFailures && errorTask.Task.IsCompleted)
                {
                    Assert.False(true, errorTask.Task.Result.Message);
                }
            }
            catch (Exception ex)
            {
                Exception e = Unwrap(ex);
                Assert.False(true, e.Message + "\n" + e.StackTrace);
            }
            finally
            {
                logger.Dispose();
            }
        }
Exemple #3
0
        private void RunWithErrors(Action <IActorRuntime> test, Configuration configuration, TestErrorChecker errorChecker)
        {
            configuration = configuration ?? GetConfiguration();

            TextWriter logger;

            if (configuration.IsVerbose)
            {
                logger = new TestOutputLogger(this.TestOutput, true);
            }
            else
            {
                logger = TextWriter.Null;
            }

            try
            {
                var runtime = RuntimeFactory.Create(configuration);
                runtime.SetLogger(logger);
                for (int i = 0; i < configuration.TestingIterations; i++)
                {
                    test(runtime);
                }
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
                if (ex is AggregateException ae)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var e in ae.InnerExceptions)
                    {
                        sb.AppendLine(e.Message);
                    }

                    msg = sb.ToString();
                }

                errorChecker(msg);
            }
            finally
            {
                logger.Dispose();
            }
        }
Exemple #4
0
        private void TestWithErrors(Delegate test, Configuration configuration, TestErrorChecker errorChecker, bool replay)
        {
            configuration = configuration ?? GetConfiguration();

            TextWriter logger;

            if (configuration.IsVerbose)
            {
                logger = new TestOutputLogger(this.TestOutput, true);
            }
            else
            {
                logger = TextWriter.Null;
            }

            try
            {
                var engine = RunTest(test, configuration, logger);
                CheckErrors(engine, errorChecker);

                if (replay)
                {
                    configuration.WithReplayStrategy(engine.ReproducableTrace);

                    engine = RunTest(test, configuration, logger);

                    string replayError = (engine.Strategy as ReplayStrategy).ErrorText;
                    Assert.True(replayError.Length == 0, replayError);
                    CheckErrors(engine, errorChecker);
                }
            }
            catch (Exception ex)
            {
                Assert.False(true, ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                logger.Dispose();
            }
        }
Exemple #5
0
        protected void RunWithException <TException>(Action test, Configuration configuration = null)
        {
            configuration = configuration ?? GetConfiguration();

            Type exceptionType = typeof(TException);

            Assert.True(exceptionType.IsSubclassOf(typeof(Exception)), "Please configure the test correctly. " +
                        $"Type '{exceptionType}' is not an exception type.");

            TextWriter logger;

            if (configuration.IsVerbose)
            {
                logger = new TestOutputLogger(this.TestOutput, true);
            }
            else
            {
                logger = TextWriter.Null;
            }

            try
            {
                var runtime = RuntimeFactory.Create(configuration);
                runtime.SetLogger(logger);
                for (int i = 0; i < configuration.TestingIterations; i++)
                {
                    test();
                }
            }
            catch (Exception ex)
            {
                Assert.True(ex.GetType() == exceptionType, ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                logger.Dispose();
            }
        }