Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ public static IApplicationBuilder UseWebJobsScriptHost(this IApplicationBuilder
config.UseMiddleware<HostWarmupMiddleware>();
});

// This middleware must be registered before any other middleware depending on
// JobHost/ScriptHost scoped services.
builder.UseMiddleware<ScriptHostRequestServiceProviderMiddleware>();
builder.UseWhen(context => !context.Request.IsAdminResumeRequest(), config =>
{
// This middleware must be registered before any other middleware depending on
// JobHost/ScriptHost scoped services.
config.UseMiddleware<ScriptHostRequestServiceProviderMiddleware>();
});

if (environment.IsLinuxAzureManagedHosting())
{
Expand Down
6 changes: 6 additions & 0 deletions src/WebJobs.Script/Extensions/HttpRequestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class HttpRequestExtensions
{
private static readonly PathString _adminRoot = new PathString("/admin");
private static readonly PathString _adminDownloadRequestRoot = new PathString("/admin/functions/download");
private static readonly PathString _adminResumeRequestRoot = new PathString("/admin/host/resume");

public static bool IsAdminRequest(this HttpRequest request)
{
Expand All @@ -35,6 +36,11 @@ public static bool IsAdminDownloadRequest(this HttpRequest request)
return request.Path.StartsWithSegments(_adminDownloadRequestRoot);
}

public static bool IsAdminResumeRequest(this HttpRequest request)
{
return request.Path.StartsWithSegments(_adminResumeRequestRoot);
}

public static TValue GetRequestPropertyOrDefault<TValue>(this HttpRequest request, string key)
{
if (request.HttpContext != null &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Script.Configuration;
using Microsoft.Azure.WebJobs.Script.WebHost.Models;
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.WebJobs.Script.Tests;
using Newtonsoft.Json;
using Xunit;
Expand Down Expand Up @@ -43,9 +48,10 @@ public async Task DrainModeEnabled_RunningHost_StartsNewHost_ReturnsOk()

// Validate host is "Running" after resume is called
response = await SamplesTestHelpers.InvokeResume(this);
Assert.True(HttpStatusCode.OK == response.StatusCode,
string.Join(Environment.NewLine, Host.GetWebHostLogMessages().Where(m => m.Level == LogLevel.Error).Select(m => m.ToString())));
responseString = await response.Content.ReadAsStringAsync();
var resumeStatus = JsonConvert.DeserializeObject<ResumeStatus>(responseString);

Assert.Equal(ScriptHostState.Running, resumeStatus.State);

// Validate the drain state is changed to "Disabled"
Expand Down Expand Up @@ -88,18 +94,21 @@ public async Task DrainModeDisabled_RunningHost_ReturnsOk()

public class ResumeTestFixture : EndToEndTestFixture
{
static ResumeTestFixture()
{
}

public ResumeTestFixture()
: base(Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "..", "sample", "NodeResume"), "samples", RpcWorkerConstants.NodeLanguageWorkerName)
{
}

public override void ConfigureScriptHost(IWebJobsBuilder webJobsBuilder)
public override void ConfigureWebHost(IConfigurationBuilder configBuilder)
{
base.ConfigureScriptHost(webJobsBuilder);
base.ConfigureWebHost(configBuilder);

configBuilder.AddInMemoryCollection(new Dictionary<string, string>
{
// This forces the hosts to be stopped and disposed before a new one starts.
// There was a bug hiding here originally, so we'll run all these tests this way.
{ ConfigurationSectionNames.SequentialJobHostRestart, "true" }
});
}
}
}