-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removing AllowSynchronousIO; hiding behind v2 compat mode
- Loading branch information
Showing
31 changed files
with
399 additions
and
168 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/WebJobs.Script.WebHost/Configuration/HttpBodyControlOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Azure.WebJobs.Hosting; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.WebHost.Configuration | ||
{ | ||
internal class HttpBodyControlOptions : IOptionsFormatter | ||
{ | ||
public bool AllowSynchronousIO { get; set; } | ||
|
||
public string Format() | ||
{ | ||
var options = new JObject | ||
{ | ||
{ nameof(AllowSynchronousIO), AllowSynchronousIO } | ||
}; | ||
|
||
return options.ToString(Formatting.Indented); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/WebJobs.Script.WebHost/Configuration/HttpBodyControlOptionsSetup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Azure.WebJobs.Script.Config; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.WebHost.Configuration | ||
{ | ||
internal class HttpBodyControlOptionsSetup : IConfigureOptions<HttpBodyControlOptions> | ||
{ | ||
private readonly IEnvironment _environment; | ||
|
||
public HttpBodyControlOptionsSetup(IEnvironment environment) | ||
{ | ||
_environment = environment; | ||
} | ||
|
||
public void Configure(HttpBodyControlOptions options) | ||
{ | ||
options.AllowSynchronousIO = _environment.IsV2CompatibilityMode() | ||
|| FeatureFlags.IsEnabled(ScriptConstants.FeatureFlagAllowSynchronousIO, _environment); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/WebJobs.Script.WebHost/Middleware/AllowSynchronousIOMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http.Features; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.WebHost.Middleware | ||
{ | ||
public class AllowSynchronousIOMiddleware | ||
{ | ||
private readonly RequestDelegate _next; | ||
|
||
public AllowSynchronousIOMiddleware(RequestDelegate next) | ||
{ | ||
_next = next; | ||
} | ||
|
||
public async Task Invoke(HttpContext context) | ||
{ | ||
var bodyControlFeature = context.Features.Get<IHttpBodyControlFeature>(); | ||
if (bodyControlFeature != null) | ||
{ | ||
bodyControlFeature.AllowSynchronousIO = true; | ||
} | ||
|
||
await _next.Invoke(context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
src/WebJobs.Script/Config/CompatibilityModeOptionsSetup.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
test/WebJobs.Script.Tests.Integration/Middleware/AllowSynchronousIOMiddlewareTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs.Script.WebHost; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Newtonsoft.Json.Linq; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Tests.Integration.Middleware | ||
{ | ||
public class AllowSynchronousIOMiddlewareTests | ||
{ | ||
[Fact] | ||
public async Task SyncRead_Fails_ByDefault() | ||
{ | ||
using (var host = GetHost()) | ||
{ | ||
HostSecretsInfo secrets = await host.SecretManager.GetHostSecretsAsync(); | ||
var response = await MakeRequest(host.HttpClient, secrets.MasterKey); | ||
|
||
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); | ||
|
||
var a = host.GetScriptHostLogMessages().Select(p => p.Exception?.ToString()); | ||
|
||
Assert.Contains(host.GetScriptHostLogMessages(), p => p.Exception != null && p.Exception.ToString().Contains("Synchronous operations are disallowed.")); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task SyncRead_Succeeds_WithFlag() | ||
{ | ||
using (var host = GetHost(d => d.Add(EnvironmentSettingNames.AzureWebJobsFeatureFlags, ScriptConstants.FeatureFlagAllowSynchronousIO))) | ||
{ | ||
HostSecretsInfo secrets = await host.SecretManager.GetHostSecretsAsync(); | ||
var response = await MakeRequest(host.HttpClient, secrets.MasterKey); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task SyncRead_Succeeds_InV2CompatMode() | ||
{ | ||
using (var host = GetHost(d => d.Add(EnvironmentSettingNames.FunctionsV2CompatibilityModeKey, "true"))) | ||
{ | ||
HostSecretsInfo secrets = await host.SecretManager.GetHostSecretsAsync(); | ||
var response = await MakeRequest(host.HttpClient, secrets.MasterKey); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
|
||
var content = await response.Content.ReadAsStringAsync(); | ||
} | ||
} | ||
|
||
private static TestFunctionHost GetHost(Action<IDictionary<string, string>> addEnvironmentVariables = null) | ||
{ | ||
string scriptPath = @"TestScripts\DirectLoad\"; | ||
string logPath = Path.Combine(Path.GetTempPath(), @"Functions"); | ||
|
||
var host = new TestFunctionHost(scriptPath, logPath, | ||
configureWebHostServices: s => | ||
{ | ||
IDictionary<string, string> dict = new Dictionary<string, string>(); | ||
addEnvironmentVariables?.Invoke(dict); | ||
s.AddSingleton<IEnvironment>(_ => new TestEnvironment(dict)); | ||
}); | ||
|
||
return host; | ||
} | ||
|
||
private static Task<HttpResponseMessage> MakeRequest(HttpClient client, string masterKey) | ||
{ | ||
var request = new HttpRequestMessage | ||
{ | ||
RequestUri = new Uri(string.Format($"http://localhost/api/function1?code={masterKey}&name=brett")), | ||
Method = HttpMethod.Post | ||
}; | ||
|
||
var input = new JObject | ||
{ | ||
{ "scenario", "syncRead" } | ||
}; | ||
|
||
request.Content = new StringContent(input.ToString(), Encoding.UTF8, "application/json"); | ||
|
||
return client.SendAsync(request); | ||
} | ||
} | ||
} |
Oops, something went wrong.