Exemplo n.º 1
0
        public void LanguageWorker_FormatWorkerPath_UnsupportedEnvironmentRuntimeVersion()
        {
            _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, "3.4");

            RpcWorkerDescription workerDescription = new RpcWorkerDescription()
            {
                Arguments                = new List <string>(),
                DefaultExecutablePath    = "python",
                SupportedRuntimeVersions = new List <string>()
                {
                    "3.6", "3.7"
                },
                DefaultWorkerPath = $"{RpcWorkerConstants.RuntimeVersionPlaceholder}/worker.py",
                WorkerDirectory   = string.Empty,
                Extensions        = new List <string>()
                {
                    ".py"
                },
                Language = "python",
                DefaultRuntimeVersion = "3.7" // Ignore this if environment is set
            };
            var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
                                .AddInMemoryCollection(new Dictionary <string, string>
            {
                ["languageWorker"] = "test"
            });
            var config = configBuilder.Build();
            var scriptSettingsManager = new ScriptSettingsManager(config);
            var testLogger            = new TestLogger("test");

            var ex = Assert.Throws <NotSupportedException>(() => workerDescription.FormatWorkerPathIfNeeded(_testSysRuntimeInfo, _testEnvironment, testLogger));

            Assert.Equal(ex.Message, $"Version 3.4 is not supported for language {workerDescription.Language}");
        }
Exemplo n.º 2
0
        public void ValidateWorkerDescription_ResolvesDotNetDefaultWorkerExecutablePath_WhenExpectedFileExists(
            string defaultExecutablePath)
        {
            var testLogger = new TestLogger(testLanguage);

            var expectedExecutablePath =
                RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                    ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "dotnet", "dotnet.exe")
                    : defaultExecutablePath;

            var workerDescription = new RpcWorkerDescription
            {
                Language              = testLanguage,
                Extensions            = new List <string>(),
                DefaultExecutablePath = defaultExecutablePath,
                FileExists            = path =>
                {
                    Assert.Equal(expectedExecutablePath, path);
                    return(true);
                }
            };

            workerDescription.ApplyDefaultsAndValidate(Directory.GetCurrentDirectory(), testLogger);
            Assert.Equal(expectedExecutablePath, workerDescription.DefaultExecutablePath);
        }
Exemplo n.º 3
0
        public void ValidateWorkerDescription_DoesNotModifyDefaultWorkerExecutablePathAndWarns_WhenExpectedFileDoesNotExist(
            string defaultExecutablePath)
        {
            var testLogger = new TestLogger(testLanguage);

            var expectedExecutablePath =
                RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                    ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "dotnet", "dotnet.exe")
                    : defaultExecutablePath;

            var workerDescription = new RpcWorkerDescription
            {
                Language              = testLanguage,
                Extensions            = new List <string>(),
                DefaultExecutablePath = defaultExecutablePath,
                FileExists            = path =>
                {
                    Assert.Equal(expectedExecutablePath, path);
                    return(false);
                }
            };

            workerDescription.ApplyDefaultsAndValidate(Directory.GetCurrentDirectory(), testLogger);
            Assert.Equal(defaultExecutablePath, workerDescription.DefaultExecutablePath);
            Assert.True(testLogger.GetLogMessages().Any(message => message.Level == LogLevel.Warning &&
                                                        message.FormattedMessage.Contains(defaultExecutablePath) &&
                                                        message.FormattedMessage.Contains(expectedExecutablePath)));
        }
        public void LanguageWorker_HydratedWorkerPath_UnsupportedDefaultRuntimeVersion()
        {
            RpcWorkerDescription workerDescription = new RpcWorkerDescription()
            {
                Arguments                = new List <string>(),
                DefaultExecutablePath    = "python",
                SupportedRuntimeVersions = new List <string>()
                {
                    "3.6", "3.7"
                },
                DefaultWorkerPath = $"{RpcWorkerConstants.RuntimeVersionPlaceholder}/worker.py",
                WorkerDirectory   = string.Empty,
                Extensions        = new List <string>()
                {
                    ".py"
                },
                Language = "python",
                DefaultRuntimeVersion = "3.5"
            };
            var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
                                .AddInMemoryCollection(new Dictionary <string, string>
            {
                ["languageWorker"] = "test"
            });
            var config = configBuilder.Build();
            var scriptSettingsManager = new ScriptSettingsManager(config);
            var testLogger            = new TestLogger("test");
            var configFactory         = new RpcWorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, _testEnvironment, new TestMetricsLogger());

            var ex = Assert.Throws <NotSupportedException>(() => configFactory.GetHydratedWorkerPath(workerDescription));

            Assert.Equal(ex.Message, $"Version {workerDescription.DefaultRuntimeVersion} is not supported for language {workerDescription.Language}");
        }
Exemplo n.º 5
0
        public static JObject GetTestWorkerConfig(string language, string[] arguments, bool invalid, string profileName, bool emptyWorkerPath = false)
        {
            WorkerDescription description = GetTestDefaultWorkerDescription(language, arguments);

            JObject config = new JObject();

            config[OutOfProcConstants.WorkerDescription] = JObject.FromObject(description);

            if (!string.IsNullOrEmpty(profileName))
            {
                var appSvcDescription = new RpcWorkerDescription()
                {
                    DefaultExecutablePath = "myFooPath",
                };

                JObject profiles = new JObject();
                profiles[profileName] = JObject.FromObject(appSvcDescription);
                config[OutOfProcConstants.WorkerDescriptionProfiles] = profiles;
            }

            if (invalid)
            {
                config[OutOfProcConstants.WorkerDescription] = "invalidWorkerConfig";
            }

            if (emptyWorkerPath)
            {
                config[OutOfProcConstants.WorkerDescription][OutOfProcConstants.WorkerDescriptionDefaultWorkerPath] = null;
            }

            return(config);
        }
        public void LanguageWorker_FormatWorkerPath_DefualtRuntimeVersion_WorkerRuntimeMismatch()
        {
            _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, "13");
            _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, "node");

            RpcWorkerDescription workerDescription = new RpcWorkerDescription()
            {
                Arguments                = new List <string>(),
                DefaultExecutablePath    = "python",
                SupportedRuntimeVersions = new List <string>()
                {
                    "3.6", "3.7"
                },
                DefaultWorkerPath = $"{RpcWorkerConstants.RuntimeVersionPlaceholder}/worker.py",
                WorkerDirectory   = string.Empty,
                Extensions        = new List <string>()
                {
                    ".py"
                },
                Language = "python",
                DefaultRuntimeVersion = "3.7" // Ignore this if environment is set
            };
            var testLogger = new TestLogger("test");

            workerDescription.FormatWorkerPathIfNeeded(_testSysRuntimeInfo, _testEnvironment, testLogger);
            Assert.Equal("3.7", workerDescription.DefaultRuntimeVersion);
        }
        public void LanguageWorker_FormatWorkerPath_EnvironmentVersionSet(
            string defaultWorkerPath,
            string environmentRuntimeVersion,
            string sanitizeRuntimeVersionRegex,
            string expectedPath)
        {
            _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, "python");
            _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, environmentRuntimeVersion);
            RpcWorkerDescription workerDescription = new RpcWorkerDescription()
            {
                Arguments                   = new List <string>(),
                DefaultExecutablePath       = "python",
                DefaultWorkerPath           = defaultWorkerPath,
                DefaultRuntimeVersion       = "3.6",
                SanitizeRuntimeVersionRegex = sanitizeRuntimeVersionRegex,
                SupportedArchitectures      = new List <string>()
                {
                    Architecture.X64.ToString(), Architecture.X86.ToString()
                },
                SupportedRuntimeVersions = new List <string>()
                {
                    "3.6", "3.7"
                },
                SupportedOperatingSystems = new List <string>()
                {
                    OSPlatform.Windows.ToString(),
                                 OSPlatform.OSX.ToString(),
                                 OSPlatform.Linux.ToString()
                },
                WorkerDirectory = string.Empty,
                Extensions      = new List <string>()
                {
                    ".py"
                },
                Language = "python"
            };
            var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
                                .AddInMemoryCollection(new Dictionary <string, string>
            {
                ["languageWorker"] = "test"
            });
            var config = configBuilder.Build();
            var scriptSettingsManager = new ScriptSettingsManager(config);
            var testLogger            = new TestLogger("test");

            workerDescription.FormatWorkerPathIfNeeded(_testSysRuntimeInfo, _testEnvironment, testLogger);

            // Override file exists to return true
            workerDescription.FileExists = path =>
            {
                Assert.Equal(workerDescription.DefaultWorkerPath, path);
                return(true);
            };

            Assert.Equal(expectedPath, workerDescription.DefaultWorkerPath);

            var expectedLogMessage = string.Format($"EnvironmentVariable FUNCTIONS_WORKER_RUNTIME_VERSION: {environmentRuntimeVersion}");

            Assert.Collection(testLogger.GetLogMessages(), p => Assert.Equal(expectedLogMessage, p.FormattedMessage));
        }
Exemplo n.º 8
0
        public static IList <RpcWorkerConfig> GetTestWorkerConfigsNoLanguage()
        {
            var workerDesc = new RpcWorkerDescription();

            return(new List <RpcWorkerConfig>()
            {
                new RpcWorkerConfig()
                {
                    Description = workerDesc
                }
            });
        }
        public void LanguageWorker_FormatWorkerPath_EnvironmentVersionNotSet(
            string defaultWorkerPath,
            string sanitizeRuntimeVersionRegex,
            string expectedPath)
        {
            // We fall back to the default version when this is not set
            // Environment.SetEnvironmentVariable(LanguageWorkerConstants.FunctionWorkerRuntimeVersionSettingName, "3.7");

            RpcWorkerDescription workerDescription = new RpcWorkerDescription()
            {
                Arguments              = new List <string>(),
                DefaultExecutablePath  = "python",
                SupportedArchitectures = new List <string>()
                {
                    Architecture.X64.ToString(), Architecture.X86.ToString()
                },
                SupportedRuntimeVersions = new List <string>()
                {
                    "3.6", "3.7"
                },
                SupportedOperatingSystems = new List <string>()
                {
                    OSPlatform.Windows.ToString(),
                                 OSPlatform.OSX.ToString(),
                                 OSPlatform.Linux.ToString()
                },
                DefaultWorkerPath = defaultWorkerPath,
                WorkerDirectory   = string.Empty,
                Extensions        = new List <string>()
                {
                    ".py"
                },
                Language = "python",
                DefaultRuntimeVersion       = "3.6",
                SanitizeRuntimeVersionRegex = sanitizeRuntimeVersionRegex
            };
            var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
                                .AddInMemoryCollection(new Dictionary <string, string>
            {
                ["languageWorker"] = "test"
            });
            var config = configBuilder.Build();
            var scriptSettingsManager = new ScriptSettingsManager(config);
            var testLogger            = new TestLogger("test");

            workerDescription.FormatWorkerPathIfNeeded(_testSysRuntimeInfo, _testEnvironment, testLogger);

            Assert.Equal(expectedPath, workerDescription.DefaultWorkerPath);
            Assert.Equal("3.6", workerDescription.DefaultRuntimeVersion);
        }
        public void LanguageWorker_HydratedWorkerPath_UnsupportedArchitecture(Architecture unsupportedArch)
        {
            RpcWorkerDescription workerDescription = new RpcWorkerDescription()
            {
                Arguments              = new List <string>(),
                DefaultExecutablePath  = "python",
                DefaultWorkerPath      = "{architecture}/worker.py",
                WorkerDirectory        = string.Empty,
                SupportedArchitectures = new List <string>()
                {
                    Architecture.X64.ToString(), Architecture.X86.ToString()
                },
                SupportedRuntimeVersions = new List <string>()
                {
                    "3.6", "3.7"
                },
                SupportedOperatingSystems = new List <string>()
                {
                    OSPlatform.Windows.ToString(),
                                 OSPlatform.OSX.ToString(),
                                 OSPlatform.Linux.ToString()
                },
                Extensions = new List <string>()
                {
                    ".py"
                },
                Language = "python",
                DefaultRuntimeVersion = "3.7"
            };
            var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
                                .AddInMemoryCollection(new Dictionary <string, string>
            {
                ["languageWorker"] = "test"
            });
            var config = configBuilder.Build();
            var scriptSettingsManager = new ScriptSettingsManager(config);
            var testLogger            = new TestLogger("test");
            Mock <ISystemRuntimeInformation> mockRuntimeInfo = new Mock <ISystemRuntimeInformation>();

            mockRuntimeInfo.Setup(r => r.GetOSArchitecture()).Returns(unsupportedArch);
            mockRuntimeInfo.Setup(r => r.GetOSPlatform()).Returns(OSPlatform.Linux);
            var configFactory = new RpcWorkerConfigFactory(config, testLogger, mockRuntimeInfo.Object, _testEnvironment, new TestMetricsLogger());

            var ex = Assert.Throws <PlatformNotSupportedException>(() => configFactory.GetHydratedWorkerPath(workerDescription));

            Assert.Equal(ex.Message, $"Architecture {unsupportedArch.ToString()} is not supported for language {workerDescription.Language}");
        }
Exemplo n.º 11
0
        public static WorkerDescription GetTestHttpInvokerDescription(string[] arguments, bool invalid = false)
        {
            if (invalid)
            {
                return(new RpcWorkerDescription());
            }
            RpcWorkerDescription workerDescription = new RpcWorkerDescription()
            {
                DefaultExecutablePath = HttpInvokerExe
            };

            if (arguments != null)
            {
                workerDescription.Arguments = arguments.ToList();
            }
            return(workerDescription);
        }
Exemplo n.º 12
0
        public void LanguageWorker_HydratedWorkerPath_EnvironmentVersionNotSet(string defaultWorkerPath, string expectedPath)
        {
            // We fall back to the default version when this is not set
            // Environment.SetEnvironmentVariable(LanguageWorkerConstants.FunctionWorkerRuntimeVersionSettingName, "3.7");

            RpcWorkerDescription workerDescription = new RpcWorkerDescription()
            {
                Arguments              = new List <string>(),
                DefaultExecutablePath  = "python",
                SupportedArchitectures = new List <string>()
                {
                    Architecture.X64.ToString(), Architecture.X86.ToString()
                },
                SupportedRuntimeVersions = new List <string>()
                {
                    "3.6", "3.7"
                },
                SupportedOperatingSystems = new List <string>()
                {
                    OSPlatform.Windows.ToString(),
                                 OSPlatform.OSX.ToString(),
                                 OSPlatform.Linux.ToString()
                },
                DefaultWorkerPath = defaultWorkerPath,
                WorkerDirectory   = string.Empty,
                Extensions        = new List <string>()
                {
                    ".py"
                },
                Language = "python",
                DefaultRuntimeVersion = "3.6"
            };
            var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
                                .AddInMemoryCollection(new Dictionary <string, string>
            {
                ["languageWorker"] = "test"
            });
            var config = configBuilder.Build();
            var scriptSettingsManager = new ScriptSettingsManager(config);
            var testLogger            = new TestLogger("test");
            var configFactory         = new RpcWorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, _testEnvironment, new TestMetricsLogger());

            Assert.Equal(expectedPath, configFactory.GetHydratedWorkerPath(workerDescription));
            Assert.Collection(testLogger.GetLogMessages(),
                              p => Assert.Equal("EnvironmentVariable FUNCTIONS_WORKER_RUNTIME_VERSION: 3.6", p.FormattedMessage));
        }
        public void LanguageWorker_HydratedWorkerPath_EnvironmentVersionSet(string defaultWorkerPath, string expectedPath)
        {
            _testEnvironment.SetEnvironmentVariable(LanguageWorkerConstants.FunctionWorkerRuntimeVersionSettingName, "3.7");

            RpcWorkerDescription workerDescription = new RpcWorkerDescription()
            {
                Arguments              = new List <string>(),
                DefaultExecutablePath  = "python",
                DefaultWorkerPath      = defaultWorkerPath,
                DefaultRuntimeVersion  = "3.6",
                SupportedArchitectures = new List <string>()
                {
                    Architecture.X64.ToString(), Architecture.X86.ToString()
                },
                SupportedRuntimeVersions = new List <string>()
                {
                    "3.6", "3.7"
                },
                SupportedOperatingSystems = new List <string>()
                {
                    OSPlatform.Windows.ToString(),
                                 OSPlatform.OSX.ToString(),
                                 OSPlatform.Linux.ToString()
                },
                WorkerDirectory = string.Empty,
                Extensions      = new List <string>()
                {
                    ".py"
                },
                Language = "python"
            };
            var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
                                .AddInMemoryCollection(new Dictionary <string, string>
            {
                ["languageWorker"] = "test"
            });
            var config = configBuilder.Build();
            var scriptSettingsManager = new ScriptSettingsManager(config);
            var testLogger            = new TestLogger("test");
            var configFactory         = new WorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, _testEnvironment);

            Assert.Equal(expectedPath, configFactory.GetHydratedWorkerPath(workerDescription));
        }
Exemplo n.º 14
0
        public void ValidateWorkerDescription_DoesNotModifyDefaultWorkerExecutablePath_WhenDoesNotStrictlyMatchDotNet(
            string defaultExecutablePath)
        {
            var testLogger = new TestLogger(testLanguage);

            var workerDescription = new RpcWorkerDescription
            {
                Language              = testLanguage,
                Extensions            = new List <string>(),
                DefaultExecutablePath = defaultExecutablePath,
                FileExists            = path =>
                {
                    Assert.True(false, "FileExists should not be called");
                    return(false);
                }
            };

            workerDescription.ApplyDefaultsAndValidate(Directory.GetCurrentDirectory(), testLogger);
            Assert.Equal(defaultExecutablePath, workerDescription.DefaultExecutablePath);
        }
Exemplo n.º 15
0
        public void LanguageWorker_FormatWorkerPath_UnsupportedOS()
        {
            OSPlatform           bogusOS           = OSPlatform.Create("BogusOS");
            RpcWorkerDescription workerDescription = new RpcWorkerDescription()
            {
                Arguments                 = new List <string>(),
                DefaultExecutablePath     = "python",
                DefaultWorkerPath         = "{os}/worker.py",
                SupportedOperatingSystems = new List <string>()
                {
                    OSPlatform.Windows.ToString(),
                                 OSPlatform.OSX.ToString(),
                                 OSPlatform.Linux.ToString()
                },
                WorkerDirectory = string.Empty,
                Extensions      = new List <string>()
                {
                    ".py"
                },
                Language = "python",
                DefaultRuntimeVersion = "3.7"
            };
            var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
                                .AddInMemoryCollection(new Dictionary <string, string>
            {
                ["languageWorker"] = "test"
            });
            var config = configBuilder.Build();
            var scriptSettingsManager = new ScriptSettingsManager(config);
            var testLogger            = new TestLogger("test");
            Mock <ISystemRuntimeInformation> mockRuntimeInfo = new Mock <ISystemRuntimeInformation>();

            mockRuntimeInfo.Setup(r => r.GetOSArchitecture()).Returns(Architecture.X64);
            mockRuntimeInfo.Setup(r => r.GetOSPlatform()).Returns(bogusOS);

            var ex = Assert.Throws <PlatformNotSupportedException>(() => workerDescription.FormatWorkerPathIfNeeded(mockRuntimeInfo.Object, _testEnvironment, testLogger));

            Assert.Equal(ex.Message, $"OS BogusOS is not supported for language {workerDescription.Language}");
        }
        public void AddArgumentsFromAppSettings_JavaOpts(string expectedArgument, string javaOpts)
        {
            RpcWorkerDescription workerDescription = new RpcWorkerDescription()
            {
                Arguments = new List <string>()
                {
                    "-jar"
                },
                DefaultExecutablePath = "java",
                DefaultWorkerPath     = "javaworker.jar",
                Extensions            = new List <string>()
                {
                    ".jar"
                },
                Language = "java"
            };
            var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
                                .AddInMemoryCollection(new Dictionary <string, string>
            {
                ["languageWorker"] = "test",
                ["languageWorkers:java:arguments"] = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
            });
            var config = configBuilder.Build();
            var scriptSettingsManager = new ScriptSettingsManager(config);
            var testLogger            = new TestLogger("test");
            var configFactory         = new WorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, _testEnvironment);
            var languageSection       = config.GetSection("languageWorkers:java");
            var testEnvVariables      = new Dictionary <string, string>
            {
                { "JAVA_OPTS", javaOpts }
            };

            using (var variables = new TestScopedSettings(scriptSettingsManager, testEnvVariables))
            {
                WorkerConfigFactory.AddArgumentsFromAppSettings(workerDescription, languageSection);
                Assert.Equal(2, workerDescription.Arguments.Count);
                Assert.Equal(expectedArgument, workerDescription.Arguments[1]);
            }
        }