Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix / refactor FunctionsHostingConfigOptionsTest #10890

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

jviau
Copy link
Contributor

@jviau jviau commented Feb 26, 2025

Issue describing the changes in this PR

resolves #10889

Pull request checklist

IMPORTANT: Currently, changes must be backported to the in-proc branch to be included in Core Tools and non-Flex deployments.

  • Backporting to the in-proc branch is not required -- TODO
    • Otherwise: Link to backporting PR
  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • My changes do not require diagnostic events changes
    • Otherwise: I have added/updated all related diagnostic events and their documentation (Documentation issue linked to PR)
  • I have added all required tests (Unit tests, E2E tests)

Additional information

Refactors FunctionsHostingConfigOptionsTest to stabilize and improve the tests.

  1. Removes ConfigureDefaultTestWebScriptHost usage
    • This is the main source of instability as it made these effectively integration tests. Using that host brings in a lot of other components. The unstable issue observed was bundle resolution was running and intermittently failing! It was even calling our CDN. Outbound HTTP calls in unit tests is not good.
  2. Splits the large Property_Validation test into two, one for validating access and another for validating expectations. Also converts these into a theory using MemberData.
  3. Removes unnecessary delays, host starts, and more from tests

@jviau jviau requested a review from a team as a code owner February 26, 2025 20:07
// Note: For legacy purposes (we used to call Configuration.Bind() on this object), some properties whose ScmHostingConfig key and
// property name match exactly need to support "True/False".
// It is recommended that new properties only look at "1/0" for their setting.
yield return new object[] { nameof(FunctionsHostingConfigOptions.DisableLinuxAppServiceExecutionDetails), "DisableLinuxExecutionDetails=1", true };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use collection expressions here to reduce some of the verbosity (e.g. yield return [nameof(FunctionsHostingConfigOptions.DisableLinuxAppServiceExecutionDetails), "DisableLinuxExecutionDetails=1", true];)

}

[Fact]
public void Inject_Succeded()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling: (previous issue) -> Inject_Succeeded

{
(nameof(FunctionsHostingConfigOptions.DisableLinuxAppServiceExecutionDetails), "DisableLinuxExecutionDetails=1", true),
(nameof(FunctionsHostingConfigOptions.DisableLinuxAppServiceLogBackoff), "DisableLinuxLogBackoff=1", true),
// make sure all props are internal to prevent inadverntent binding in the future
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling: inadvertent

.Where(p => p.Name != nameof(FunctionsHostingConfigOptions.Features));

foreach (var prop in props)
var prop = AllProperties.Select(x => x[0] as PropertyInfo).Single(p => p.Name == propertyName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p.Name == propertyName -> string.Equals with an explicit string comparison.

[InlineData("feature1", "value1")]
[InlineData("featuree1", null)]
public async Task Case_Insensitive(string key, string expectedValue)
public static IEnumerable<object[]> AllProperties
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace this with:

public static IEnumerable<PropertyInfo> AllProperties =>
    typeof(FunctionsHostingConfigOptions).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
        .Where(p => p.Name != nameof(FunctionsHostingConfigOptions.Features));

public static IEnumerable<object[]> AllPropertiesInput => AllProperties.Select(p => new[] { p });

Doing so would enable you to use AllPropertiesInput in the MemberData while changing the property match in line 151 with:

var prop = AllProperties.Single(p => string.Equals( p.Name, propertyName, StringComparison.Ordinal));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unstable test: FunctionsHostingConfigOptionsTest.Property_Validation
2 participants