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

3776 - Latest version reports it is old #4220

Closed
wants to merge 5 commits into from

Conversation

VineethReyya
Copy link
Contributor

@VineethReyya VineethReyya commented Jan 7, 2025

Issue describing the changes in this PR

Fix1 : when we install Azure Function Core Tool via chocolatey, the shim is generating twice as we have 3.exe files (in root folder inproc6 and inproc8 folder). Now we have added additional checks to ignore func.exe from subfolders (inproc6 and inproc8 folder) and generate shim for func.exe in root directory.

Fix 2 : In VersionHelper.cs we have changed the logic to check whether latestCoreToolsAssemblyZipFile( by extracting the segment contains '.zip' from the download link) contains CliVersion (by adding '.zip')

resolves #3776

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • I have added all required tests (Unit tests, E2E tests)

@VineethReyya VineethReyya requested a review from a team as a code owner January 7, 2025 05:07
@VineethReyya VineethReyya linked an issue Jan 7, 2025 that may be closed by this pull request
umangsriv
umangsriv previously approved these changes Jan 7, 2025
aishwaryabh
aishwaryabh previously approved these changes Jan 7, 2025
src/Azure.Functions.Cli/Helpers/VersionHelper.cs Outdated Show resolved Hide resolved
{
try
{
var client = new System.Net.Http.HttpClient
client ??= new System.Net.Http.HttpClient
Copy link
Member

Choose a reason for hiding this comment

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

I'm concerned about creating a new instance of HttpClient here every time this method is called and not disposing it. I imagine you added the parameter here so you can provide a mocked client?

Instead, can we switch to either DI or a singleton for the HttpClient. With the singleton, you can still use a mocked client i.e.

// VersionHelper.cs
private static readonly HttpClient _httpClient = new HttpClient
{
    Timeout = TimeSpan.FromSeconds(1)
 };

// Test
// Set the singleton HttpClient to the mocked one for the test (using reflection or static setter)
        typeof(VersionHelper)
            .GetField("_httpClient", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
            .SetValue(null, httpClient);

DI is usually best

Copy link
Contributor Author

@VineethReyya VineethReyya Jan 8, 2025

Choose a reason for hiding this comment

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

Thanks for the review @liliankasem, I imagine you added the parameter here so you can provide a mocked client? -- Yes

we can dispose the client with using statement. Am I in the right direction?

using (client ??= new System.Net.Http.HttpClient{Timeout = TimeSpan.FromSeconds(1)})

please review the changes when you have a moment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't want to dispose the client then i can go with below code and its working fine
//versionhelper.cs
private static HttpClient _httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(1) };

//versiontest.cs

// Return HttpClient with mocked handler
var httpClient = new HttpClient(mockHandler.Object) { Timeout = TimeSpan.FromSeconds(1) };

typeof(VersionHelper)
.GetField("_httpClient", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
.SetValue(null, httpClient);

return httpClient;

Copy link
Member

Choose a reason for hiding this comment

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

Given this is only runs when the --help action is called, using a using statement here to dispose is fine. I didn't suggest this originally because I didn't think the using statement would work with the ??= operator, but if it does, let's do that.

src/Azure.Functions.Cli/Helpers/VersionHelper.cs Outdated Show resolved Hide resolved
@VineethReyya VineethReyya dismissed stale reviews from aishwaryabh and umangsriv via 1113312 January 8, 2025 08:39
@liliankasem
Copy link
Member

@VineethReyya can you break out these changes into a different PR?

I think the chocolatey script change that you describe in the PR description is not related to the VersionHelper change. Given this PR handles two different fixes, I would like them to be their own PRs so it's easier to track changes that break anything, and also easier to revert a single fix instead of both at the same time.

@VineethReyya
Copy link
Contributor Author

VineethReyya commented Jan 8, 2025

@VineethReyya can you break out these changes into a different PR?

I think the chocolatey script change that you describe in the PR description is not related to the VersionHelper change. Given this PR handles two different fixes, I would like them to be their own PRs so it's easier to track changes that break anything, and also easier to revert a single fix instead of both at the same time.

@liliankasem Both the fixes are related to same ticket.

@VineethReyya
Copy link
Contributor Author

@liliankasem created separate PRs for different issues. Part I, Part II. please have a look and review the changes.

@VineethReyya
Copy link
Contributor Author

closed this PR as new separate PRs created for fixes

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.

4 participants