Example #1
0
        public RpcWorkerChannelTests()
        {
            _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 RpcWorkerChannel(
                _workerId,
                _eventManager,
                _testWorkerConfig,
                _mockrpcWorkerProcess.Object,
                _logger,
                _metricsLogger,
                0,
                _testEnvironment,
                _hostOptionsMonitor);
        }
Example #2
0
        public async Task Drain_Verify()
        {
            var              resultSource = new TaskCompletionSource <ScriptInvocationResult>();
            Guid             invocationId = Guid.NewGuid();
            RpcWorkerChannel channel      = new RpcWorkerChannel(
                _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();
        }
Example #5
0
        public async Task StartWorkerProcessAsync_WorkerProcess_Throws()
        {
            Mock <IWorkerProcess> mockrpcWorkerProcessThatThrows = new Mock <IWorkerProcess>();

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

            _workerChannel = new RpcWorkerChannel(
                _workerId,
                _scriptRootPath,
                _eventManager,
                _testWorkerConfig,
                mockrpcWorkerProcessThatThrows.Object,
                _logger,
                _metricsLogger,
                0);
            await Assert.ThrowsAsync <FileNotFoundException>(async() => await _workerChannel.StartWorkerProcessAsync());
        }
Example #6
0
        public RpcWorkerChannelTests()
        {
            _logger = new TestLogger("FunctionDispatcherTests");
            _testFunctionRpcService = new TestFunctionRpcService(_eventManager, _workerId, _logger, _expectedLogMsg);
            _testWorkerConfig       = TestHelpers.GetTestWorkerConfigs().FirstOrDefault();
            _mockrpcWorkerProcess.Setup(m => m.StartProcessAsync()).Returns(Task.CompletedTask);

            _workerChannel = new RpcWorkerChannel(
                _workerId,
                _scriptRootPath,
                _eventManager,
                _testWorkerConfig,
                _mockrpcWorkerProcess.Object,
                _logger,
                _metricsLogger,
                0);
        }