public RpcWorkerProcessTests()
        {
            _eventManager = new Mock <IScriptEventManager>();
            var workerProcessFactory           = new Mock <IWorkerProcessFactory>();
            var processRegistry                = new Mock <IProcessRegistry>();
            var rpcServer                      = new TestRpcServer();
            var languageWorkerConsoleLogSource = new Mock <IWorkerConsoleLogSource>();
            var testEnv           = new TestEnvironment();
            var testWorkerConfigs = TestHelpers.GetTestWorkerConfigs();

            _hostProcessMonitorMock = new Mock <IHostProcessMonitor>(MockBehavior.Strict);
            var scriptHostManagerMock         = new Mock <IScriptHostManager>(MockBehavior.Strict);
            var scriptHostServiceProviderMock = scriptHostManagerMock.As <IServiceProvider>();

            scriptHostServiceProviderMock.Setup(p => p.GetService(typeof(IHostProcessMonitor))).Returns(() => _hostProcessMonitorMock.Object);

            var serviceProviderMock = new Mock <IServiceProvider>(MockBehavior.Strict);

            serviceProviderMock.Setup(p => p.GetService(typeof(IScriptHostManager))).Returns(scriptHostManagerMock.Object);

            _rpcWorkerProcess = new RpcWorkerProcess("node",
                                                     "testworkerId",
                                                     "testrootPath",
                                                     rpcServer.Uri,
                                                     testWorkerConfigs.ElementAt(0),
                                                     _eventManager.Object,
                                                     workerProcessFactory.Object,
                                                     processRegistry.Object,
                                                     new TestLogger("test"),
                                                     languageWorkerConsoleLogSource.Object,
                                                     new TestMetricsLogger(),
                                                     serviceProviderMock.Object);
        }
        public async Task RpcInitializationService_Initializes_RpcServerOnly_LinuxConsumption_NoPlaceHolderMode()
        {
            IRpcServer testRpcServer   = new TestRpcServer();
            var        mockEnvironment = new Mock <IEnvironment>();

            mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode)).Returns("0");
            mockEnvironment.Setup(p => p.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName)).Returns(string.Empty);
            mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.ContainerName)).Returns("LinuxContainer");

            var fileSystem = new Mock <IFileSystem>();

            fileSystem.Setup(f =>
                             f.File.Exists(It.Is <string>(path => path.EndsWith(ScriptConstants.DisableContainerFileName))))
            .Returns(false);
            FileUtility.Instance = fileSystem.Object;

            _rpcInitializationService = new RpcInitializationService(_optionsMonitor, mockEnvironment.Object, testRpcServer, _mockLanguageWorkerChannelManager.Object, _logger);
            await _rpcInitializationService.StartAsync(CancellationToken.None);

            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.PythonLanguageWorkerName), Times.Never);
            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.NodeLanguageWorkerName), Times.Never);
            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.JavaLanguageWorkerName), Times.Never);
            Assert.Contains("testserver", testRpcServer.Uri.ToString());
            await testRpcServer.ShutdownAsync();

            FileUtility.Instance = null;
        }
        public async Task RpcInitializationService_Does_Not_Initialize_RpcServerAndChannels_LinuxConsumption_DisabledContainer()
        {
            IRpcServer testRpcServer   = new TestRpcServer();
            var        mockEnvironment = new Mock <IEnvironment>();

            mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.ContainerName)).Returns("LinuxContainer");

            var fileSystem = new Mock <IFileSystem>();

            fileSystem.Setup(f =>
                             f.File.Exists(It.Is <string>(path => path.EndsWith(ScriptConstants.DisableContainerFileName))))
            .Returns(true);
            FileUtility.Instance = fileSystem.Object;

            _rpcInitializationService = new RpcInitializationService(_optionsMonitor, mockEnvironment.Object, testRpcServer, _mockLanguageWorkerChannelManager.Object, _logger);
            await _rpcInitializationService.StartAsync(CancellationToken.None);

            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.PythonLanguageWorkerName), Times.Never);
            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.NodeLanguageWorkerName), Times.Never);
            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.JavaLanguageWorkerName), Times.Never);
            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.PowerShellLanguageWorkerName), Times.Never);
            Assert.DoesNotContain("testserver", testRpcServer.Uri.ToString());
            await testRpcServer.ShutdownAsync();

            FileUtility.Instance = null;
        }
        public async Task RpcInitializationService_Initializes_RpcServerAndChannels_WorkerRuntime_Set_Node_NoPlaceHolderMode()
        {
            IRpcServer testRpcServer   = new TestRpcServer();
            var        mockEnvironment = new Mock <IEnvironment>();

            mockEnvironment.Setup(p => p.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName)).Returns(RpcWorkerConstants.NodeLanguageWorkerName);
            _rpcInitializationService = new RpcInitializationService(_optionsMonitor, mockEnvironment.Object, testRpcServer, _mockLanguageWorkerChannelManager.Object, _logger);
            await _rpcInitializationService.StartAsync(CancellationToken.None);

            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.NodeLanguageWorkerName), Times.Never);
            Assert.Contains("testserver", testRpcServer.Uri.ToString());
            await testRpcServer.ShutdownAsync();
        }
        public async Task RpcInitializationService_Initializes_RpcServerOnly_WebHostLevel_WorkerRuntime_NotSet_NoPlaceHolderMode()
        {
            IRpcServer testRpcServer   = new TestRpcServer();
            var        mockEnvironment = new Mock <IEnvironment>();

            _rpcInitializationService = new RpcInitializationService(_optionsMonitor, mockEnvironment.Object, testRpcServer, _mockLanguageWorkerChannelManager.Object, _logger);
            _rpcInitializationService.AddSupportedWebHostLevelRuntime(RpcWorkerConstants.NodeLanguageWorkerName);

            await _rpcInitializationService.StartAsync(CancellationToken.None);

            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.JavaLanguageWorkerName), Times.Never);
            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.NodeLanguageWorkerName), Times.Never);
            Assert.Contains("testserver", testRpcServer.Uri.ToString());
            await testRpcServer.ShutdownAsync();
        }
        public async Task RpcInitializationService_Initializes_RpcServerOnly_LinuxAppService_NoPlaceHolderMode()
        {
            IRpcServer testRpcServer   = new TestRpcServer();
            var        mockEnvironment = new Mock <IEnvironment>();

            mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.FunctionsLogsMountPath)).Returns(@"d:\test");
            mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteInstanceId)).Returns("1234");
            mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode)).Returns("0");
            mockEnvironment.Setup(p => p.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName)).Returns(string.Empty);

            _rpcInitializationService = new RpcInitializationService(_optionsMonitor, mockEnvironment.Object, testRpcServer, _mockLanguageWorkerChannelManager.Object, _logger);
            await _rpcInitializationService.StartAsync(CancellationToken.None);

            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.PythonLanguageWorkerName), Times.Never);
            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.NodeLanguageWorkerName), Times.Never);
            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.JavaLanguageWorkerName), Times.Never);
            Assert.Contains("testserver", testRpcServer.Uri.ToString());
            await testRpcServer.ShutdownAsync();
        }
Ejemplo n.º 7
0
        public RpcWorkerProcessTests()
        {
            _eventManager = new Mock <IScriptEventManager>();
            var workerProcessFactory           = new Mock <IWorkerProcessFactory>();
            var processRegistry                = new Mock <IProcessRegistry>();
            var rpcServer                      = new TestRpcServer();
            var languageWorkerConsoleLogSource = new Mock <IWorkerConsoleLogSource>();
            var testEnv = new TestEnvironment();

            _rpcWorkerProcess = new RpcWorkerProcess("node",
                                                     "testworkerId",
                                                     "testrootPath",
                                                     rpcServer.Uri,
                                                     null,
                                                     _eventManager.Object,
                                                     workerProcessFactory.Object,
                                                     processRegistry.Object,
                                                     new TestLogger("test"),
                                                     languageWorkerConsoleLogSource.Object);
        }
        public async Task RpcInitializationService_AppOffline()
        {
            IRpcServer testRpcServer   = new TestRpcServer();
            var        mockEnvironment = new Mock <IEnvironment>();
            string     offlineFilePath = null;

            try
            {
                offlineFilePath           = TestHelpers.CreateOfflineFile();
                _rpcInitializationService = new RpcInitializationService(_optionsMonitor, mockEnvironment.Object, testRpcServer, _mockLanguageWorkerChannelManager.Object, _logger);
                await _rpcInitializationService.StartAsync(CancellationToken.None);

                _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.JavaLanguageWorkerName), Times.Never);
                Assert.DoesNotContain("testserver", testRpcServer.Uri.ToString());
                await testRpcServer.ShutdownAsync();
            }
            finally
            {
                TestHelpers.DeleteTestFile(offlineFilePath);
            }
        }
        public RpcWorkerProcessTests()
        {
            _eventManager = new Mock <IScriptEventManager>();
            var workerProcessFactory           = new Mock <IWorkerProcessFactory>();
            var processRegistry                = new Mock <IProcessRegistry>();
            var rpcServer                      = new TestRpcServer();
            var languageWorkerConsoleLogSource = new Mock <IWorkerConsoleLogSource>();
            var testEnv           = new TestEnvironment();
            var testWorkerConfigs = TestHelpers.GetTestWorkerConfigs();

            _rpcWorkerProcess = new RpcWorkerProcess("node",
                                                     "testworkerId",
                                                     "testrootPath",
                                                     rpcServer.Uri,
                                                     testWorkerConfigs.ElementAt(0),
                                                     _eventManager.Object,
                                                     workerProcessFactory.Object,
                                                     processRegistry.Object,
                                                     new TestLogger("test"),
                                                     languageWorkerConsoleLogSource.Object,
                                                     new TestMetricsLogger());
        }
        public async Task RpcInitializationService_Initializes_RpcServer_RpcChannels_PlaceholderMode(string workerRuntime)
        {
            IRpcServer testRpcServer   = new TestRpcServer();
            var        mockEnvironment = new Mock <IEnvironment>();

            mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode)).Returns("1");
            mockEnvironment.Setup(p => p.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName)).Returns(workerRuntime);
            if (string.IsNullOrEmpty(workerRuntime))
            {
                mockEnvironment.Setup(p => p.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerPlaceholderModeListSettingName)).Returns($"{RpcWorkerConstants.PythonLanguageWorkerName};{RpcWorkerConstants.JavaLanguageWorkerName};{RpcWorkerConstants.NodeLanguageWorkerName}");
            }
            else
            {
                mockEnvironment.Setup(p => p.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerPlaceholderModeListSettingName)).Returns($"{RpcWorkerConstants.PythonLanguageWorkerName};{RpcWorkerConstants.JavaLanguageWorkerName};");
            }
            _rpcInitializationService = new RpcInitializationService(_optionsMonitor, mockEnvironment.Object, testRpcServer, _mockLanguageWorkerChannelManager.Object, _logger);
            await _rpcInitializationService.StartAsync(CancellationToken.None);

            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.NodeLanguageWorkerName), Times.Once);
            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.JavaLanguageWorkerName), Times.Once);
            _mockLanguageWorkerChannelManager.Verify(m => m.InitializeChannelAsync(RpcWorkerConstants.PythonLanguageWorkerName), Times.Once);
            Assert.Contains("testserver", testRpcServer.Uri.ToString());
            await testRpcServer.ShutdownAsync();
        }