Esempio n. 1
0
        private static TestRpcWorkerConfig MakeTestConfig(string language, string[] arguments, bool invalid = false, string addAppSvcProfile = "", bool emptyWorkerPath = false)
        {
            string json = RpcWorkerConfigTestUtilities.GetTestWorkerConfig(language, arguments, invalid, addAppSvcProfile, emptyWorkerPath).ToString();

            return(new TestRpcWorkerConfig()
            {
                Json = json,
                Language = language,
            });
        }
Esempio n. 2
0
        public void ValidateWorkerDescription_Succeeds(WorkerDescription workerDescription)
        {
            var testLogger = new TestLogger(testLanguage);

            try
            {
                RpcWorkerConfigTestUtilities.CreateTestWorkerFileInCurrentDir();
                workerDescription.ApplyDefaultsAndValidate(Directory.GetCurrentDirectory(), testLogger);
            }
            finally
            {
                RpcWorkerConfigTestUtilities.DeleteTestWorkerFileInCurrentDir();
            }
        }
Esempio n. 3
0
        public void ReadWorkerProviderFromConfig_InvalidWorker()
        {
            var testConfig = MakeTestConfig(testLanguage, new string[0]);
            var configs    = new List <TestRpcWorkerConfig>()
            {
                testConfig
            };
            TestMetricsLogger testMetricsLogger = new TestMetricsLogger();

            RpcWorkerConfigTestUtilities.CreateWorkerFolder(customRootPath, testConfig, false);
            Dictionary <string, string> keyValuePairs = new Dictionary <string, string>
            {
                [$"{RpcWorkerConstants.LanguageWorkersSectionName}:{testLanguage}:{WorkerConstants.WorkerDirectorySectionName}"] = customRootPath
            };

            var workerConfigs = TestReadWorkerProviderFromConfig(configs, new TestLogger(testLanguage), testMetricsLogger, null, keyValuePairs);

            AreRequiredMetricsEmitted(testMetricsLogger);
            Assert.Empty(workerConfigs);
        }
Esempio n. 4
0
        private IEnumerable <RpcWorkerConfig> TestReadWorkerProviderFromConfig(IEnumerable <TestRpcWorkerConfig> configs, ILogger testLogger, TestMetricsLogger testMetricsLogger, string language = null, Dictionary <string, string> keyValuePairs = null, bool appSvcEnv = false)
        {
            Mock <IEnvironment> mockEnvironment = new Mock <IEnvironment>();
            var workerPathSection = $"{RpcWorkerConstants.LanguageWorkersSectionName}:{WorkerConstants.WorkersDirectorySectionName}";

            try
            {
                foreach (var workerConfig in configs)
                {
                    RpcWorkerConfigTestUtilities.CreateWorkerFolder(rootPath, workerConfig);
                }

                IConfigurationRoot config = TestConfigBuilder(workerPathSection, keyValuePairs);

                var scriptHostOptions     = new ScriptJobHostOptions();
                var scriptSettingsManager = new ScriptSettingsManager(config);
                var configFactory         = new RpcWorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, _testEnvironment, testMetricsLogger);
                if (appSvcEnv)
                {
                    var testEnvVariables = new Dictionary <string, string>
                    {
                        { EnvironmentSettingNames.AzureWebsiteInstanceId, "123" },
                    };
                    using (var variables = new TestScopedSettings(scriptSettingsManager, testEnvVariables))
                    {
                        configFactory.BuildWorkerProviderDictionary();
                        return(configFactory.GetConfigs());
                    }
                }
                configFactory.BuildWorkerProviderDictionary();
                return(configFactory.GetConfigs());
            }
            finally
            {
                RpcWorkerConfigTestUtilities.DeleteTestDir(rootPath);
                RpcWorkerConfigTestUtilities.DeleteTestDir(customRootPath);
            }
        }
Esempio n. 5
0
        public void ReadWorkerProviderFromAppSetting()
        {
            var testConfig = MakeTestConfig(testLanguage, new string[0]);
            var configs    = new List <TestRpcWorkerConfig>()
            {
                testConfig
            };
            TestMetricsLogger testMetricsLogger = new TestMetricsLogger();

            RpcWorkerConfigTestUtilities.CreateWorkerFolder(customRootPath, testConfig);
            Dictionary <string, string> keyValuePairs = new Dictionary <string, string>
            {
                [$"{RpcWorkerConstants.LanguageWorkersSectionName}:{testLanguage}:{WorkerConstants.WorkerDirectorySectionName}"] = Path.Combine(customRootPath, testLanguage)
            };

            var workerConfigs = TestReadWorkerProviderFromConfig(configs, new TestLogger(testLanguage), testMetricsLogger, null, keyValuePairs);

            AreRequiredMetricsEmitted(testMetricsLogger);
            Assert.Single(workerConfigs);
            RpcWorkerConfig workerConfig = workerConfigs.Single();

            Assert.Equal(Path.Combine(customRootPath, testLanguage, $"{RpcWorkerConfigTestUtilities.TestWorkerPathInWorkerConfig}.{testLanguage}"), workerConfig.Description.DefaultWorkerPath);
        }