Skip to content

Conversation

@Francisco-Gamino
Copy link
Contributor

@Francisco-Gamino Francisco-Gamino commented Jun 7, 2019

This PR contains the following changes:

  • Fixing faulty logic in InstallFunctionAppDependencies, so that if an exception thrown, it will get caught, logged, and wrapped in a DependencyInstallationException for post processing.
  • Adding unit test to validate installing the function app dependencies and the installation retry logic
  • Adding logic to dependency manager to fail in the first dependencies installation run if the PSGallery could not be reached, but continue if previous dependencies exist.
  • Adding unit test to validate that a function app execution should continue if the PSGallery could not be reached but a previous installation of managed dependencies exists.

After this code change, in the InstallFunctionAppDependencies, we perform two operations:

  1. Prepare the folder destination path where the function app dependencies will be installed.
  • If the destination folder exist, we try to empty it
  • If the folder does not exist, we create it
  1. Call Save-Module to install the function app dependency. If Save-Module fails, we log the error, and we retry for a total of three times.

If an issue is encountered in either (1) or (2) after three retries, the exception will be caught and wrapped in a DependencyInstallationException for post processing. This exception is expose via DependencyManager.DependencyError.

Added unit test to validate installing the function app dependencies and the installation retry logic. For this, calls to Save-Module are being mocked.

Installation flow for first install vs update
I added logic to dependency manager to fail in the first dependencies installation run if the PSGallery could not be reached, but continue if previous dependencies exist.

Lastly, I added unit tests to validate that a function app execution should continue if the PSGallery could not be reached but a previous installation of managed dependencies exists. For this, I've refactored code from DependencyManagementUtils to DependencyManager to be able to mock calls to the PSGallery to retrieve the latest module version.

… DependencyManager.cs to accommodate for unit test.
…endencies as well as a successful module download.
… DependencyManager.cs to accommodate for unit test.
…endencies as well as a successful module download.
var message = string.Format(PowerShellWorkerStrings.ModuleHasBeenInstalled, moduleName, version);
var filePath = Path.Join(path, TestFileName);
File.WriteAllText(filePath, message);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you really need a file? Why not just keep a list of messages in memory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can keep the module name and version in memory. Test case updated.

}

[Fact]
public void TestManagedDependencyRetryLogic()
Copy link
Contributor

Choose a reason for hiding this comment

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

TestManagedDependencyRetryLogic [](start = 20, length = 31)

Consider adding a test for the case when the retry logic kicks in and succeeds. In order to do simulate that, I would suggest passing a number to TestDependencyManager instead of just a boolean ShouldThrow (something like ShouldThrowCount).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Thanks for the suggestion.
I have added a new test case that succeeds after two failed attempts.

@AnatoliB: Could you please take another look?

…installation run if the PSGallery could not be reached, but continue if previous dependencies exist.
…tinue if the PSGallery could not be reached but a previous installation of managed dependencies exists.
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