public async Task DoesNotPublishExecutionActivityInStandbyMode()
        {
            var activity = new ContainerFunctionExecutionActivity(DateTime.MinValue, "func-1",
                                                                  ExecutionStage.InProgress, "trigger-1", false);

            var environment = new TestEnvironment();

            environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode, "1");
            environment.SetEnvironmentVariable(EnvironmentSettingNames.ContainerName, "Container-Name");

            var meshClient     = new Mock <IMeshServiceClient>();
            var standbyOptions = new TestOptionsMonitor <StandbyOptions>(new StandbyOptions {
                InStandbyMode = true
            });

            using (var publisher = new LinuxContainerActivityPublisher(standbyOptions, meshClient.Object,
                                                                       environment, NullLogger <LinuxContainerActivityPublisher> .Instance, FlushIntervalMs))
            {
                await publisher.StartAsync(CancellationToken.None);

                publisher.PublishFunctionExecutionActivity(activity);
                await Task.Delay(DelayIntervalMs);

                await publisher.StopAsync(CancellationToken.None);

                meshClient.Verify(c =>
                                  c.PublishContainerActivity(It.IsAny <IEnumerable <ContainerFunctionExecutionActivity> >()), Times.Never);
            }
        }
        public async Task PublishesFunctionExecutionActivity()
        {
            var activity = new ContainerFunctionExecutionActivity(DateTime.MinValue, "func-1",
                                                                  ExecutionStage.InProgress, "trigger-1", false);

            var environment = new TestEnvironment();

            environment.SetEnvironmentVariable(EnvironmentSettingNames.ContainerName, "Container-Name");

            var meshClient = new Mock <IMeshServiceClient>();

            meshClient.Setup(c =>
                             c.PublishContainerActivity(
                                 It.IsAny <IEnumerable <ContainerFunctionExecutionActivity> >())).Returns(Task.FromResult(true));

            var standbyOptions = new TestOptionsMonitor <StandbyOptions>(new StandbyOptions {
                InStandbyMode = false
            });

            using (var publisher = new LinuxContainerActivityPublisher(standbyOptions, meshClient.Object,
                                                                       environment, NullLogger <LinuxContainerActivityPublisher> .Instance, FlushIntervalMs))
            {
                await publisher.StartAsync(CancellationToken.None);

                publisher.PublishFunctionExecutionActivity(activity);
                await Task.Delay(DelayIntervalMs);

                await publisher.StopAsync(CancellationToken.None);

                meshClient.Verify(
                    c => c.PublishContainerActivity(
                        It.Is <IEnumerable <ContainerFunctionExecutionActivity> >(e =>
                                                                                  MatchesFunctionActivities(e, activity))), Times.Once);
            }
        }
        public async Task PublishesUniqueFunctionExecutionActivitiesOnly()
        {
            // activity1 and activity2 are duplicates. so only activity2 will be published
            var activity1 = new ContainerFunctionExecutionActivity(DateTime.MinValue, "func-1",
                                                                   ExecutionStage.InProgress, "trigger-1", false);
            var activity2 = new ContainerFunctionExecutionActivity(DateTime.MaxValue, "func-1",
                                                                   ExecutionStage.InProgress, "trigger-1", false);
            var activity3 = new ContainerFunctionExecutionActivity(DateTime.MaxValue, "func-1", ExecutionStage.Finished,
                                                                   "trigger-1", true);
            var activity4 = new ContainerFunctionExecutionActivity(DateTime.MaxValue, "func-1", ExecutionStage.Finished,
                                                                   "trigger-1", false);

            var environment = new TestEnvironment();

            environment.SetEnvironmentVariable(EnvironmentSettingNames.ContainerName, "Container-Name");

            var meshClient = new Mock <IMeshServiceClient>();

            var standbyOptions = new TestOptionsMonitor <StandbyOptions>(new StandbyOptions {
                InStandbyMode = false
            });

            using (var publisher = new LinuxContainerActivityPublisher(standbyOptions, meshClient.Object,
                                                                       environment, NullLogger <LinuxContainerActivityPublisher> .Instance, FlushIntervalMs))
            {
                await publisher.StartAsync(CancellationToken.None);

                publisher.PublishFunctionExecutionActivity(activity1);
                publisher.PublishFunctionExecutionActivity(activity2);
                publisher.PublishFunctionExecutionActivity(activity3);
                publisher.PublishFunctionExecutionActivity(activity4);
                await Task.Delay(DelayIntervalMs);

                await publisher.StopAsync(CancellationToken.None);

                meshClient.Verify(
                    c => c.PublishContainerActivity(
                        It.Is <IEnumerable <ContainerFunctionExecutionActivity> >(e =>
                                                                                  MatchesFunctionActivities(e, activity2, activity3, activity4))), Times.Once);
            }
        }
Пример #4
0
        public async Task PublishesSpecializationCompleteEvent()
        {
            var activity = new ContainerFunctionExecutionActivity(DateTime.MinValue, "func-1",
                                                                  ExecutionStage.InProgress, "trigger-1", false);

            var environment = new TestEnvironment();

            environment.SetEnvironmentVariable(EnvironmentSettingNames.ContainerName, "Container-Name");

            var meshClient = new Mock <IMeshServiceClient>(MockBehavior.Strict);

            meshClient.Setup(c => c.NotifyHealthEvent(ContainerHealthEventType.Informational, It.IsAny <Type>(),
                                                      LinuxContainerActivityPublisher.SpecializationCompleteEvent)).Returns(Task.FromResult(true));

            var standbyOptions = new TestOptionsMonitor <StandbyOptions>(new StandbyOptions {
                InStandbyMode = false
            });

            using (var publisher = new LinuxContainerActivityPublisher(standbyOptions, meshClient.Object,
                                                                       environment, NullLogger <LinuxContainerActivityPublisher> .Instance, 1000, InitialFlushIntervalMs))
            {
                await publisher.StartAsync(CancellationToken.None);

                publisher.PublishFunctionExecutionActivity(activity);
                await Task.Delay(100);

                await publisher.StopAsync(CancellationToken.None);

                meshClient.Verify(c => c.NotifyHealthEvent(ContainerHealthEventType.Informational, It.IsAny <Type>(),
                                                           LinuxContainerActivityPublisher.SpecializationCompleteEvent), Times.Once);

                // Since test is waiting for 100ms and Flush interval is 1000ms, there will be no PublishContainerActivity
                meshClient.Verify(
                    c => c.PublishContainerActivity(
                        It.Is <IEnumerable <ContainerFunctionExecutionActivity> >(e =>
                                                                                  MatchesFunctionActivities(e, activity))), Times.Never);
            }
        }