public GrpcWorkerChannelTests()
        {
            _logger = new TestLogger("FunctionDispatcherTests");
            _testFunctionRpcService = new TestFunctionRpcService(_eventManager, _workerId, _logger, _expectedLogMsg);
            _testWorkerConfig       = TestHelpers.GetTestWorkerConfigs().FirstOrDefault();
            _mockrpcWorkerProcess.Setup(m => m.StartProcessAsync()).Returns(Task.CompletedTask);
            _testEnvironment = new TestEnvironment();

            var hostOptions = new ScriptApplicationHostOptions
            {
                IsSelfHost     = true,
                ScriptPath     = _scriptRootPath,
                LogPath        = Environment.CurrentDirectory, // not tested
                SecretsPath    = Environment.CurrentDirectory, // not tested
                HasParentScope = true
            };

            _hostOptionsMonitor = TestHelpers.CreateOptionsMonitor(hostOptions);

            _workerChannel = new GrpcWorkerChannel(
                _workerId,
                _eventManager,
                _testWorkerConfig,
                _mockrpcWorkerProcess.Object,
                _logger,
                _metricsLogger,
                0,
                _testEnvironment,
                _hostOptionsMonitor);
        }
Exemplo n.º 2
0
        public async Task GetLatencies_DoesNot_StartTimer_WhenDynamicConcurrencyDisabled()
        {
            RpcWorkerConfig config = new RpcWorkerConfig()
            {
                Description = new RpcWorkerDescription()
                {
                    Language = RpcWorkerConstants.NodeLanguageWorkerName
                },
            };

            _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionsWorkerDynamicConcurrencyEnabled, null);
            GrpcWorkerChannel workerChannel = new GrpcWorkerChannel(
                _workerId,
                _eventManager,
                config,
                _mockrpcWorkerProcess.Object,
                _logger,
                _metricsLogger,
                0,
                _testEnvironment,
                _hostOptionsMonitor,
                _sharedMemoryManager,
                _functionDataCache,
                _workerConcurrencyOptions);

            // wait 10 seconds
            await Task.Delay(10000);

            IEnumerable <TimeSpan> latencyHistory = workerChannel.GetLatencies();

            Assert.True(latencyHistory.Count() == 0);
        }
        public async Task Drain_Verify()
        {
            var  resultSource         = new TaskCompletionSource <ScriptInvocationResult>();
            Guid invocationId         = Guid.NewGuid();
            GrpcWorkerChannel channel = new GrpcWorkerChannel(
                _workerId,
                _eventManager,
                _testWorkerConfig,
                _mockrpcWorkerProcess.Object,
                _logger,
                _metricsLogger,
                0,
                _testEnvironment,
                _hostOptionsMonitor);

            channel.SetupFunctionInvocationBuffers(GetTestFunctionsList("node"));
            ScriptInvocationContext scriptInvocationContext = GetTestScriptInvocationContext(invocationId, resultSource);
            await channel.SendInvocationRequest(scriptInvocationContext);

            Task result = channel.DrainInvocationsAsync();

            Assert.NotEqual(result.Status, TaskStatus.RanToCompletion);
            channel.InvokeResponse(new InvocationResponse
            {
                InvocationId = invocationId.ToString(),
                Result       = new StatusResult
                {
                    Status = StatusResult.Types.Status.Success
                },
            });
            await result;

            Assert.Equal(result.Status, TaskStatus.RanToCompletion);
        }
        private async Task WaitForJobHostChannelReady()
        {
            await TestHelpers.Await(() =>
            {
                var currentChannel = GetCurrentJobHostWorkerChannel();
                return(currentChannel != null);
            }, pollingInterval : 4 * 1000, timeout : 60 * 1000);

            _nodeWorkerChannel = GetCurrentJobHostWorkerChannel();
        }
        private async Task WaitForWorkerProcessRestart(int restartCount)
        {
            await TestHelpers.Await(() =>
            {
                var currentChannel = GetCurrentJobHostWorkerChannel();
                return(currentChannel != null && currentChannel.Id != _nodeWorkerChannel.Id);
            }, pollingInterval : 4 * 1000, timeout : 60 * 1000);

            _nodeWorkerChannel = GetCurrentJobHostWorkerChannel();
        }
Exemplo n.º 6
0
        public GrpcWorkerChannelTests()
        {
            _logger = new TestLogger("FunctionDispatcherTests");
            _testFunctionRpcService = new TestFunctionRpcService(_eventManager, _workerId, _logger, _expectedLogMsg);
            _testWorkerConfig       = TestHelpers.GetTestWorkerConfigs().FirstOrDefault();
            _testWorkerConfig.CountOptions.ProcessStartupTimeout    = TimeSpan.FromSeconds(5);
            _testWorkerConfig.CountOptions.InitializationTimeout    = TimeSpan.FromSeconds(5);
            _testWorkerConfig.CountOptions.EnvironmentReloadTimeout = TimeSpan.FromSeconds(5);

            _mockrpcWorkerProcess.Setup(m => m.StartProcessAsync()).Returns(Task.CompletedTask);
            _mockrpcWorkerProcess.Setup(m => m.Id).Returns(910);
            _testEnvironment = new TestEnvironment();
            _testEnvironment.SetEnvironmentVariable(FunctionDataCacheConstants.FunctionDataCacheEnabledSettingName, "1");
            _workerConcurrencyOptions = Options.Create(new WorkerConcurrencyOptions());
            _workerConcurrencyOptions.Value.CheckInterval = TimeSpan.FromSeconds(1);

            ILogger <MemoryMappedFileAccessor> mmapAccessorLogger = NullLogger <MemoryMappedFileAccessor> .Instance;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                _mapAccessor = new MemoryMappedFileAccessorWindows(mmapAccessorLogger);
            }
            else
            {
                _mapAccessor = new MemoryMappedFileAccessorUnix(mmapAccessorLogger, _testEnvironment);
            }
            _sharedMemoryManager = new SharedMemoryManager(_loggerFactory, _mapAccessor);
            _functionDataCache   = new FunctionDataCache(_sharedMemoryManager, _loggerFactory, _testEnvironment);

            var hostOptions = new ScriptApplicationHostOptions
            {
                IsSelfHost     = true,
                ScriptPath     = _scriptRootPath,
                LogPath        = Environment.CurrentDirectory, // not tested
                SecretsPath    = Environment.CurrentDirectory, // not tested
                HasParentScope = true
            };

            _hostOptionsMonitor = TestHelpers.CreateOptionsMonitor(hostOptions);

            _workerChannel = new GrpcWorkerChannel(
                _workerId,
                _eventManager,
                _testWorkerConfig,
                _mockrpcWorkerProcess.Object,
                _logger,
                _metricsLogger,
                0,
                _testEnvironment,
                _hostOptionsMonitor,
                _sharedMemoryManager,
                _functionDataCache,
                _workerConcurrencyOptions);
        }
        public async Task StartWorkerProcessAsync_WorkerProcess_Throws()
        {
            Mock <IWorkerProcess> mockrpcWorkerProcessThatThrows = new Mock <IWorkerProcess>();

            mockrpcWorkerProcessThatThrows.Setup(m => m.StartProcessAsync()).Throws <FileNotFoundException>();

            _workerChannel = new GrpcWorkerChannel(
                _workerId,
                _eventManager,
                _testWorkerConfig,
                mockrpcWorkerProcessThatThrows.Object,
                _logger,
                _metricsLogger,
                0,
                _testEnvironment,
                _hostOptionsMonitor);
            await Assert.ThrowsAsync <FileNotFoundException>(async() => await _workerChannel.StartWorkerProcessAsync());
        }
Exemplo n.º 8
0
        public GrpcWorkerChannelTests()
        {
            _logger = new TestLogger("FunctionDispatcherTests");
            _testFunctionRpcService = new TestFunctionRpcService(_eventManager, _workerId, _logger, _expectedLogMsg);
            _testWorkerConfig       = TestHelpers.GetTestWorkerConfigs().FirstOrDefault();
            _mockrpcWorkerProcess.Setup(m => m.StartProcessAsync()).Returns(Task.CompletedTask);
            _testEnvironment = new TestEnvironment();
            ILogger <MemoryMappedFileAccessor> mmapAccessorLogger = NullLogger <MemoryMappedFileAccessor> .Instance;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                _mapAccessor = new MemoryMappedFileAccessorWindows(mmapAccessorLogger);
            }
            else
            {
                _mapAccessor = new MemoryMappedFileAccessorUnix(mmapAccessorLogger, _testEnvironment);
            }
            _sharedMemoryManager = new SharedMemoryManager(_loggerFactory, _mapAccessor);

            var hostOptions = new ScriptApplicationHostOptions
            {
                IsSelfHost     = true,
                ScriptPath     = _scriptRootPath,
                LogPath        = Environment.CurrentDirectory, // not tested
                SecretsPath    = Environment.CurrentDirectory, // not tested
                HasParentScope = true
            };

            _hostOptionsMonitor = TestHelpers.CreateOptionsMonitor(hostOptions);

            _workerChannel = new GrpcWorkerChannel(
                _workerId,
                _eventManager,
                _testWorkerConfig,
                _mockrpcWorkerProcess.Object,
                _logger,
                _metricsLogger,
                0,
                _testEnvironment,
                _hostOptionsMonitor,
                _sharedMemoryManager);
        }
Exemplo n.º 9
0
        public async Task StartWorkerProcessAsync_WorkerProcess_Throws()
        {
            Mock <IWorkerProcess> mockrpcWorkerProcessThatThrows = new Mock <IWorkerProcess>();

            mockrpcWorkerProcessThatThrows.Setup(m => m.StartProcessAsync()).Throws <FileNotFoundException>();

            _workerChannel = new GrpcWorkerChannel(
                _workerId,
                _eventManager,
                _testWorkerConfig,
                mockrpcWorkerProcessThatThrows.Object,
                _logger,
                _metricsLogger,
                0,
                _testEnvironment,
                _hostOptionsMonitor,
                _sharedMemoryManager,
                _functionDataCache,
                _workerConcurrencyOptions);
            await Assert.ThrowsAsync <FileNotFoundException>(async() => await _workerChannel.StartWorkerProcessAsync(CancellationToken.None));
        }
Exemplo n.º 10
0
        public async Task GetLatencies_StartsTimer_WhenDynamicConcurrencyEnabled()
        {
            RpcWorkerConfig config = new RpcWorkerConfig()
            {
                Description = new RpcWorkerDescription()
                {
                    Language = RpcWorkerConstants.NodeLanguageWorkerName
                }
            };

            _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionsWorkerDynamicConcurrencyEnabled, "true");
            GrpcWorkerChannel workerChannel = new GrpcWorkerChannel(
                _workerId,
                _eventManager,
                config,
                _mockrpcWorkerProcess.Object,
                _logger,
                _metricsLogger,
                0,
                _testEnvironment,
                _hostOptionsMonitor,
                _sharedMemoryManager,
                _functionDataCache,
                _workerConcurrencyOptions);

            IEnumerable <TimeSpan> latencyHistory = null;

            // wait 10 seconds
            await TestHelpers.Await(() =>
            {
                latencyHistory = workerChannel.GetLatencies();
                return(latencyHistory.Count() > 0);
            }, pollingInterval : 1000, timeout : 10 * 1000);

            // We have non empty latencyHistory so the timer was started
            _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionsWorkerDynamicConcurrencyEnabled, null);
        }