public void ShouldSendAsSeparateRequestPerLogWithAttachmentIncludingWithoutAttachment() { var service = new MockServiceBuilder().Build(); var logsReporter = new LogsReporter(_testReporter.Object, service.Object, _extensionManager, _requestExecuter, _logRequestAmender.Object); var withoutAttachment = new CreateLogItemRequest { Text = "a", Time = DateTime.UtcNow }; var withAttachment = new CreateLogItemRequest { Text = "a", Time = DateTime.UtcNow, Attach = new LogItemAttach() }; logsReporter.Log(withAttachment); logsReporter.Log(withoutAttachment); logsReporter.Log(withAttachment); logsReporter.Log(withoutAttachment); logsReporter.Sync(); service.Verify(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>()), Times.Exactly(2)); }
public void ShouldNotifyAfterItemStarted() { ILaunchReporter l = null; ITestReporter t = null; AfterLaunchStartedEventArgs afterLaunchStartedEventArgs = null; AfterTestStartedEventArgs afterTestStartedEventArgs = null; var observer = new Mock <IReportEventsObserver>(); observer.Setup(o => o.Initialize(It.IsAny <IReportEventsSource>())).Callback <IReportEventsSource>(s => { s.OnAfterLaunchStarted += (a, b) => { l = a; afterLaunchStartedEventArgs = b; }; s.OnAfterTestStarted += (a, b) => { t = a; afterTestStartedEventArgs = b; }; }); var extManager = new Shared.Extensibility.ExtensionManager(); extManager.ReportEventObservers.Add(observer.Object); var client = new MockServiceBuilder().Build().Object; var launch = new LaunchReporterBuilder(client).With(extManager).Build(1, 0, 0); launch.Sync(); afterLaunchStartedEventArgs.ClientService.Should().BeSameAs(client); l.Should().BeSameAs(launch); afterTestStartedEventArgs.ClientService.Should().BeSameAs(client); t.Should().BeSameAs(launch.ChildTestReporters[0]); }
public void ShouldNotBreakReportingIfHandlerThrowsException() { var observer = new Mock <IReportEventsObserver>(); observer.Setup(o => o.Initialize(It.IsAny <IReportEventsSource>())).Callback <IReportEventsSource>(s => { s.OnBeforeLaunchStarting += (a, b) => throw new Exception(); s.OnAfterLaunchStarted += (a, b) => throw new Exception(); s.OnBeforeLaunchFinishing += (a, b) => throw new Exception(); s.OnAfterLaunchFinished += (a, b) => throw new Exception(); s.OnBeforeTestStarting += (a, b) => throw new Exception(); s.OnAfterTestStarted += (a, b) => throw new Exception(); s.OnBeforeTestFinishing += (a, b) => throw new Exception(); s.OnAfterTestFinished += (a, b) => throw new Exception(); }); var extManager = new Shared.Extensibility.ExtensionManager(); extManager.ReportEventObservers.Add(observer.Object); var client = new MockServiceBuilder().Build().Object; var launch = new LaunchReporterBuilder(client).With(extManager).Build(1, 0, 0); Action act = () => launch.Sync(); act.Should().NotThrow(); }
public async Task RetryDoesNotExceedSuccess() { var helper = new MockServiceBuilder("localhost"); int callCount = 0; helper.UnaryHandler = new UnaryServerMethod <string, string>((request, context) => { callCount++; if (callCount == 1) { context.Status = new Status(StatusCode.Cancelled, ""); } return(Task.FromResult("ok")); }); var server = helper.GetServer(); server.Start(); var callInvoker = helper.GetChannel().Intercept(new RetryInterceptor()); var metadata = new Metadata { { GrpcConstants.RetryCountMetadataKey, "5" } }; await callInvoker.AsyncUnaryCall(new Method <string, string>(MethodType.Unary, MockServiceBuilder.ServiceName, "Unary", Marshallers.StringMarshaller, Marshallers.StringMarshaller), "localhost", new CallOptions().WithHeaders(metadata), ""); Assert.Equal(2, callCount); }
public void ShouldSendRequestsEvenIfPreviousFailed() { var service = new MockServiceBuilder().Build(); service.Setup(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>())).Throws <Exception>(); var logsReporter = new LogsReporter(_testReporter.Object, service.Object, _extensionManager, _requestExecuter, _logRequestAmender.Object); logsReporter.BatchCapacity = 1; for (int i = 0; i < 2; i++) { logsReporter.Log(new CreateLogItemRequest { Text = "a", Time = DateTime.UtcNow }); } try { logsReporter.Sync(); } catch (Exception) { } service.Verify(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>()), Times.Exactly(2)); }
public void StartLaunchScheduling() { var service = new MockServiceBuilder().Build(); var launchReporters = new List <Mock <LaunchReporter> >(); for (int i = 0; i < 1000; i++) { var launchReporter = new Mock <LaunchReporter>(service.Object); launchReporter.Object.Start(new Client.Requests.StartLaunchRequest { Name = $"ReportPortal Shared {i}", StartTime = DateTime.UtcNow }); launchReporters.Add(launchReporter); } for (int i = 0; i < 1000; i++) { var launchReporter = launchReporters[i]; Assert.NotNull(launchReporter.Object.StartTask); launchReporter.Object.Sync(); Assert.Equal($"ReportPortal Shared {i}", launchReporter.Object.LaunchInfo.Name); } service.Verify(s => s.StartLaunchAsync(It.IsAny <Client.Requests.StartLaunchRequest>()), Times.Exactly(1000)); }
public void ShouldBeThreadSafeWhenSchedulingLogRequests() { var logItemRequestTexts = new List <string>(); var service = new MockServiceBuilder().Build(); service.Setup(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>())) .Callback <CreateLogItemRequest[]>(rqs => { foreach (var rq in rqs) { logItemRequestTexts.Add(rq.Text); } }) .Returns(() => Task.FromResult(new Client.Abstractions.Responses.LogItemsCreatedResponse())); var logsReporter = new LogsReporter(_testReporter.Object, service.Object, _extensionManager, _requestExecuter, _logRequestAmender.Object); Parallel.For(0, 1000, (i) => logsReporter.Log(new CreateLogItemRequest { Text = i.ToString(), Time = DateTime.UtcNow })); logsReporter.Sync(); service.Verify(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>()), Times.Exactly(100)); logItemRequestTexts.Should().HaveCount(1000); logItemRequestTexts.Should().OnlyHaveUniqueItems(); }
public void ShouldNotifyBeforeItemFinishing() { ILaunchReporter l = null; ITestReporter t = null; BeforeLaunchFinishingEventArgs beforeLaunchFinishingEventArgs = null; BeforeTestFinishingEventArgs beforeTestFinishingEventArgs = null; var observer = new Mock <IReportEventsObserver>(); observer.Setup(o => o.Initialize(It.IsAny <IReportEventsSource>())).Callback <IReportEventsSource>(s => { s.OnBeforeLaunchFinishing += (a, b) => { l = a; beforeLaunchFinishingEventArgs = b; }; s.OnBeforeTestFinishing += (a, b) => { t = a; beforeTestFinishingEventArgs = b; }; }); var extManager = new Shared.Extensibility.ExtensionManager(); extManager.ReportEventObservers.Add(observer.Object); var client = new MockServiceBuilder().Build().Object; var launch = new LaunchReporterBuilder(client).With(extManager).Build(1, 0, 0); launch.Sync(); beforeLaunchFinishingEventArgs.ClientService.Should().BeSameAs(client); l.Should().BeSameAs(launch); beforeLaunchFinishingEventArgs.FinishLaunchRequest.Should().NotBeNull(); beforeTestFinishingEventArgs.ClientService.Should().BeSameAs(client); t.Should().BeSameAs(launch.ChildTestReporters[0]); beforeTestFinishingEventArgs.FinishTestItemRequest.Should().NotBeNull(); }
public void FinishLaunchWhichIsNotStarted() { var service = new MockServiceBuilder().Build(); var launch = new LaunchReporter(service.Object, null, null, new ExtensionManager()); launch.Invoking(l => l.Finish(new FinishLaunchRequest())).Should().Throw <InsufficientExecutionStackException>().And.Message.Should().Contain("wasn't scheduled for starting"); }
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>(); }
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"); }
public void CannotLogIfLaunchNotStarted() { var service = new MockServiceBuilder().Build(); var launch = new LaunchReporter(service.Object, null, null, new ExtensionManager()); Action act = () => launch.Log(new CreateLogItemRequest { Time = DateTime.UtcNow, Text = "log" }); act.Should().Throw <InsufficientExecutionStackException>().WithMessage("*launch wasn't scheduled for starting*"); }
public void ShouldInvokeHandleLogMethod() { var service = new MockServiceBuilder().Build(); var launchScheduler = new LaunchScheduler(service.Object); var launchReporter = launchScheduler.Build(1, 1, 1); launchReporter.Sync(); Assert.True(Invoked); }
public void StartLaunchTimeout() { var service = new MockServiceBuilder().Build(); service.Setup(s => s.Launch.StartAsync(It.IsAny <StartLaunchRequest>())).Throws <TaskCanceledException>(); var requestExecuterFactory = new MockRequestExecuterFactoryBuilder().Build(); var launchScheduler = new LaunchReporterBuilder(service.Object).With(requestExecuterFactory.Object); var launchReporter = launchScheduler.Build(1, 1, 1); var exp = Assert.ThrowsAny <Exception>(() => launchReporter.Sync()); }
public void SuccessReporting(int suitesPerLaunch, int testsPerSuite, int logsPerTest) { var service = new MockServiceBuilder().Build(); var launchScheduler = new LaunchScheduler(service.Object); var launchReporter = launchScheduler.Build(suitesPerLaunch, testsPerSuite, logsPerTest); launchReporter.Sync(); service.Verify(s => s.StartTestItemAsync(It.IsAny <Client.Requests.StartTestItemRequest>()), Times.Exactly(suitesPerLaunch)); service.Verify(s => s.StartTestItemAsync(null, It.IsAny <Client.Requests.StartTestItemRequest>()), Times.Exactly(testsPerSuite * suitesPerLaunch)); service.Verify(s => s.AddLogItemAsync(It.IsAny <Client.Requests.AddLogItemRequest>()), Times.Exactly(suitesPerLaunch * testsPerSuite * logsPerTest)); }
public void StartTestItemTimeout() { var service = new MockServiceBuilder().Build(); service.Setup(s => s.TestItem.StartAsync(It.IsAny <string>(), It.IsAny <StartTestItemRequest>())).Throws <TaskCanceledException>(); var launchScheduler = new LaunchReporterBuilder(service.Object).With(new MockRequestExecuterFactoryBuilder().Build().Object); var launchReporter = launchScheduler.Build(1, 1, 1); var exp = Assert.ThrowsAny <Exception>(() => launchReporter.Sync()); Assert.Contains("Cannot finish launch", exp.Message); }
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(); }
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); }
public void FailedLogsShouldNotAffectFinishingLaunch(int suitesPerLaunch, int testsPerSuite, int logsPerTest) { var service = new MockServiceBuilder().Build(); service.Setup(s => s.AddLogItemAsync(It.IsAny <Client.Requests.AddLogItemRequest>())).Throws <Exception>(); var launchScheduler = new LaunchScheduler(service.Object); var launchReporter = launchScheduler.Build(suitesPerLaunch, testsPerSuite, logsPerTest); launchReporter.Sync(); service.Verify(s => s.StartTestItemAsync(It.IsAny <Client.Requests.StartTestItemRequest>()), Times.Exactly(suitesPerLaunch)); service.Verify(s => s.StartTestItemAsync(null, It.IsAny <Client.Requests.StartTestItemRequest>()), Times.Exactly(testsPerSuite * suitesPerLaunch)); service.Verify(s => s.AddLogItemAsync(It.IsAny <Client.Requests.AddLogItemRequest>()), Times.Exactly(suitesPerLaunch * testsPerSuite * logsPerTest)); }
public void SuccessReporting(int suitesPerLaunch, int testsPerSuite, int logsPerTest) { var service = new MockServiceBuilder().Build(); var launchScheduler = new LaunchReporterBuilder(service.Object); var launchReporter = launchScheduler.Build(suitesPerLaunch, testsPerSuite, logsPerTest); launchReporter.Sync(); service.Verify(s => s.TestItem.StartAsync(It.IsAny <StartTestItemRequest>()), Times.Exactly(suitesPerLaunch)); service.Verify(s => s.TestItem.StartAsync(It.IsAny <string>(), It.IsAny <StartTestItemRequest>()), Times.Exactly(testsPerSuite * suitesPerLaunch)); service.Verify(s => s.TestItem.FinishAsync(It.IsAny <string>(), It.IsAny <FinishTestItemRequest>()), Times.Exactly(testsPerSuite * suitesPerLaunch + suitesPerLaunch)); launchReporter.ChildTestReporters.Select(s => s.Info.Uuid).Should().OnlyHaveUniqueItems(); launchReporter.ChildTestReporters.SelectMany(s => s.ChildTestReporters).Select(t => t.Info.Uuid).Should().OnlyHaveUniqueItems(); }
public void ShouldNotBreakReportingIfInitializtionThrowsException() { var observer = new Mock <IReportEventsObserver>(); observer.Setup(o => o.Initialize(It.IsAny <IReportEventsSource>())).Throws <Exception>(); var extManager = new Shared.Extensibility.ExtensionManager(); extManager.ReportEventObservers.Add(observer.Object); var client = new MockServiceBuilder().Build().Object; var launch = new LaunchReporterBuilder(client).With(extManager).Build(1, 0, 0); Action act = () => launch.Sync(); act.Should().NotThrow(); }
public void FailedStartSuiteItemShouldRaiseExceptionAtFinishLaunch(int suitesPerLaunch, int testsPerSuite, int logsPerTest) { var service = new MockServiceBuilder().Build(); service.Setup(s => s.StartTestItemAsync(It.IsAny <Client.Requests.StartTestItemRequest>())).Throws <Exception>(); var launchScheduler = new LaunchScheduler(service.Object); var launchReporter = launchScheduler.Build(suitesPerLaunch, testsPerSuite, logsPerTest); var exp = Assert.ThrowsAny <Exception>(() => launchReporter.Sync()); Assert.Contains("Cannot finish launch", exp.Message); service.Verify(s => s.StartTestItemAsync(It.IsAny <Client.Requests.StartTestItemRequest>()), Times.Exactly(suitesPerLaunch)); service.Verify(s => s.StartTestItemAsync(null, It.IsAny <Client.Requests.StartTestItemRequest>()), Times.Never); service.Verify(s => s.FinishTestItemAsync(null, It.IsAny <Client.Requests.FinishTestItemRequest>()), Times.Never); }
public void ShouldInvokeFormatLogMethod() { var service = new MockServiceBuilder().Build(); var logFormatter = new Mock <ILogFormatter>(); var extensionManager = new Mock <IExtensionManager>(); extensionManager.Setup(p => p.LogFormatters).Returns(new List <ILogFormatter> { logFormatter.Object }); var launchScheduler = new LaunchReporterBuilder(service.Object).With(extensionManager.Object); var launchReporter = launchScheduler.Build(1, 1, 1); launchReporter.Sync(); logFormatter.Verify(lf => lf.FormatLog(It.IsAny <CreateLogItemRequest>()), Times.Once); }
public void FailedLogsShouldNotAffectFinishingLaunch(int suitesPerLaunch, int testsPerSuite, int logsPerTest) { var service = new MockServiceBuilder().Build(); service.Setup(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>())).Throws <Exception>(); var requestExecuterFactory = new MockRequestExecuterFactoryBuilder().Build(); var launchScheduler = new LaunchReporterBuilder(service.Object).With(requestExecuterFactory.Object); var launchReporter = launchScheduler.Build(suitesPerLaunch, testsPerSuite, logsPerTest); launchReporter.Sync(); service.Verify(s => s.Launch.StartAsync(It.IsAny <StartLaunchRequest>()), Times.Exactly(1)); service.Verify(s => s.TestItem.StartAsync(It.IsAny <StartTestItemRequest>()), Times.Exactly(suitesPerLaunch)); service.Verify(s => s.TestItem.StartAsync(It.IsAny <string>(), It.IsAny <StartTestItemRequest>()), Times.Exactly(testsPerSuite * suitesPerLaunch)); service.Verify(s => s.TestItem.FinishAsync(It.IsAny <string>(), It.IsAny <FinishTestItemRequest>()), Times.Exactly(testsPerSuite * suitesPerLaunch + suitesPerLaunch)); service.Verify(s => s.Launch.FinishAsync(It.IsAny <string>(), It.IsAny <FinishLaunchRequest>()), Times.Once); }
public void FailedFinishTestItemShouldRaiseExceptionAtFinishLaunch(int suitesPerLaunch, int testsPerSuite, int logsPerTest) { var service = new MockServiceBuilder().Build(); service.Setup(s => s.TestItem.FinishAsync(It.IsAny <string>(), It.IsAny <FinishTestItemRequest>())).Throws(new Exception()); var requestExecuterFactory = new MockRequestExecuterFactoryBuilder().Build(); var launchScheduler = new LaunchReporterBuilder(service.Object).With(requestExecuterFactory.Object); var launchReporter = launchScheduler.Build(suitesPerLaunch, testsPerSuite, logsPerTest); var exp = Assert.ThrowsAny <Exception>(() => launchReporter.Sync()); Assert.Contains("Cannot finish launch", exp.Message); service.Verify(s => s.TestItem.StartAsync(It.IsAny <StartTestItemRequest>()), Times.Exactly(suitesPerLaunch)); service.Verify(s => s.TestItem.StartAsync(It.IsAny <string>(), It.IsAny <StartTestItemRequest>()), Times.Exactly(suitesPerLaunch * testsPerSuite)); service.Verify(s => s.TestItem.FinishAsync(It.IsAny <string>(), It.IsAny <FinishTestItemRequest>()), Times.Exactly(suitesPerLaunch * testsPerSuite)); }
public void ShouldSendBatchedRequests() { var service = new MockServiceBuilder().Build(); var logsReporter = new LogsReporter(_testReporter.Object, service.Object, _extensionManager, _requestExecuter, _logRequestAmender.Object); for (int i = 0; i < 50; i++) { logsReporter.Log(new CreateLogItemRequest { Text = "a", Time = DateTime.UtcNow }); } logsReporter.Sync(); service.Verify(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>()), Times.Exactly(5)); }
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); }
public void ShouldBeAbleToChangeRequestBeforeTestStarting() { var observer = new Mock <IReportEventsObserver>(); observer.Setup(o => o.Initialize(It.IsAny <IReportEventsSource>())).Callback <IReportEventsSource>(s => { s.OnBeforeTestStarting += (a, b) => b.StartTestItemRequest.Name = "NewName"; }); var extManager = new Shared.Extensibility.ExtensionManager(); extManager.ReportEventObservers.Add(observer.Object); var client = new MockServiceBuilder().Build().Object; var launch = new LaunchReporterBuilder(client).With(extManager).Build(1, 0, 0); launch.Sync(); launch.ChildTestReporters[0].Info.Name.Should().Be("NewName"); }
public async Task RetryHeaderDecidesRetryCount() { var helper = new MockServiceBuilder("localhost"); int callCount = 0; helper.UnaryHandler = new UnaryServerMethod <string, string>((request, context) => { callCount++; context.Status = new Status(StatusCode.Cancelled, ""); return(Task.FromResult("ok")); }); var server = helper.GetServer(); server.Start(); var callInvoker = helper.GetChannel().Intercept(new RetryInterceptor()); var metadata = new Metadata { { GrpcConstants.RetryCountMetadataKey, "0" } }; await Assert.ThrowsAsync <AggregateException>(async() => await callInvoker.AsyncUnaryCall(new Method <string, string>(MethodType.Unary, MockServiceBuilder.ServiceName, "Unary", Marshallers.StringMarshaller, Marshallers.StringMarshaller), "localhost", new CallOptions().WithHeaders(metadata), "")); Assert.Equal(1, callCount); callCount = 0; var oneRetryMetadata = new Metadata { { GrpcConstants.RetryCountMetadataKey, "1" } }; await Assert.ThrowsAsync <AggregateException>(async() => await callInvoker.AsyncUnaryCall(new Method <string, string>(MethodType.Unary, MockServiceBuilder.ServiceName, "Unary", Marshallers.StringMarshaller, Marshallers.StringMarshaller), "localhost", new CallOptions().WithHeaders(oneRetryMetadata), "")); Assert.Equal(2, callCount); await server.ShutdownAsync(); }
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); }