Skip to content

Commit 7dc547c

Browse files
Bugfix for collection monitoring etag logic (#623)
* check response code before comparing etags when they may be null * fix ordering of etag check and response check * fix mock response etag header * fix select in tests * add comment to explain loadselected etag is never null
1 parent 662250e commit 7dc547c

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/AzureAppConfigurationProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,6 @@ await CallWithRequestTracing(async () =>
812812
{
813813
using Response response = page.GetRawResponse();
814814

815-
ETag serverEtag = (ETag)response.Headers.ETag;
816-
817815
foreach (ConfigurationSetting setting in page.Values)
818816
{
819817
data[setting.Key] = setting;
@@ -824,7 +822,9 @@ await CallWithRequestTracing(async () =>
824822
}
825823
}
826824

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

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/Extensions/ConfigurationClientExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ public static async Task<bool> HaveCollectionsChanged(this ConfigurationClient c
9595
{
9696
using Response response = page.GetRawResponse();
9797

98-
ETag serverEtag = (ETag)response.Headers.ETag;
99-
10098
// Return true if the lists of etags are different
10199
if ((!existingMatchConditionsEnumerator.MoveNext() ||
102-
!existingMatchConditionsEnumerator.Current.IfNoneMatch.Equals(serverEtag)) &&
100+
!existingMatchConditionsEnumerator.Current.IfNoneMatch.Equals(response.Headers.ETag)) &&
103101
response.Status == (int)HttpStatusCode.OK)
104102
{
105103
return true;

tests/Tests.AzureAppConfiguration/Azure.Core.Testing/MockResponse.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ public MockResponse(int status, string reasonPhrase = null)
1818
Status = status;
1919
ReasonPhrase = reasonPhrase;
2020

21-
AddHeader(new HttpHeader(HttpHeader.Names.ETag, "\"" + Guid.NewGuid().ToString() + "\""));
21+
if (status == 200)
22+
{
23+
AddHeader(new HttpHeader(HttpHeader.Names.ETag, "\"" + Guid.NewGuid().ToString() + "\""));
24+
}
2225
}
2326

2427
public override int Status { get; }

tests/Tests.AzureAppConfiguration/RefreshTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ public async Task RefreshTests_SelectedKeysRefreshWithRegisterAll()
10691069
.AddAzureAppConfiguration(options =>
10701070
{
10711071
options.ClientManager = TestHelpers.CreateMockedConfigurationClientManager(mockClient.Object);
1072-
options.Select("TestKey*");
1072+
options.Select("TestKey*", "label");
10731073
options.ConfigurationSettingPageIterator = new MockConfigurationSettingPageIterator();
10741074
options.ConfigureRefresh(refreshOptions =>
10751075
{
@@ -1159,7 +1159,7 @@ MockAsyncPageable GetTestKeys(SettingSelector selector, CancellationToken ct)
11591159
.AddAzureAppConfiguration(options =>
11601160
{
11611161
options.ClientManager = TestHelpers.CreateMockedConfigurationClientManager(mockClient.Object);
1162-
options.Select("TestKey*");
1162+
options.Select("TestKey*", "label");
11631163
options.ConfigurationSettingPageIterator = new MockConfigurationSettingPageIterator();
11641164
options.ConfigureRefresh(refreshOptions =>
11651165
{

0 commit comments

Comments
 (0)