예제 #1
0
        public void StartingAlreadyStartedLaunch()
        {
            var launchReporter = new LaunchReporter(_service);

            launchReporter.Start(new Client.Requests.StartLaunchRequest());

            Assert.Throws <InsufficientExecutionStackException>(() => launchReporter.Start(new Client.Requests.StartLaunchRequest()));
        }
예제 #2
0
        public void StartLaunchScheduling()
        {
            var totalNumber = 1000;

            var fakeService = new FakeService(new Uri("https://rp.epam.com/api/v1/"), "ci-agents-checks", "b79e81a5-8448-49b5-857d-945ff5fd5ed2");

            var launchReporters = new List <LaunchReporter>();

            for (int i = 0; i < totalNumber; i++)
            {
                var launchReporter = new LaunchReporter(fakeService);

                launchReporters.Add(launchReporter);

                var launchDateTime = DateTime.UtcNow;

                launchReporter.Start(new Client.Requests.StartLaunchRequest
                {
                    Name      = $"ReportPortal Shared {i}",
                    StartTime = launchDateTime
                });
            }

            Task.WaitAll(launchReporters.Select(l => l.StartTask).ToArray());

            Assert.Equal(totalNumber, launchReporters.Select(l => l.LaunchInfo.Name).Distinct().Count());
            Assert.Equal(totalNumber, launchReporters.Select(l => l.LaunchInfo.Id).Distinct().Count());
        }
        /// <summary>
        /// Starting connect to report portal. Create launcher and start it.
        /// </summary>
        /// <param name="args"></param>
        protected virtual void TestAssemblyExecutionStarting(MessageHandlerArgs <ITestAssemblyStarting> args)
        {
            lock (Logger.LockObject)
            {
                try
                {
                    LaunchMode launchMode = _config.GetValue(ConfigurationPath.LaunchDebugMode, false) ? LaunchMode.Debug : LaunchMode.Default;

                    var startLaunchRequest = new StartLaunchRequest
                    {
                        Name       = _config.GetValue(ConfigurationPath.LaunchName, args.Message.TestAssembly.Assembly.Name),
                        StartTime  = DateTime.UtcNow,
                        Mode       = launchMode,
                        Attributes = _config.GetKeyValues("Launch:Attributes", new List <KeyValuePair <string, string> >()).Select(a => new ItemAttribute {
                            Key = a.Key, Value = a.Value
                        }).ToList(),
                        Description = _config.GetValue(ConfigurationPath.LaunchDescription, "")
                    };

                    Shared.Extensibility.Embedded.Analytics.AnalyticsReportEventsObserver.DefineConsumer("agent-dotnet-xunit");

                    _launchReporter = new LaunchReporter(_service, _config, null, Shared.Extensibility.ExtensionManager.Instance);
                    _launchReporter.Start(startLaunchRequest);
                }
                catch (Exception exp)
                {
                    Logger.LogError(exp.ToString());
                }
            }
        }
예제 #4
0
        public void BridgeLogMessage()
        {
            var launchReporter = new LaunchReporter(_service);

            Bridge.Context.LaunchReporter = launchReporter;

            launchReporter.Start(new StartLaunchRequest
            {
                Name      = "ReportPortal Shared",
                StartTime = DateTime.UtcNow,
                Mode      = LaunchMode.Debug,
                Tags      = new System.Collections.Generic.List <string>()
            });


            var suiteNode = launchReporter.StartChildTestReporter(new StartTestItemRequest
            {
                Name      = $"Suite",
                StartTime = DateTime.UtcNow,
                Type      = TestItemType.Suite
            });

            var testNode = suiteNode.StartChildTestReporter(new StartTestItemRequest
            {
                Name      = $"Test",
                StartTime = DateTime.UtcNow,
                Type      = TestItemType.Step
            });

            for (int i = 0; i < 20; i++)
            {
                Log.Message(new AddLogItemRequest
                {
                    Level = LogLevel.Info,
                    Time  = DateTime.UtcNow.AddMilliseconds(i),
                    Text  = $"Log {i}"
                });
            }

            testNode.Finish(new Client.Requests.FinishTestItemRequest
            {
                EndTime = DateTime.UtcNow,
                Status  = Client.Models.Status.Passed
            });

            suiteNode.Finish(new Client.Requests.FinishTestItemRequest
            {
                EndTime = DateTime.UtcNow,
                Status  = Client.Models.Status.Passed
            });

            launchReporter.Finish(new Client.Requests.FinishLaunchRequest
            {
                EndTime = DateTime.UtcNow
            });

            launchReporter.FinishTask.Wait();
        }
예제 #5
0
        public void StartSpec(SpecExecutionStartingRequest request)
        {
            lock (_lockObj)
            {
                if (_launch == null)
                {
                    var launchReporter = new LaunchReporter(_service, _configuration, null, ExtensionManager.Instance);

                    // if execution is rerun
                    if (request.CurrentExecutionInfo.ExecutionArgs.Any(arg => arg.FlagName.ToLowerInvariant() == "failed"))
                    {
                        _startLaunchRequest.IsRerun = true;
                    }

                    launchReporter.Start(_startLaunchRequest);

                    _launch = launchReporter;
                }

                var specResult = request.SpecResult;

                var specReporter = _launch.StartChildTestReporter(new StartTestItemRequest
                {
                    Type        = TestItemType.Suite,
                    Name        = specResult.ProtoSpec.SpecHeading,
                    Description = string.Join("", specResult.ProtoSpec.Items.Where(i => i.ItemType == ProtoItem.Types.ItemType.Comment).Select(c => c.Comment.Text)),
                    StartTime   = DateTime.UtcNow,
                    Attributes  = specResult.ProtoSpec.Tags.Select(t => new ItemAttributeConverter().ConvertFrom(t, opts => opts.UndefinedKey = "tag")).ToList()
                });

                // pre hook messages
                if (specResult.ProtoSpec.PreHookMessages.Count != 0 || specResult.ProtoSpec.PreHookFailures.Count != 0)
                {
                    foreach (var preHookMessage in specResult.ProtoSpec.PreHookMessages)
                    {
                        specReporter.Log(new CreateLogItemRequest
                        {
                            Level = LogLevel.Debug,
                            Text  = preHookMessage,
                            Time  = DateTime.UtcNow
                        });
                    }

                    foreach (var preHookFailure in specResult.ProtoSpec.PreHookFailures)
                    {
                        specReporter.Log(new CreateLogItemRequest
                        {
                            Level = LogLevel.Error,
                            Text  = $"{preHookFailure.ErrorMessage}{Environment.NewLine}{preHookFailure.StackTrace}",
                            Time  = DateTime.UtcNow
                        });
                    }
                }

                var key = GetSpecKey(request.CurrentExecutionInfo, request.CurrentExecutionInfo.CurrentSpec);
                _specs[key] = specReporter;
            }
        }
 public void Start()
 {
     _launchReporter = new LaunchReporter(_rpService, null, null);
     _launchReporter.Start(new StartLaunchRequest
     {
         StartTime = DateTime.UtcNow,
         Name      = Environment.GetEnvironmentVariable("rp.launch")
     });
 }
예제 #7
0
        public void Test1()
        {
            var service        = new Service(new Uri("https://rp.epam.com/api/v1/"), "default_project", "7853c7a9-7f27-43ea-835a-cab01355fd17");
            var launchReporter = new LaunchReporter(service);

            launchReporter.Start(new Client.Requests.StartLaunchRequest
            {
                Name      = "ReportPortal.Shared",
                StartTime = DateTime.UtcNow,
                Mode      = Client.Models.LaunchMode.Debug
            });

            var suiteReporter = launchReporter.StartNewTestNode(new Client.Requests.StartTestItemRequest
            {
                Name      = "Suite",
                StartTime = DateTime.UtcNow,
                Type      = Client.Models.TestItemType.Suite
            });

            var testReporter = suiteReporter.StartNewTestNode(new Client.Requests.StartTestItemRequest
            {
                Name      = "Test",
                StartTime = DateTime.UtcNow,
                Type      = Client.Models.TestItemType.Step
            });

            for (int i = 0; i < 10; i++)
            {
                System.Threading.Thread.Sleep(1);
                testReporter.Log(new Client.Requests.AddLogItemRequest
                {
                    Text  = $"Log message #{i}",
                    Time  = DateTime.UtcNow,
                    Level = Client.Models.LogLevel.Info
                });
            }

            testReporter.Finish(new Client.Requests.FinishTestItemRequest
            {
                EndTime = DateTime.UtcNow,
                Status  = Client.Models.Status.Passed
            });

            suiteReporter.Finish(new Client.Requests.FinishTestItemRequest
            {
                EndTime = DateTime.UtcNow,
                Status  = Client.Models.Status.Passed
            });

            launchReporter.Finish(new Client.Requests.FinishLaunchRequest
            {
                EndTime = DateTime.UtcNow
            });
            launchReporter.FinishTask.Wait();
        }
예제 #8
0
        public void ShouldThrowExceptionWhenStartingAlreadyStartedTestItem()
        {
            var service = new MockServiceBuilder().Build();

            var launch = new LaunchReporter(service.Object, null, null, new Mock <IExtensionManager>().Object);

            launch.Start(new StartLaunchRequest());
            var test = launch.StartChildTestReporter(new StartTestItemRequest());

            test.Invoking(t => t.Start(new StartTestItemRequest())).Should().ThrowExactly <InsufficientExecutionStackException>();
        }
예제 #9
0
        public void StartingLaunchWhichIsAlreadyStarted()
        {
            var service = new MockServiceBuilder().Build();

            var launch = new LaunchReporter(service.Object, null, null, new ExtensionManager());

            launch.Start(new StartLaunchRequest {
            });
            launch.Invoking(l => l.Start(new StartLaunchRequest {
            })).Should().Throw <InsufficientExecutionStackException>().And.Message.Should().Contain("already scheduled for starting");
        }
예제 #10
0
        public void MixingTestsAndLogs()
        {
            var service = new MockServiceBuilder().Build();

            var launchReporter = new LaunchReporter(service.Object, null, null, new ExtensionManager());

            launchReporter.Start(new StartLaunchRequest {
                StartTime = DateTime.UtcNow
            });

            for (int i = 0; i < 10; i++)
            {
                var suite = launchReporter.StartChildTestReporter(new StartTestItemRequest {
                    StartTime = DateTime.UtcNow
                });

                suite.Log(new CreateLogItemRequest {
                    Time = DateTime.UtcNow
                });

                for (int j = 0; j < 20; j++)
                {
                    var test = suite.StartChildTestReporter(new StartTestItemRequest {
                        StartTime = DateTime.UtcNow
                    });

                    test.Log(new CreateLogItemRequest {
                        Time = DateTime.UtcNow
                    });

                    test.Finish(new FinishTestItemRequest {
                        EndTime = DateTime.UtcNow
                    });
                }

                suite.Log(new CreateLogItemRequest {
                    Time = DateTime.UtcNow
                });

                suite.Finish(new FinishTestItemRequest {
                    EndTime = DateTime.UtcNow
                });
            }

            launchReporter.Finish(new FinishLaunchRequest {
                EndTime = DateTime.UtcNow
            });

            launchReporter.Sync();
        }
예제 #11
0
        public void FinishTestItemWhenChildTestItemIsNotScheduledToFinish()
        {
            var service = new MockServiceBuilder().Build();

            var launch = new LaunchReporter(service.Object, null, null, new Mock <IExtensionManager>().Object);

            launch.Start(new StartLaunchRequest {
            });
            var test      = launch.StartChildTestReporter(new StartTestItemRequest());
            var innerTest = test.StartChildTestReporter(new StartTestItemRequest());

            var exp = Assert.Throws <InsufficientExecutionStackException>(() => test.Finish(new FinishTestItemRequest()));

            Assert.Contains("are not scheduled to finish yet", exp.Message);
        }
예제 #12
0
        public async Task UseExistingLaunchId()
        {
            var launchDateTime = DateTime.UtcNow;

            var launch = await _service.Launch.StartAsync(new StartLaunchRequest
            {
                Name      = "UseExistingLaunchId",
                StartTime = launchDateTime,
                Mode      = LaunchMode.Debug
            });

            var config = new ConfigurationBuilder().Build();

            config.Properties["Launch:Id"] = launch.Uuid;

            var launchReporter = new LaunchReporter(_service, config, null, new ExtensionManager());

            launchReporter.Start(new StartLaunchRequest
            {
                Name      = "SomeOtherName",
                StartTime = launchDateTime.AddDays(1)
            });
            launchReporter.Finish(new FinishLaunchRequest
            {
                EndTime = DateTime.UtcNow
            });

            launchReporter.Sync();

            Assert.Equal(launch.Uuid, launchReporter.Info.Uuid);
            Assert.Equal(launchDateTime.ToString(), launchReporter.Info.StartTime.ToString());

            var reportedLaunch = await _service.Launch.GetAsync(launch.Uuid);

            Assert.Equal("UseExistingLaunchId", reportedLaunch.Name);
            Assert.Equal(launchDateTime.ToString(), reportedLaunch.StartTime.ToString());

            await _service.Launch.FinishAsync(launch.Uuid, new FinishLaunchRequest
            {
                EndTime = DateTime.UtcNow
            });

            var gotLaunch = await _service.Launch.GetAsync(launchReporter.Info.Uuid);

            await _service.Launch.DeleteAsync(gotLaunch.Id);
        }
예제 #13
0
        public void LaunchShouldCareOfFinishTime()
        {
            var launchStartTime = DateTime.UtcNow;

            var service = new MockServiceBuilder().Build();

            var launch = new LaunchReporter(service.Object, null, null, new ExtensionManager());

            launch.Start(new StartLaunchRequest()
            {
                StartTime = launchStartTime
            });
            launch.Finish(new FinishLaunchRequest()
            {
                EndTime = launchStartTime.AddDays(-1)
            });
            launch.Sync();

            launch.Info.FinishTime.Should().Be(launch.Info.StartTime);
        }
예제 #14
0
        public void ShouldBeAbleToLogIntoLaunch()
        {
            var service = new MockServiceBuilder().Build();

            var launch = new LaunchReporter(service.Object, null, null, new ExtensionManager());

            launch.Start(new StartLaunchRequest()
            {
                StartTime = DateTime.UtcNow
            });
            launch.Log(new CreateLogItemRequest {
                Time = DateTime.UtcNow, Text = "log"
            });
            launch.Finish(new FinishLaunchRequest()
            {
                EndTime = DateTime.UtcNow
            });
            launch.Sync();

            service.Verify(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>()), Times.Once);
        }
예제 #15
0
        public async Task UseExistingLaunchId()
        {
            var launchDateTime = DateTime.UtcNow;

            var launch = await _service.StartLaunchAsync(new Client.Requests.StartLaunchRequest
            {
                Name      = "UseExistingLaunchId",
                StartTime = launchDateTime,
                Mode      = Client.Models.LaunchMode.Debug
            });

            var launchReporter = new LaunchReporter(_service, launch.Id);

            launchReporter.Start(new Client.Requests.StartLaunchRequest
            {
                Name      = "SomeOtherName",
                StartTime = launchDateTime.AddDays(1)
            });
            launchReporter.Finish(new Client.Requests.FinishLaunchRequest
            {
                EndTime = DateTime.UtcNow
            });

            launchReporter.FinishTask.Wait();

            Assert.Equal(launch.Id, launchReporter.LaunchInfo.Id);
            Assert.Equal(launchDateTime.ToString(), launchReporter.LaunchInfo.StartTime.ToString());

            var reportedLaunch = await _service.GetLaunchAsync(launch.Id);

            Assert.Equal("UseExistingLaunchId", reportedLaunch.Name);
            Assert.Equal(launchDateTime.ToString(), reportedLaunch.StartTime.ToString());

            await _service.FinishLaunchAsync(launch.Id, new Client.Requests.FinishLaunchRequest
            {
                EndTime = DateTime.UtcNow
            });

            await _service.DeleteLaunchAsync(launch.Id);
        }
예제 #16
0
        public void FailedLaunchLogShouldNotBreakReporting()
        {
            var service = new MockServiceBuilder().Build();

            service.Setup(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest>())).Throws(new Exception());

            var launch = new LaunchReporter(service.Object, null, null, new ExtensionManager());

            launch.Start(new StartLaunchRequest()
            {
                StartTime = DateTime.UtcNow
            });
            launch.Log(new CreateLogItemRequest {
                Time = DateTime.UtcNow, Text = "log"
            });
            launch.Finish(new FinishLaunchRequest()
            {
                EndTime = DateTime.UtcNow
            });

            launch.Sync();
        }
        public bool StartLaunch(string launchName, Mode mode, string tags)
        {
            try
            {
                var launchRequest = new StartLaunchRequest()
                {
                    Name      = launchName,
                    StartTime = DateTime.UtcNow,
                    Mode      = (LaunchMode)mode,
                    Tags      = SplitOnTags(tags)
                };

                _launchReporter.Start(launchRequest);
                ReportSuccess(nameof(StartLaunch));
                return(true);
            }
            catch (Exception ex)
            {
                ReportError(nameof(StartLaunch), ex);
                return(false);
            }
        }
예제 #18
0
        public void LaunchReporter()
        {
            var configuration = new Configuration.ConfigurationBuilder().Build();

            var nopService     = new NopService();
            var launchReporter = new LaunchReporter(nopService, configuration, null, new ExtensionManager());

            var launchDateTime = DateTime.UtcNow;

            launchReporter.Start(new StartLaunchRequest
            {
                Name      = "ReportPortal Benchmark",
                StartTime = launchDateTime,
                Mode      = LaunchMode.Debug
            });

            for (int i = 0; i < SuitesCount; i++)
            {
                var suiteNode = launchReporter.StartChildTestReporter(new StartTestItemRequest
                {
                    Name      = $"Suite {i}",
                    StartTime = launchDateTime.AddMilliseconds(-1),
                    Type      = TestItemType.Suite
                });

                suiteNode.Finish(new FinishTestItemRequest
                {
                    EndTime = launchDateTime,
                    Status  = Status.Passed
                });
            }

            launchReporter.Finish(new FinishLaunchRequest
            {
                EndTime = launchDateTime
            });

            launchReporter.Sync();
        }
        public void LaunchReporter()
        {
            var nopService     = new NopService(new Uri("https://rp.epam.com/api/v1/"), "", "");
            var launchReporter = new LaunchReporter(nopService);

            var launchDateTime = DateTime.UtcNow;

            launchReporter.Start(new Client.Requests.StartLaunchRequest
            {
                Name      = "ReportPortal Benchmark",
                StartTime = launchDateTime,
                Mode      = Client.Models.LaunchMode.Debug,
                Tags      = new System.Collections.Generic.List <string>()
            });

            for (int i = 0; i < SuitesCount; i++)
            {
                var suiteNode = launchReporter.StartChildTestReporter(new Client.Requests.StartTestItemRequest
                {
                    Name      = $"Suite {i}",
                    StartTime = launchDateTime.AddMilliseconds(-1),
                    Type      = Client.Models.TestItemType.Suite
                });

                suiteNode.Finish(new Client.Requests.FinishTestItemRequest
                {
                    EndTime = launchDateTime,
                    Status  = Client.Models.Status.Passed
                });
            }

            launchReporter.Finish(new Client.Requests.FinishLaunchRequest
            {
                EndTime = launchDateTime
            });

            launchReporter.FinishTask.Wait();
        }
예제 #20
0
        public void RerunLaunch()
        {
            var service = new MockServiceBuilder().Build();

            var config = new Shared.Configuration.ConfigurationBuilder().Build();

            config.Properties["Launch:RerunOf"] = "any_uuid_of_existing_launch";

            var launch = new LaunchReporter(service.Object, config, null, new Mock <IExtensionManager>().Object);

            launch.Start(new StartLaunchRequest()
            {
                StartTime = DateTime.UtcNow
            });
            launch.Finish(new FinishLaunchRequest()
            {
                EndTime = DateTime.UtcNow
            });
            launch.Sync();

            service.Verify(s => s.Launch.StartAsync(It.IsAny <StartLaunchRequest>()), Times.Once);
            service.Verify(s => s.Launch.FinishAsync(It.IsAny <string>(), It.IsAny <FinishLaunchRequest>()), Times.Never);
        }
예제 #21
0
        public void ShouldNotLogIfLaunchFailedToStart()
        {
            var service = new MockServiceBuilder().Build();

            service.Setup(s => s.Launch.StartAsync(It.IsAny <StartLaunchRequest>())).Throws(new Exception());

            var launch = new LaunchReporter(service.Object, null, null, new ExtensionManager());

            launch.Start(new StartLaunchRequest()
            {
                StartTime = DateTime.UtcNow
            });

            launch.Log(new CreateLogItemRequest {
                Time = DateTime.UtcNow, Text = "log"
            });

            Action waitAct = () => launch.Sync();

            waitAct.Should().Throw <Exception>();

            service.Verify(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest>()), Times.Never);
        }
예제 #22
0
        static void Main(string[] args)
        {
            var port = Convert.ToInt32(Environment.GetEnvironmentVariable("plugin_connection_port"));

            var rpUri     = new Uri(ReadEnvVariable("rp_uri"));
            var rpProject = ReadEnvVariable("rp_project");
            var rpUuid    = ReadEnvVariable("rp_uuid");

            var service        = new Service(rpUri, rpProject, rpUuid);
            var launchReporter = new LaunchReporter(service);

            using (var gaugeConnection = new GaugeConnection(new TcpClientWrapper(port)))
            {
                while (gaugeConnection.Connected)
                {
                    var message = Message.Parser.ParseFrom(gaugeConnection.ReadBytes().ToArray());

                    if (message.MessageType == Message.Types.MessageType.SuiteExecutionResult)
                    {
                        var suiteExecutionResult = message.SuiteExecutionResult.SuiteResult;

                        launchReporter.Start(new Client.Requests.StartLaunchRequest
                        {
                            Name      = suiteExecutionResult.ProjectName,
                            Tags      = suiteExecutionResult.Tags.Select(t => t.ToString()).ToList(),
                            StartTime = DateTime.UtcNow
                        });

                        foreach (var specResult in suiteExecutionResult.SpecResults)
                        {
                            var specReporter = launchReporter.StartNewTestNode(new Client.Requests.StartTestItemRequest
                            {
                                Type        = Client.Models.TestItemType.Suite,
                                Name        = specResult.ProtoSpec.SpecHeading,
                                Description = string.Join("", specResult.ProtoSpec.Items.Where(i => i.ItemType == ProtoItem.Types.ItemType.Comment).Select(c => c.Comment.Text)),
                                StartTime   = DateTime.UtcNow,
                                Tags        = specResult.ProtoSpec.Tags.Select(t => t.ToString()).ToList()
                            });

                            foreach (var scenarioResult in specResult.ProtoSpec.Items.Where(i => i.ItemType == ProtoItem.Types.ItemType.Scenario))
                            {
                                var scenarioReporter = specReporter.StartNewTestNode(new Client.Requests.StartTestItemRequest
                                {
                                    Type        = Client.Models.TestItemType.Step,
                                    StartTime   = DateTime.UtcNow,
                                    Name        = scenarioResult.Scenario.ScenarioHeading,
                                    Description = string.Join("", scenarioResult.Scenario.ScenarioItems.Where(i => i.ItemType == ProtoItem.Types.ItemType.Comment).Select(c => c.Comment.Text)),
                                    Tags        = scenarioResult.Scenario.Tags.Select(t => t.ToString()).ToList()
                                });

                                foreach (var scenarioContext in scenarioResult.Scenario.Contexts)
                                {
                                    scenarioReporter.Log(new Client.Requests.AddLogItemRequest
                                    {
                                        Level = Client.Models.LogLevel.Info,
                                        Time  = DateTime.UtcNow,
                                        Text  = scenarioContext.Step.ActualText
                                    });
                                }

                                foreach (var stepResult in scenarioResult.Scenario.ScenarioItems.Where(i => i.ItemType == ProtoItem.Types.ItemType.Step))
                                {
                                    var text = stepResult.Step.ActualText;

                                    scenarioReporter.Log(new Client.Requests.AddLogItemRequest
                                    {
                                        Level = Client.Models.LogLevel.Info,
                                        Time  = DateTime.UtcNow,
                                        Text  = text
                                    });
                                }

                                scenarioReporter.Finish(new Client.Requests.FinishTestItemRequest
                                {
                                    EndTime = DateTime.UtcNow,
                                    Status  = _statusMap[scenarioResult.Scenario.ExecutionStatus]
                                });
                            }

                            specReporter.Finish(new Client.Requests.FinishTestItemRequest
                            {
                                Status  = Client.Models.Status.Passed,
                                EndTime = DateTime.UtcNow
                            });
                        }

                        launchReporter.Finish(new Client.Requests.FinishLaunchRequest
                        {
                            EndTime = DateTime.UtcNow
                        });
                    }

                    if (message.MessageType == Message.Types.MessageType.KillProcessRequest)
                    {
                        Console.Write("Finishing to send results to Report Portal... ");
                        var sw = Stopwatch.StartNew();
                        launchReporter.FinishTask?.Wait();

                        Console.WriteLine($"Elapsed: {sw.Elapsed}");

                        return;
                    }
                }
            }
        }
예제 #23
0
        public async Task UseRerunLaunchId()
        {
            var launchDateTime = DateTime.UtcNow;
            var launchName     = "UseRerunLaunchId";

            var launch = await _service.Launch.StartAsync(new StartLaunchRequest
            {
                Name      = launchName,
                StartTime = launchDateTime,
                Mode      = LaunchMode.Debug
            });

            var config = new ConfigurationBuilder().Build();

            config.Properties["Launch:RerunOf"] = launch.Uuid;

            var tasks = new List <Task <LaunchReporter> >();

            for (int i = 0; i < 3; i++)
            {
                tasks.Add(Task.Run(() =>
                {
                    var r_launch = new LaunchReporter(_service, config, null, null);

                    r_launch.Start(new StartLaunchRequest
                    {
                        Name      = "UseRerunLaunchId",
                        StartTime = launchDateTime,
                        Mode      = LaunchMode.Debug
                    });

                    for (int j = 0; j < 30; j++)
                    {
                        var r_suiteReporter = r_launch.StartChildTestReporter(new StartTestItemRequest
                        {
                            Name      = $"Suite {j}",
                            StartTime = launchDateTime,
                            Type      = TestItemType.Suite
                        });

                        for (int jj = 0; jj < 3; jj++)
                        {
                            var rr_suiteReporter = r_suiteReporter.StartChildTestReporter(new StartTestItemRequest
                            {
                                Name      = $"Suite {jj}",
                                StartTime = launchDateTime,
                                Type      = TestItemType.Suite
                            });

                            for (int k = 0; k < 0; k++)
                            {
                                var r_test = rr_suiteReporter.StartChildTestReporter(new StartTestItemRequest
                                {
                                    Name      = $"Test {k}",
                                    StartTime = launchDateTime,
                                    Type      = TestItemType.Step
                                });

                                for (int l = 0; l < 0; l++)
                                {
                                    r_test.Log(new CreateLogItemRequest
                                    {
                                        Level = LogLevel.Info,
                                        Text  = $"Log message #{l}",
                                        Time  = launchDateTime
                                    });
                                }

                                r_test.Finish(new FinishTestItemRequest
                                {
                                    EndTime = launchDateTime,
                                    Status  = Status.Passed
                                });
                            }

                            rr_suiteReporter.Finish(new FinishTestItemRequest
                            {
                                EndTime = launchDateTime,
                                Status  = Status.Passed
                            });
                        }

                        r_suiteReporter.Finish(new FinishTestItemRequest
                        {
                            EndTime = launchDateTime,
                            Status  = Status.Passed
                        });
                    }

                    r_launch.Finish(new FinishLaunchRequest
                    {
                        EndTime = launchDateTime
                    });

                    r_launch.Sync();

                    return(r_launch);
                }));
            }

            Task.WaitAll(tasks.ToArray());

            var reportedLaunch = await _service.Launch.GetAsync(launch.Uuid);

            Assert.Equal(launchName, reportedLaunch.Name);
            Assert.Equal(launchDateTime.ToString(), reportedLaunch.StartTime.ToString());

            await _service.Launch.FinishAsync(launch.Uuid, new FinishLaunchRequest
            {
                EndTime = DateTime.UtcNow
            });

            //var gotLaunch = await _service.Launch.GetAsync(launchReporter.LaunchInfo.Uuid);

            //await _service.Launch.DeleteAsync(gotLaunch.Id);
        }
예제 #24
0
        public async Task UseRerun()
        {
            var launchDateTime = DateTime.UtcNow;
            var launchName     = "UseRerun";

            var launch = await _service.Launch.StartAsync(new StartLaunchRequest
            {
                Name      = launchName,
                StartTime = launchDateTime,
                Mode      = LaunchMode.Debug
            });

            await _service.Launch.FinishAsync(launch.Uuid, new FinishLaunchRequest
            {
                EndTime = DateTime.UtcNow
            });

            var config = new ConfigurationBuilder().Build();

            config.Properties["Launch:Rerun"] = true;


            var r_launch = new LaunchReporter(_service, config, null, new ExtensionManager());

            r_launch.Start(new StartLaunchRequest
            {
                Name      = "UseRerun",
                StartTime = launchDateTime,
                Mode      = LaunchMode.Debug
            });

            for (int j = 0; j < 1; j++)
            {
                var r_suiteReporter = r_launch.StartChildTestReporter(new StartTestItemRequest
                {
                    Name      = $"Suite {j}",
                    StartTime = launchDateTime,
                    Type      = TestItemType.Suite
                });

                for (int jj = 0; jj < 1; jj++)
                {
                    var rr_suiteReporter = r_suiteReporter.StartChildTestReporter(new StartTestItemRequest
                    {
                        Name      = $"Suite {jj}",
                        StartTime = launchDateTime,
                        Type      = TestItemType.Suite
                    });

                    for (int k = 0; k < 10; k++)
                    {
                        var r_test = rr_suiteReporter.StartChildTestReporter(new StartTestItemRequest
                        {
                            Name      = $"Test {k}",
                            StartTime = launchDateTime,
                            Type      = TestItemType.Step
                        });

                        for (int l = 0; l < 0; l++)
                        {
                            r_test.Log(new CreateLogItemRequest
                            {
                                Level = LogLevel.Info,
                                Text  = $"Log message #{l}",
                                Time  = launchDateTime
                            });
                        }

                        r_test.Finish(new FinishTestItemRequest
                        {
                            EndTime = launchDateTime,
                            Status  = Status.Passed
                        });
                    }

                    rr_suiteReporter.Finish(new FinishTestItemRequest
                    {
                        EndTime = launchDateTime,
                        Status  = Status.Passed
                    });
                }

                r_suiteReporter.Finish(new FinishTestItemRequest
                {
                    EndTime = launchDateTime,
                    Status  = Status.Passed
                });
            }

            r_launch.Finish(new FinishLaunchRequest
            {
                EndTime = launchDateTime
            });

            r_launch.Sync();

            var reportedLaunch = await _service.Launch.GetAsync(r_launch.Info.Uuid);

            Assert.Equal(launchName, reportedLaunch.Name);
            Assert.Equal(launchDateTime.ToString(), reportedLaunch.StartTime.ToString());

            var gotLaunch = await _service.Launch.GetAsync(r_launch.Info.Uuid);

            await _service.Launch.DeleteAsync(gotLaunch.Id);
        }
예제 #25
0
        public LaunchReporter Build(int suitesPerLaunch, int testsPerSuite, int logsPerTest)
        {
            var launchReporter = new LaunchReporter(Service, null, RequestExecuterFactory?.Create(), ExtensionManager);

            var launchDateTime = DateTime.UtcNow;

            launchReporter.Start(new StartLaunchRequest
            {
                Name      = "ReportPortal Shared",
                StartTime = launchDateTime,
                Mode      = LaunchMode.Debug
            });

            for (int i = 0; i < suitesPerLaunch; i++)
            {
                var suiteNode = launchReporter.StartChildTestReporter(new StartTestItemRequest
                {
                    Name      = $"Suite {i}",
                    StartTime = launchDateTime.AddMilliseconds(-1),
                    Type      = TestItemType.Suite
                });

                for (int j = 0; j < testsPerSuite; j++)
                {
                    var testNode = suiteNode.StartChildTestReporter(new StartTestItemRequest
                    {
                        Name      = $"Test {j}",
                        StartTime = launchDateTime,
                        Type      = TestItemType.Step
                    });

                    for (int l = 0; l < logsPerTest; l++)
                    {
                        testNode.Log(new CreateLogItemRequest
                        {
                            Level = LogLevel.Info,
                            Text  = $"Log message #{l}",
                            Time  = launchDateTime
                        });
                    }

                    testNode.Finish(new FinishTestItemRequest
                    {
                        EndTime = launchDateTime,
                        Status  = Status.Passed
                    });
                }

                suiteNode.Finish(new FinishTestItemRequest
                {
                    EndTime = launchDateTime,
                    Status  = Status.Passed
                });
            }

            launchReporter.Finish(new FinishLaunchRequest
            {
                EndTime = launchDateTime
            });

            return(launchReporter);
        }
        public LaunchReporter Build(int suitesPerLaunch, int testsPerSuite, int logsPerTest)
        {
            var launchReporter = new LaunchReporter(Service);

            var launchDateTime = DateTime.UtcNow;

            launchReporter.Start(new Client.Requests.StartLaunchRequest
            {
                Name      = "ReportPortal Shared",
                StartTime = launchDateTime,
                Mode      = Client.Models.LaunchMode.Debug,
                Tags      = new System.Collections.Generic.List <string>()
            });

            for (int i = 0; i < suitesPerLaunch; i++)
            {
                var suiteNode = launchReporter.StartChildTestReporter(new Client.Requests.StartTestItemRequest
                {
                    Name      = $"Suite {i}",
                    StartTime = launchDateTime.AddMilliseconds(-1),
                    Type      = Client.Models.TestItemType.Suite
                });

                for (int j = 0; j < testsPerSuite; j++)
                {
                    var testNode = suiteNode.StartChildTestReporter(new Client.Requests.StartTestItemRequest
                    {
                        Name      = $"Test {j}",
                        StartTime = launchDateTime,
                        Type      = Client.Models.TestItemType.Step
                    });

                    for (int l = 0; l < logsPerTest; l++)
                    {
                        testNode.Log(new Client.Requests.AddLogItemRequest
                        {
                            Level = Client.Models.LogLevel.Info,
                            Text  = $"Log message #{l}",
                            Time  = launchDateTime
                        });
                    }

                    testNode.Finish(new Client.Requests.FinishTestItemRequest
                    {
                        EndTime = launchDateTime,
                        Status  = Client.Models.Status.Passed
                    });
                }

                suiteNode.Finish(new Client.Requests.FinishTestItemRequest
                {
                    EndTime = launchDateTime,
                    Status  = Client.Models.Status.Passed
                });
            }

            launchReporter.Finish(new Client.Requests.FinishLaunchRequest
            {
                EndTime = launchDateTime
            });

            return(launchReporter);
        }
예제 #27
0
        static void Main(string[] args)
        {
            var port = Convert.ToInt32(Environment.GetEnvironmentVariable("plugin_connection_port"));

            var rpUri     = new Uri(Config.GetValue <string>("Uri"));
            var rpProject = Config.GetValue <string>("Project");
            var rpUuid    = Config.GetValue <string>("Uuid");

            var service        = new Service(rpUri, rpProject, rpUuid);
            var launchReporter = new LaunchReporter(service, Config, requestExecuterFactory: null);

            using (var gaugeConnection = new GaugeConnection(new TcpClientWrapper(port)))
            {
                while (gaugeConnection.Connected)
                {
                    var message = Message.Parser.ParseFrom(gaugeConnection.ReadBytes().ToArray());

                    if (message.MessageType == Message.Types.MessageType.SuiteExecutionResult)
                    {
                        var suiteExecutionResult = message.SuiteExecutionResult.SuiteResult;

                        var launchStartDateTime = DateTime.UtcNow.AddMilliseconds(-suiteExecutionResult.ExecutionTime);
                        launchReporter.Start(new Client.Requests.StartLaunchRequest
                        {
                            Name        = Config.GetValue("Launch:Name", suiteExecutionResult.ProjectName),
                            Description = Config.GetValue("Launch:Description", string.Empty),
                            Tags        = Config.GetValues("Launch:Tags", new List <string>()).ToList(),
                            StartTime   = launchStartDateTime
                        });

                        foreach (var specResult in suiteExecutionResult.SpecResults)
                        {
                            var specStartTime = launchStartDateTime;
                            var specReporter  = launchReporter.StartChildTestReporter(new Client.Requests.StartTestItemRequest
                            {
                                Type        = Client.Models.TestItemType.Suite,
                                Name        = specResult.ProtoSpec.SpecHeading,
                                Description = string.Join("", specResult.ProtoSpec.Items.Where(i => i.ItemType == ProtoItem.Types.ItemType.Comment).Select(c => c.Comment.Text)),
                                StartTime   = specStartTime,
                                Tags        = specResult.ProtoSpec.Tags.Select(t => t.ToString()).ToList()
                            });

                            foreach (var scenarioResult in specResult.ProtoSpec.Items.Where(i => i.ItemType == ProtoItem.Types.ItemType.Scenario || i.ItemType == ProtoItem.Types.ItemType.TableDrivenScenario))
                            {
                                ProtoScenario scenario;

                                switch (scenarioResult.ItemType)
                                {
                                case ProtoItem.Types.ItemType.Scenario:
                                    scenario = scenarioResult.Scenario;
                                    break;

                                case ProtoItem.Types.ItemType.TableDrivenScenario:
                                    scenario = scenarioResult.TableDrivenScenario.Scenario;
                                    break;

                                default:
                                    scenario = scenarioResult.Scenario;
                                    break;
                                }

                                var scenarioStartTime = specStartTime;
                                var scenarioReporter  = specReporter.StartChildTestReporter(new Client.Requests.StartTestItemRequest
                                {
                                    Type        = Client.Models.TestItemType.Step,
                                    StartTime   = scenarioStartTime,
                                    Name        = scenario.ScenarioHeading,
                                    Description = string.Join("", scenario.ScenarioItems.Where(i => i.ItemType == ProtoItem.Types.ItemType.Comment).Select(c => c.Comment.Text)),
                                    Tags        = scenario.Tags.Select(t => t.ToString()).ToList()
                                });

                                // internal log ("rp_log_enabled" property)
                                if (Config.GetValue("log:enabled", false))
                                {
                                    scenarioReporter.Log(new Client.Requests.AddLogItemRequest
                                    {
                                        Text   = "Spec Result Proto",
                                        Level  = Client.Models.LogLevel.Trace,
                                        Time   = DateTime.UtcNow,
                                        Attach = new Client.Models.Attach("Spec", "application/json", System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(specResult)))
                                    });
                                    scenarioReporter.Log(new Client.Requests.AddLogItemRequest
                                    {
                                        Text   = "Scenario Result Proto",
                                        Level  = Client.Models.LogLevel.Trace,
                                        Time   = DateTime.UtcNow,
                                        Attach = new Client.Models.Attach("Scenario", "application/json", System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(scenarioResult)))
                                    });
                                }

                                var lastStepStartTime = scenarioStartTime;
                                if (scenario.ScenarioItems != null)
                                {
                                    foreach (var stepResult in scenario.ScenarioItems.Where(i => i.ItemType == ProtoItem.Types.ItemType.Step))
                                    {
                                        var text         = "!!!MARKDOWN_MODE!!!" + stepResult.Step.ActualText;
                                        var stepLogLevel = stepResult.Step.StepExecutionResult.ExecutionResult.Failed ? Client.Models.LogLevel.Error : Client.Models.LogLevel.Info;

                                        // if step argument is table
                                        var tableParameter = stepResult.Step.Fragments.FirstOrDefault(f => f.Parameter?.Table != null)?.Parameter.Table;
                                        if (tableParameter != null)
                                        {
                                            text += Environment.NewLine + Environment.NewLine + "| " + string.Join(" | ", tableParameter.Headers.Cells.ToArray()) + " |";
                                            text += Environment.NewLine + "| " + string.Join(" | ", tableParameter.Headers.Cells.Select(c => "---")) + " |";

                                            foreach (var tableRow in tableParameter.Rows)
                                            {
                                                text += Environment.NewLine + "| " + string.Join(" | ", tableRow.Cells.ToArray()) + " |";
                                            }
                                        }

                                        // if dynamic arguments
                                        var dynamicParameteres = stepResult.Step.Fragments.Where(f => f.FragmentType == Fragment.Types.FragmentType.Parameter && f.Parameter.ParameterType == Parameter.Types.ParameterType.Dynamic).Select(f => f.Parameter);
                                        if (dynamicParameteres.Count() != 0)
                                        {
                                            text += Environment.NewLine;

                                            foreach (var dynamicParameter in dynamicParameteres)
                                            {
                                                text += $"{Environment.NewLine}{dynamicParameter.Name}: {dynamicParameter.Value}";
                                            }
                                        }

                                        if (stepResult.Step.StepExecutionResult.ExecutionResult.Failed)
                                        {
                                            text += $"{Environment.NewLine}{Environment.NewLine}{stepResult.Step.StepExecutionResult.ExecutionResult.ErrorMessage}{Environment.NewLine}{stepResult.Step.StepExecutionResult.ExecutionResult.StackTrace}";
                                        }

                                        scenarioReporter.Log(new Client.Requests.AddLogItemRequest
                                        {
                                            Level = stepLogLevel,
                                            Time  = lastStepStartTime,
                                            Text  = text
                                        });

                                        if (stepResult.Step.StepExecutionResult.ExecutionResult.ScreenShot?.Length != 0)
                                        {
                                            scenarioReporter.Log(new Client.Requests.AddLogItemRequest
                                            {
                                                Level  = Client.Models.LogLevel.Debug,
                                                Time   = lastStepStartTime,
                                                Text   = "Screenshot",
                                                Attach = new Client.Models.Attach("Screenshot", "image/png", stepResult.Step.StepExecutionResult.ExecutionResult.ScreenShot.ToByteArray())
                                            });
                                        }

                                        lastStepStartTime = lastStepStartTime.AddMilliseconds(stepResult.Step.StepExecutionResult.ExecutionResult.ExecutionTime);
                                    }
                                }

                                scenarioReporter.Finish(new Client.Requests.FinishTestItemRequest
                                {
                                    EndTime = scenarioStartTime.AddMilliseconds(scenario.ExecutionTime),
                                    Status  = _statusMap[scenario.ExecutionStatus]
                                });
                            }

                            var specFinishStatus = specResult.Failed ? Client.Models.Status.Failed : Client.Models.Status.Passed;
                            specReporter.Finish(new Client.Requests.FinishTestItemRequest
                            {
                                Status  = specFinishStatus,
                                EndTime = specStartTime.AddMilliseconds(specResult.ExecutionTime)
                            });
                        }

                        launchReporter.Finish(new Client.Requests.FinishLaunchRequest
                        {
                            EndTime = DateTime.UtcNow
                        });
                    }

                    if (message.MessageType == Message.Types.MessageType.KillProcessRequest)
                    {
                        Console.Write("Finishing to send results to Report Portal... ");
                        var sw = Stopwatch.StartNew();
                        launchReporter.Sync();

                        Console.WriteLine($"Elapsed: {sw.Elapsed}");

                        return;
                    }
                }
            }
        }