-
Notifications
You must be signed in to change notification settings - Fork 250
feat(e2e): dynamically fetch VM extension version with caching, timeouts, and fallback #8064
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
Open
surajssd
wants to merge
9
commits into
main
Choose a base branch
from
suraj/optimize-extensio-version-lookup
base: main
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.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8bf1a58
feat(e2e): dynamically fetch latest VM extension version with caching
surajssd e244638
refactor(e2e): use slices.MaxFunc instead of sort.Slice for version l…
surajssd f2c91ba
test(e2e): add unit tests for cachedFunc memoization utility
surajssd ea69622
fix(e2e): add 30s context timeout to createVMExtensionLinuxAKSNode
surajssd 26f1183
fix(e2e): fall back to hardcoded VM extension version on discovery fa…
surajssd 1a9cf30
test(e2e): add unit tests for VM extension version parsing and compar…
surajssd 28a981a
fix(e2e): use %v instead of %w in fmt.Sprintf for panic message
surajssd 11558eb
test(e2e): fix flaky VM extension cache timing test
surajssd 7872d35
fix(e2e): add missing return in toolkit.Logf nil guard
surajssd 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "sync/atomic" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func Test_cachedFunc_returns_consistent_results(t *testing.T) { | ||
| var callCount atomic.Int32 | ||
| fn := cachedFunc(func(ctx context.Context, key string) (string, error) { | ||
| callCount.Add(1) | ||
| return "result-" + key, nil | ||
| }) | ||
|
|
||
| ctx := context.Background() | ||
| first, err := fn(ctx, "a") | ||
| require.NoError(t, err) | ||
|
|
||
| second, err := fn(ctx, "a") | ||
| require.NoError(t, err) | ||
|
|
||
| assert.Equal(t, first, second, "cached function should return the same result on repeated calls") | ||
| assert.Equal(t, int32(1), callCount.Load(), "underlying function should only be called once for the same key") | ||
| } | ||
|
|
||
| func Test_cachedFunc_warm_call_is_faster_than_cold(t *testing.T) { | ||
| fn := cachedFunc(func(ctx context.Context, key string) (string, error) { | ||
| // simulate a slow operation like a network call | ||
| time.Sleep(10 * time.Millisecond) | ||
| return "result", nil | ||
| }) | ||
|
|
||
| ctx := context.Background() | ||
|
|
||
| start := time.Now() | ||
| _, err := fn(ctx, "key") | ||
| coldDuration := time.Since(start) | ||
| require.NoError(t, err) | ||
|
|
||
| start = time.Now() | ||
| _, err = fn(ctx, "key") | ||
| warmDuration := time.Since(start) | ||
| require.NoError(t, err) | ||
|
|
||
| assert.Less(t, warmDuration, coldDuration, "warm (cached) call should be faster than cold call") | ||
| } | ||
|
|
||
| func Test_cachedFunc_different_keys_produce_different_cache_entries(t *testing.T) { | ||
| var callCount atomic.Int32 | ||
| fn := cachedFunc(func(ctx context.Context, key string) (string, error) { | ||
| callCount.Add(1) | ||
| return "result-" + key, nil | ||
| }) | ||
|
|
||
| ctx := context.Background() | ||
|
|
||
| resultA, err := fn(ctx, "a") | ||
| require.NoError(t, err) | ||
|
|
||
| resultB, err := fn(ctx, "b") | ||
| require.NoError(t, err) | ||
|
|
||
| assert.Equal(t, "result-a", resultA) | ||
| assert.Equal(t, "result-b", resultB) | ||
| assert.NotEqual(t, resultA, resultB, "different keys should produce different results") | ||
| assert.Equal(t, int32(2), callCount.Load(), "underlying function should be called once per unique key") | ||
| } | ||
|
|
||
| func Test_cachedFunc_caches_errors(t *testing.T) { | ||
| var callCount atomic.Int32 | ||
| expectedErr := fmt.Errorf("something went wrong") | ||
| fn := cachedFunc(func(ctx context.Context, key string) (string, error) { | ||
| callCount.Add(1) | ||
| return "", expectedErr | ||
| }) | ||
|
|
||
| ctx := context.Background() | ||
|
|
||
| _, err1 := fn(ctx, "a") | ||
| require.ErrorIs(t, err1, expectedErr) | ||
|
|
||
| _, err2 := fn(ctx, "a") | ||
| require.ErrorIs(t, err2, expectedErr) | ||
|
|
||
| assert.Equal(t, int32(1), callCount.Load(), "underlying function should only be called once even when it returns an error") | ||
| } | ||
|
|
||
| func Test_cachedFunc_with_struct_key(t *testing.T) { | ||
| type request struct { | ||
| Location string | ||
| Type string | ||
| } | ||
|
|
||
| var callCount atomic.Int32 | ||
| fn := cachedFunc(func(ctx context.Context, req request) (string, error) { | ||
| callCount.Add(1) | ||
| return req.Location + "-" + req.Type, nil | ||
| }) | ||
|
|
||
| ctx := context.Background() | ||
|
|
||
| r1, err := fn(ctx, request{Location: "eastus", Type: "ext1"}) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "eastus-ext1", r1) | ||
|
|
||
| // same key should return cached result | ||
| r2, err := fn(ctx, request{Location: "eastus", Type: "ext1"}) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, r1, r2) | ||
|
|
||
| // different key should call the function again | ||
| r3, err := fn(ctx, request{Location: "westus", Type: "ext1"}) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "westus-ext1", r3) | ||
|
|
||
| assert.Equal(t, int32(2), callCount.Load(), "underlying function should be called once per unique struct key") | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.