public async Task VerifyDurableTaskHubNameIsAdded() { var vars = new Dictionary <string, string> { { EnvironmentSettingNames.WebSiteAuthEncryptionKey, TestHelpers.GenerateKeyHexString() }, { EnvironmentSettingNames.AzureWebsiteHostName, "appName.azurewebsites.net" } }; using (var env = new TestScopedEnvironmentVariable(vars)) { // Setup const string expectedSyncTriggersPayload = "[{\"authLevel\":\"anonymous\",\"type\":\"httpTrigger\",\"direction\":\"in\",\"name\":\"req\",\"functionName\":\"function1\"}," + "{\"name\":\"myQueueItem\",\"type\":\"orchestrationTrigger\",\"direction\":\"in\",\"queueName\":\"myqueue-items\",\"connection\":\"DurableStorage\",\"functionName\":\"function2\",\"taskHubName\":\"TestHubValue\"}," + "{\"name\":\"myQueueItem\",\"type\":\"activityTrigger\",\"direction\":\"in\",\"queueName\":\"myqueue-items\",\"connection\":\"DurableStorage\",\"functionName\":\"function3\",\"taskHubName\":\"TestHubValue\"}]"; var settings = CreateWebSettings(); var fileSystem = CreateFileSystem(settings.ScriptPath); var loggerFactory = MockNullLogerFactory.CreateLoggerFactory(); var contentBuilder = new StringBuilder(); var httpClient = CreateHttpClient(contentBuilder); var webManager = new WebFunctionsManager(new OptionsWrapper <ScriptApplicationHostOptions>(settings), new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient); FileUtility.Instance = fileSystem; // Act (var success, var error) = await webManager.TrySyncTriggers(); var content = contentBuilder.ToString(); // Assert Assert.True(success, "SyncTriggers should return success true"); Assert.True(string.IsNullOrEmpty(error), "Error should be null or empty"); Assert.Equal(expectedSyncTriggersPayload, content); } }
public async Task VerifyDurableTaskHubNameIsAdded() { // Setup const string expectedSyncTriggersPayload = "[{\"authLevel\":\"anonymous\",\"type\":\"httpTrigger\",\"direction\":\"in\",\"name\":\"req\",\"functionName\":\"function1\"}," + "{\"name\":\"myQueueItem\",\"type\":\"orchestrationTrigger\",\"direction\":\"in\",\"queueName\":\"myqueue-items\",\"connection\":\"DurableStorage\",\"functionName\":\"function2\",\"taskHubName\":\"TestHubValue\"}," + "{\"name\":\"myQueueItem\",\"type\":\"activityTrigger\",\"direction\":\"in\",\"queueName\":\"myqueue-items\",\"connection\":\"DurableStorage\",\"functionName\":\"function3\",\"taskHubName\":\"TestHubValue\"}]"; var settings = CreateWebSettings(); var fileSystem = CreateFileSystem(settings.ScriptPath); var loggerFactory = MockNullLogerFactory.CreateLoggerFactory(); var contentBuilder = new StringBuilder(); var httpClient = CreateHttpClient(contentBuilder); var webManager = new WebFunctionsManager(settings, loggerFactory, httpClient); FileUtility.Instance = fileSystem; Environment.SetEnvironmentVariable(EnvironmentSettingNames.WebSiteAuthEncryptionKey, TestHelpers.GenerateKeyHexString()); Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", "appName"); // Act (var success, var error) = await webManager.TrySyncTriggers(); var content = contentBuilder.ToString(); // Assert Assert.True(success, "SyncTriggers should return success true"); Assert.True(string.IsNullOrEmpty(error), "Error should be null or empty"); Assert.Equal(expectedSyncTriggersPayload, content); }
public void StartAssignment_ReturnsFalse_WhenNotInStandbyMode() { var loggerFactory = MockNullLogerFactory.CreateLoggerFactory(); var settingsManager = new ScriptSettingsManager(); var instanceManager = new InstanceManager(settingsManager, null, loggerFactory, null); Assert.False(WebScriptHostManager.InStandbyMode); var context = new HostAssignmentContext(); bool result = instanceManager.StartAssignment(context); Assert.False(result); }
public static void ReadFunctionsMetadataSucceeds() { string functionsPath = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\..\sample"); // Setup var settings = CreateWebSettings(); var fileSystem = CreateFileSystem(settings.ScriptPath); var loggerFactory = MockNullLogerFactory.CreateLoggerFactory(); var contentBuilder = new StringBuilder(); var httpClient = CreateHttpClient(contentBuilder); var webManager = new WebFunctionsManager(new OptionsWrapper <ScriptApplicationHostOptions>(settings), new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient); FileUtility.Instance = fileSystem; IEnumerable <FunctionMetadata> metadata = webManager.GetFunctionsMetadata(); var jsFunctions = metadata.Where(funcMetadata => funcMetadata.Language == LanguageWorkerConstants.NodeLanguageWorkerName).ToList(); var unknownFunctions = metadata.Where(funcMetadata => string.IsNullOrEmpty(funcMetadata.Language)).ToList(); Assert.Equal(2, jsFunctions.Count()); Assert.Equal(1, unknownFunctions.Count()); }
private static IFunctionDispatcher GetTestFunctionDispatcher() { var eventManager = new Mock <IScriptEventManager>(); var metricsLogger = new Mock <IMetricsLogger>(); var languageWorkerChannelManager = new Mock <ILanguageWorkerChannelManager>(); var loggerFactory = MockNullLogerFactory.CreateLoggerFactory(); var options = new ScriptJobHostOptions { RootLogPath = Path.GetTempPath() }; IOptions <ScriptJobHostOptions> scriptOptions = new OptionsManager <ScriptJobHostOptions>(new TestOptionsFactory <ScriptJobHostOptions>(options)); var workerConfigOptions = new LanguageWorkerOptions { WorkerConfigs = TestHelpers.GetTestWorkerConfigs() }; return(new FunctionDispatcher(scriptOptions, metricsLogger.Object, eventManager.Object, loggerFactory, new OptionsWrapper <LanguageWorkerOptions>(workerConfigOptions), languageWorkerChannelManager.Object)); }
public async Task StartAssignment_AppliesAssignmentContext() { var loggerFactory = MockNullLogerFactory.CreateLoggerFactory(); var settingsManager = new ScriptSettingsManager(); var instanceManager = new InstanceManager(settingsManager, null, loggerFactory, null); var envValue = new { Name = Path.GetTempFileName().Replace(".", string.Empty), Value = Guid.NewGuid().ToString() }; settingsManager.SetSetting(EnvironmentSettingNames.AzureWebsitePlaceholderMode, "1"); WebScriptHostManager.ResetStandbyMode(); var context = new HostAssignmentContext { Environment = new Dictionary <string, string> { { envValue.Name, envValue.Value } } }; bool result = instanceManager.StartAssignment(context); Assert.True(result); // specialization is done in the background await Task.Delay(500); var value = Environment.GetEnvironmentVariable(envValue.Name); Assert.Equal(value, envValue.Value); // calling again should return false, since we're no longer // in placeholder mode result = instanceManager.StartAssignment(context); Assert.False(result); }