Beispiel #1
0
 public RequestMessage(string sender, string recipient, string func, JToken[] args)
 {
     this.id        = "req-" + IdGen.Generate();
     this.sender    = sender;
     this.recipient = recipient;
     this.func      = func;
     this.args      = args;
 }
Beispiel #2
0
        public TestingSession(string assemblyName, string assemblyPath, string methodDeclaringClass, string methodName, int schedulingSeed, int timeoutMs = Constants.SessionTimeoutMs, int maxDecisions = Constants.SessionMaxDecisions)
        {
            this.Meta = new SessionInfo(IdGen.Generate().ToString(), assemblyName, assemblyPath, methodDeclaringClass, methodName, schedulingSeed, timeoutMs, maxDecisions);

            this.records = new List <SessionRecord>();

            // initialize run-time objects
            // this._onComplete = record => { };     // empty onComplete handler
            this.stateLock  = new object();
            this.traceFile  = File.AppendText(this.traceFilePath);
            this.logFile    = File.AppendText(this.logFilePath);
            this.IsFinished = new Concurrent <bool>();

            this.Reset();
        }
Beispiel #3
0
        public Promise RunTest(TestDefinition definition, int numIteration,
                               int timeoutMs             = Constants.SessionTimeoutMs,
                               int maxDecisions          = Constants.SessionMaxDecisions,
                               bool terminateOnFirstFail = false)
        {
            var testSummary = new TestSummary();

            this.summaryFile = File.AppendText("logs/client-summary-" + DateTime.Now.Ticks.ToString() + ".csv");
            this.summaryFile.WriteLine("Assembly,Class,Method,SessionId,Seed,Result,Reason,Elapsed");

            return(new Promise((resolve, reject) =>
            {
                if (definition.Setup != null)
                {
                    definition.Setup.Invoke(null, null);
                }
                resolve(null);
            }).Then(prev =>
            {
                var cts = new CancellationTokenSource();
                var run = Helpers.RepeatTask(() =>
                {
                    long started = Stopwatch.GetTimestamp();
                    return this.RunNewTestSession(definition.Run, SchedulingSeedGenerator.Generate())
                    // .Then(result => this.ReplayTestSession(((SessionRecord)result).sessionId, false))
                    .Then(result =>
                    {
                        SessionRecord record = (SessionRecord)result;

                        long elapsedMs = (Stopwatch.GetTimestamp() - started) / 10000;

                        // Append Summary
                        string summary = String.Join(",", new string[] {
                            definition.Run.DeclaringType.Assembly.FullName,
                            definition.Run.DeclaringType.FullName,
                            definition.Run.Name,
                            record.sessionId,
                            record.schedulingSeed.ToString(),
                            (record.passed ? "pass" : "fail"),
                            record.reason,
                            record.elapsedMs.ToString(),
                            elapsedMs.ToString()
                        });

                        testSummary.Update(record.numDecisions, record.elapsedMs, record.result == TestResult.MaxDecisionsReached);

                        this.summaryFile.WriteLine(summary);
                        this.summaryFile.Flush();

                        if (terminateOnFirstFail &&
                            !record.passed &&
                            record.result != TestResult.MaxDecisionsReached &&
                            !cts.IsCancellationRequested)
                        {
                            cts.Cancel();
                        }

                        return record;
                    }).Task;
                },
                                             numIteration, cts.Token);

                try
                {
                    run.Wait();
                }
                catch (AggregateException ex)
                {
                    if (ex.InnerExceptions[0] is TaskCanceledException && terminateOnFirstFail)
                    {
                        Console.WriteLine("Bug found! Suspending further tests because 'terminateOnFirstFail=true'");
                    }
                    else
                    {
                        Console.WriteLine("!!! Unexpected Exception !!!");
                        throw ex;
                    }
                }
#if DEBUG
                Console.WriteLine(TestRuntimeApi.Profiler.ToString());
#endif

                return testSummary;
            }).Then(prev =>
            {
                if (definition.Teardown != null)
                {
                    definition.Teardown.Invoke(null, null);
                }
                return prev;
            }));
        }