Skip to content

Commit 12066b1

Browse files
authored
Include HostId in SyncTriggers payload always (#9726)
1 parent 4b6bd55 commit 12066b1

File tree

2 files changed

+10
-72
lines changed

2 files changed

+10
-72
lines changed

src/WebJobs.Script.WebHost/Management/FunctionsSyncManager.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -409,19 +409,12 @@ public async Task<SyncTriggersPayload> GetSyncTriggersPayload()
409409

410410
private JObject GetMinimalPayload(string hostId, JArray triggersArray)
411411
{
412-
JObject result = new JObject
412+
// When the HostId is sent, ScaleController will use it directly rather than compute it itself.
413+
return new JObject
413414
{
414-
{ "triggers", triggersArray }
415+
{ "triggers", triggersArray },
416+
{ "hostId", hostId }
415417
};
416-
417-
if (_environment.IsFlexConsumptionSku())
418-
{
419-
// Currently we're only sending the HostId for Flex Consumption. Eventually we'll do this for all SKUs.
420-
// When the HostId is sent, ScaleController will use it directly rather than compute it itself.
421-
result["hostId"] = hostId;
422-
}
423-
424-
return result;
425418
}
426419

427420
internal static async Task<JObject> GetHostJsonExtensionsAsync(IOptionsMonitor<ScriptApplicationHostOptions> applicationHostOptions, ILogger logger)

test/WebJobs.Script.Tests.Integration/Management/FunctionsSyncManagerTests.cs

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,9 @@ public async Task TrySyncTriggers_StandbyMode_ReturnsFalse()
187187
}
188188
}
189189

190-
[Theory]
191-
[InlineData(ScriptConstants.DynamicSku)]
192-
[InlineData(ScriptConstants.FlexConsumptionSku)]
193-
public async Task TrySyncTriggers_MaxSyncTriggersPayloadSize_Succeeds(string sku)
190+
[Fact]
191+
public async Task TrySyncTriggers_MaxSyncTriggersPayloadSize_Succeeds()
194192
{
195-
_mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteSku)).Returns(sku);
196-
197193
// create a dummy file that pushes us over size
198194
string maxString = new string('x', ScriptConstants.MaxTriggersStringLength + 1);
199195
_function1 = $"{{ bindings: [], test: '{maxString}'}}";
@@ -209,16 +205,8 @@ public async Task TrySyncTriggers_MaxSyncTriggersPayloadSize_Succeeds(string sku
209205
Assert.True(syncString.Length < ScriptConstants.MaxTriggersStringLength);
210206
var syncContent = JObject.Parse(syncString);
211207

212-
if (_mockEnvironment.Object.IsFlexConsumptionSku())
213-
{
214-
Assert.Equal(2, syncContent.Count);
215-
Assert.Equal("testhostid123", syncContent["hostId"]);
216-
}
217-
else
218-
{
219-
Assert.Equal(1, syncContent.Count);
220-
Assert.Equal(null, syncContent["hostId"]);
221-
}
208+
Assert.Equal(2, syncContent.Count);
209+
Assert.Equal("testhostid123", syncContent["hostId"]);
222210

223211
JArray triggers = (JArray)syncContent["triggers"];
224212
Assert.Equal(2, triggers.Count);
@@ -291,32 +279,6 @@ public async Task TrySyncTriggers_PostsExpectedContent(bool cacheEnabled, bool s
291279
}
292280
}
293281

294-
[Theory]
295-
[InlineData(ScriptConstants.DynamicSku)]
296-
[InlineData(ScriptConstants.FlexConsumptionSku)]
297-
public async Task TrySyncTriggers_PostsExpectedContent_BySku(string sku)
298-
{
299-
_mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteSku)).Returns(sku);
300-
301-
using (var env = new TestScopedEnvironmentVariable(_vars))
302-
{
303-
// Act
304-
var syncResult = await _functionsSyncManager.TrySyncTriggersAsync();
305-
306-
// Assert
307-
Assert.True(syncResult.Success, "SyncTriggers should return success true");
308-
Assert.True(string.IsNullOrEmpty(syncResult.Error), "Error should be null or empty");
309-
310-
// verify expected headers
311-
Assert.Equal(ScriptConstants.FunctionsUserAgent, _mockHttpHandler.LastRequest.Headers.UserAgent.ToString());
312-
Assert.True(_mockHttpHandler.LastRequest.Headers.Contains(ScriptConstants.AntaresLogIdHeaderName));
313-
Assert.NotEmpty(_mockHttpHandler.LastRequest.Headers.GetValues(ScriptConstants.SiteRestrictedTokenHeaderName));
314-
Assert.NotEmpty(_mockHttpHandler.LastRequest.Headers.GetValues(ScriptConstants.SiteTokenHeaderName));
315-
316-
VerifyResultWithCacheOn(durableVersion: "V1");
317-
}
318-
}
319-
320282
private void VerifyResultWithCacheOn(string connection = DefaultTestConnection, string expectedTaskHub = "TestHubValue", string durableVersion = "V2")
321283
{
322284
var result = VerifyResultCommon(connection, expectedTaskHub, durableVersion);
@@ -356,16 +318,7 @@ public JObject VerifyResultCommon(string connection = DefaultTestConnection, str
356318
string expectedTriggersPayload = GetExpectedTriggersPayload(postedConnection: connection, postedTaskHub: expectedTaskHub, durableVersion);
357319

358320
var result = JObject.Parse(_contentBuilder.ToString());
359-
360-
bool isFlexConsumptionSku = _mockEnvironment.Object.IsFlexConsumptionSku();
361-
if (isFlexConsumptionSku)
362-
{
363-
Assert.Equal("testhostid123", result["hostId"]);
364-
}
365-
else
366-
{
367-
Assert.Null(result["hostId"]);
368-
}
321+
Assert.Equal("testhostid123", result["hostId"]);
369322

370323
// verify triggers
371324
var triggers = result["triggers"];
@@ -378,15 +331,7 @@ public JObject VerifyResultCommon(string connection = DefaultTestConnection, str
378331
var triggersLog = log.FormattedMessage.Substring(startIdx, endIdx - startIdx).Trim();
379332
var logObject = JObject.Parse(triggersLog);
380333

381-
if (isFlexConsumptionSku)
382-
{
383-
Assert.Equal("testhostid123", logObject["hostId"]);
384-
}
385-
else
386-
{
387-
Assert.Null(logObject["hostId"]);
388-
}
389-
334+
Assert.Equal("testhostid123", logObject["hostId"]);
390335
Assert.Equal(expectedTriggersPayload, logObject["triggers"].ToString(Formatting.None));
391336
Assert.False(triggersLog.Contains("secrets"));
392337

0 commit comments

Comments
 (0)