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

Bugfix for collection monitoring etag logic #623

Merged
merged 5 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,6 @@ await CallWithRequestTracing(async () =>
{
using Response response = page.GetRawResponse();

ETag serverEtag = (ETag)response.Headers.ETag;

foreach (ConfigurationSetting setting in page.Values)
{
data[setting.Key] = setting;
Expand All @@ -824,7 +822,9 @@ await CallWithRequestTracing(async () =>
}
}

matchConditions.Add(new MatchConditions { IfNoneMatch = serverEtag });
// The ETag will never be null here because it's not a conditional request
// Each successful response should have 200 status code and an ETag
matchConditions.Add(new MatchConditions { IfNoneMatch = response.Headers.ETag });
}
}).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ public static async Task<bool> HaveCollectionsChanged(this ConfigurationClient c
{
using Response response = page.GetRawResponse();

ETag serverEtag = (ETag)response.Headers.ETag;

// Return true if the lists of etags are different
if ((!existingMatchConditionsEnumerator.MoveNext() ||
!existingMatchConditionsEnumerator.Current.IfNoneMatch.Equals(serverEtag)) &&
!existingMatchConditionsEnumerator.Current.IfNoneMatch.Equals(response.Headers.ETag)) &&
response.Status == (int)HttpStatusCode.OK)
{
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public MockResponse(int status, string reasonPhrase = null)
Status = status;
ReasonPhrase = reasonPhrase;

AddHeader(new HttpHeader(HttpHeader.Names.ETag, "\"" + Guid.NewGuid().ToString() + "\""));
if (status == 200)
{
AddHeader(new HttpHeader(HttpHeader.Names.ETag, "\"" + Guid.NewGuid().ToString() + "\""));
}
}

public override int Status { get; }
Expand Down
4 changes: 2 additions & 2 deletions tests/Tests.AzureAppConfiguration/RefreshTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ public async Task RefreshTests_SelectedKeysRefreshWithRegisterAll()
.AddAzureAppConfiguration(options =>
{
options.ClientManager = TestHelpers.CreateMockedConfigurationClientManager(mockClient.Object);
options.Select("TestKey*");
options.Select("TestKey*", "label");
options.ConfigurationSettingPageIterator = new MockConfigurationSettingPageIterator();
options.ConfigureRefresh(refreshOptions =>
{
Expand Down Expand Up @@ -1159,7 +1159,7 @@ MockAsyncPageable GetTestKeys(SettingSelector selector, CancellationToken ct)
.AddAzureAppConfiguration(options =>
{
options.ClientManager = TestHelpers.CreateMockedConfigurationClientManager(mockClient.Object);
options.Select("TestKey*");
options.Select("TestKey*", "label");
options.ConfigurationSettingPageIterator = new MockConfigurationSettingPageIterator();
options.ConfigureRefresh(refreshOptions =>
{
Expand Down