Пример #1
0
        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));
        }
Пример #2
0
        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]);
        }
Пример #3
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();
        }
Пример #4
0
        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);
        }
Пример #5
0
        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));
        }
Пример #7
0
        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();
        }
Пример #8
0
        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();
        }
Пример #9
0
        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");
        }
Пример #10
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>();
        }
Пример #11
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");
        }
Пример #12
0
        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*");
        }
Пример #13
0
        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);
        }
Пример #14
0
        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));
        }
Пример #16
0
        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);
        }
Пример #17
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();
        }
Пример #18
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);
        }
        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));
        }
Пример #20
0
        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();
        }
Пример #21
0
        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);
        }
Пример #23
0
        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);
        }
Пример #24
0
        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);
        }
Пример #25
0
        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));
        }
Пример #26
0
        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));
        }
Пример #27
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);
        }
Пример #28
0
        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");
        }
Пример #29
0
        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();
        }
Пример #30
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);
        }