-
Notifications
You must be signed in to change notification settings - Fork 638
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
DYN-7691: Add assembly load contexts to packages #15424
Open
pinzart90
wants to merge
19
commits into
master
Choose a base branch
from
pkg_alc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+778
−13
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f314596
add alc for packages
pinzart90 754a48b
Update PackageLoader.cs
pinzart90 ff6a99a
update
pinzart90 a1a2ecb
update
pinzart90 717b6a1
Merge branch 'master' into pkg_alc
pinzart90 bd259e4
Update Package.cs
pinzart90 19d4f2f
Update Package.cs
pinzart90 241081b
Update PackageLoader.cs
pinzart90 196b596
Update PackageLoader.cs
pinzart90 111587f
update
pinzart90 7cd30d6
Update PackageLoader.cs
pinzart90 da7753f
Update PackageLoader.cs
pinzart90 d4bbd2b
Update PackageLoader.cs
pinzart90 d256457
add test
pinzart90 2fb0e1a
update
pinzart90 3a23e80
update
pinzart90 d8d91fe
update
pinzart90 b90f7c0
Update FeatureFlagsClient.cs
pinzart90 561919b
Update PackageLoader.cs
pinzart90 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,17 @@ | |
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace DynamoUtilities | ||
{ | ||
|
||
internal interface IFFlags | ||
{ | ||
internal T CheckFeatureFlag<T>(DynamoFeatureFlagsManager mgr, string featureFlagKey, T defaultval); | ||
} | ||
|
||
/// <summary> | ||
/// A wrapper around the DynamoFeatureFlags CLI tool. | ||
|
@@ -20,9 +21,21 @@ namespace DynamoUtilities | |
/// </summary> | ||
internal class DynamoFeatureFlagsManager : CLIWrapper | ||
{ | ||
// Utility class that supports mocking during tests | ||
class FFlags : IFFlags | ||
{ | ||
T IFFlags.CheckFeatureFlag<T>(DynamoFeatureFlagsManager mgr, string featureFlagKey, T defaultval) | ||
{ | ||
return mgr.CheckFeatureFlagInternal(featureFlagKey, defaultval); | ||
} | ||
} | ||
|
||
// Useful for mocking in tests | ||
internal IFFlags flags { get; set; } = new FFlags(); | ||
private string relativePath = Path.Combine("DynamoFeatureFlags", "DynamoFeatureFlags.exe"); | ||
private Dictionary<string, object> AllFlagsCache { get; set; }//TODO lock is likely overkill. | ||
private SynchronizationContext syncContext; | ||
private readonly bool testmode = false; | ||
internal static event Action FlagsRetrieved; | ||
|
||
//TODO(DYN-6464)- remove this field!. | ||
|
@@ -43,8 +56,10 @@ internal class DynamoFeatureFlagsManager : CLIWrapper | |
/// <param name="syncContext">context used for raising FlagRetrieved event.</param> | ||
/// <param name="testmode">will not contact feature flag service in testmode, will respond with defaults.</param> | ||
internal DynamoFeatureFlagsManager(string userkey, SynchronizationContext syncContext, bool testmode=false) | ||
{ | ||
{ | ||
this.syncContext = syncContext; | ||
this.testmode = testmode; | ||
|
||
//dont pass userkey arg if null/empty | ||
var userkeyarg = $"-u {userkey}"; | ||
var testmodearg = string.Empty; | ||
|
@@ -62,7 +77,6 @@ internal DynamoFeatureFlagsManager(string userkey, SynchronizationContext syncCo | |
|
||
internal void CacheAllFlags() | ||
{ | ||
|
||
//wait for response | ||
var dataFromCLI = GetData(featureFlagTimeoutMs); | ||
//convert from json string to dictionary. | ||
|
@@ -91,6 +105,13 @@ internal void CacheAllFlags() | |
/// <param name="defaultval">Currently the flag and default val MUST be a bool or string.</param> | ||
/// <returns></returns> | ||
internal T CheckFeatureFlag<T>(string featureFlagKey, T defaultval) | ||
{ | ||
// with testmode = true, the call goes through an interface so that we can intercept it with Mock | ||
// with testmode = false, the call simply goes to the CheckFeatureFlagInternal | ||
return testmode ? flags.CheckFeatureFlag(this, featureFlagKey, defaultval) : CheckFeatureFlagInternal(featureFlagKey, defaultval); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a performance thing I guess |
||
} | ||
|
||
private T CheckFeatureFlagInternal<T>(string featureFlagKey, T defaultval) | ||
{ | ||
if(!(defaultval is bool || defaultval is string)){ | ||
throw new ArgumentException("unsupported flag type", defaultval.GetType().ToString()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -652,13 +652,21 @@ public void PlacingCustomNodeInstanceFromPackageRetainsCorrectPackageInfoState() | |
[Test] | ||
public void LoadPackagesInAssemblyIsolation() | ||
{ | ||
var ff = new Mock<DynamoUtilities.IFFlags>(); | ||
DynamoModel.FeatureFlags.flags = ff.Object; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make |
||
ff.Setup(x => x.CheckFeatureFlag<string>(DynamoModel.FeatureFlags, "IsolatePackages", "")).Returns(() => "Package1,Package2,Package"); | ||
ff.Setup(x => x.CheckFeatureFlag<string>(DynamoModel.FeatureFlags, "DoNotIsolatePackages", "")).Returns(() => "Package"); | ||
|
||
// Needed for FeatureFlags | ||
Assert.IsTrue(DynamoModel.IsTestMode); | ||
Assert.AreEqual("Package1,Package2,Package", DynamoModel.FeatureFlags.CheckFeatureFlag<string>("IsolatePackages", "")); | ||
Assert.AreEqual("Package", DynamoModel.FeatureFlags.CheckFeatureFlag<string>("DoNotIsolatePackages", "")); | ||
|
||
|
||
var loader = GetPackageLoader(); | ||
var pathManager = new Mock<Dynamo.Interfaces.IPathManager>(); | ||
pathManager.SetupGet(x => x.PackagesDirectories).Returns( | ||
() => new List<string> { PackagesDirectory }); | ||
|
||
var loader = new PackageLoader(pathManager.Object); | ||
var libraryLoader = new ExtensionLibraryLoader(CurrentDynamoModel); | ||
|
||
loader.PackagesLoaded += libraryLoader.LoadPackages; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may have tunnel vision, but I could not think of anything else to easily enable mocking.
I seem to need mocking because I am using the CheckFeatureFlag function in the PackageLoader
I tried to avoid refactoring the entire DynamoFeatureFlagsManager to be mockable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjkkirschner any other options that you see?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature flags cli already returns a set of static test flags in test mode - is that sufficient?