Skip to content

Commit

Permalink
fix xUnit1031 warning (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyuanliang-ms authored May 31, 2024
1 parent a9eacbc commit 03be006
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 99 deletions.
10 changes: 5 additions & 5 deletions tests/Tests.AzureAppConfiguration/FailoverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FailOverTests
contentType: "text");

[Fact]
public void FailOverTests_ReturnsAllClientsIfAllBackedOff()
public async Task FailOverTests_ReturnsAllClientsIfAllBackedOff()
{
// Arrange
IConfigurationRefresher refresher = null;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void FailOverTests_ReturnsAllClientsIfAllBackedOff()
// Assert the inner request failed exceptions
Assert.True((exception.InnerException as AggregateException)?.InnerExceptions?.All(e => e is RequestFailedException) ?? false);

refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

// The client manager should have called RefreshClients when all clients were backed off
Assert.Equal(1, configClientManager.RefreshClientsCalled);
Expand Down Expand Up @@ -144,7 +144,7 @@ public void FailOverTests_PropagatesNonFailOverableExceptions()
}

[Fact]
public void FailOverTests_BackoffStateIsUpdatedOnSuccessfulRequest()
public async Task FailOverTests_BackoffStateIsUpdatedOnSuccessfulRequest()
{
// Arrange
IConfigurationRefresher refresher = null;
Expand Down Expand Up @@ -199,7 +199,7 @@ public void FailOverTests_BackoffStateIsUpdatedOnSuccessfulRequest()
refresher = options.GetRefresher();
}).Build();

refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

// The first client should not have been called during refresh
mockClient1.Verify(mc => mc.GetConfigurationSettingAsync(It.IsAny<ConfigurationSetting>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()), Times.Exactly(0));
Expand All @@ -211,7 +211,7 @@ public void FailOverTests_BackoffStateIsUpdatedOnSuccessfulRequest()
// Wait for client 1 backoff to end
Thread.Sleep(2500);

refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

// The first client should have been called now with refresh after the backoff time ends
mockClient1.Verify(mc => mc.GetConfigurationSettingAsync(It.IsAny<ConfigurationSetting>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()), Times.Exactly(1));
Expand Down
26 changes: 13 additions & 13 deletions tests/Tests.AzureAppConfiguration/FeatureManagementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public void UsesFeatureFlags()
}

[Fact]
public void WatchesFeatureFlags()
public async Task WatchesFeatureFlags()
{
var featureFlags = new List<ConfigurationSetting> { _kv };

Expand Down Expand Up @@ -513,7 +513,7 @@ public void WatchesFeatureFlags()

// Sleep to let the cache expire
Thread.Sleep(cacheExpirationTimeSpan);
refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

Assert.Equal("Browser", config["FeatureManagement:Beta:EnabledFor:0:Name"]);
Assert.Equal("Chrome", config["FeatureManagement:Beta:EnabledFor:0:Parameters:AllowedBrowsers:0"]);
Expand All @@ -523,7 +523,7 @@ public void WatchesFeatureFlags()


[Fact]
public void SkipRefreshIfCacheNotExpired()
public async Task SkipRefreshIfCacheNotExpired()
{
var featureFlags = new List<ConfigurationSetting> { _kv };

Expand Down Expand Up @@ -581,7 +581,7 @@ public void SkipRefreshIfCacheNotExpired()

featureFlags.Add(_kv2);

refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

Assert.Equal("Browser", config["FeatureManagement:Beta:EnabledFor:0:Name"]);
Assert.Equal("Firefox", config["FeatureManagement:Beta:EnabledFor:0:Parameters:AllowedBrowsers:0"]);
Expand Down Expand Up @@ -618,7 +618,7 @@ public void PreservesDefaultQuery()
}

[Fact]
public void QueriesFeatureFlags()
public async Task QueriesFeatureFlags()
{
var mockTransport = new MockTransport(req =>
{
Expand Down Expand Up @@ -646,7 +646,7 @@ public void QueriesFeatureFlags()
}

[Fact]
public void UsesEtagForFeatureFlagRefresh()
public async Task UsesEtagForFeatureFlagRefresh()
{
var mockClient = new Mock<ConfigurationClient>(MockBehavior.Strict);
mockClient.Setup(c => c.GetConfigurationSettingsAsync(It.IsAny<SettingSelector>(), It.IsAny<CancellationToken>()))
Expand All @@ -667,7 +667,7 @@ public void UsesEtagForFeatureFlagRefresh()
// Sleep to let the cache expire
Thread.Sleep(cacheExpirationTimeSpan);

refresher.TryRefreshAsync().Wait();
await refresher.TryRefreshAsync();
mockClient.Verify(c => c.GetConfigurationSettingsAsync(It.IsAny<SettingSelector>(), It.IsAny<CancellationToken>()), Times.Exactly(3));
}

Expand Down Expand Up @@ -1025,7 +1025,7 @@ public void MultipleCallsToUseFeatureFlagsWithSelectAndLabel()
}

[Fact]
public void DifferentCacheExpirationsForMultipleFeatureFlagRegistrations()
public async Task DifferentCacheExpirationsForMultipleFeatureFlagRegistrations()
{
var mockResponse = new Mock<Response>();
var mockClient = new Mock<ConfigurationClient>(MockBehavior.Strict);
Expand Down Expand Up @@ -1111,7 +1111,7 @@ public void DifferentCacheExpirationsForMultipleFeatureFlagRegistrations()

// Sleep to let the cache for feature flag with label1 expire
Thread.Sleep(cacheExpiration1);
refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

Assert.Equal("Browser", config["FeatureManagement:App1_Feature1:EnabledFor:0:Name"]);
Assert.Equal("Chrome", config["FeatureManagement:App1_Feature1:EnabledFor:0:Parameters:AllowedBrowsers:0"]);
Expand All @@ -1125,7 +1125,7 @@ public void DifferentCacheExpirationsForMultipleFeatureFlagRegistrations()
}

[Fact]
public void OverwrittenCacheExpirationForSameFeatureFlagRegistrations()
public async Task OverwrittenCacheExpirationForSameFeatureFlagRegistrations()
{
var mockResponse = new Mock<Response>();
var mockClient = new Mock<ConfigurationClient>(MockBehavior.Strict);
Expand Down Expand Up @@ -1188,7 +1188,7 @@ public void OverwrittenCacheExpirationForSameFeatureFlagRegistrations()
eTag: new ETag("c3c231fd-39a0-4cb6-3237-4614474b92c1" + "f"));

Thread.Sleep(cacheExpiration1);
refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

// The cache expiration time for feature flags was overwritten by second call to UseFeatureFlags.
// Sleeping for cacheExpiration1 time should not update feature flags.
Expand All @@ -1200,7 +1200,7 @@ public void OverwrittenCacheExpirationForSameFeatureFlagRegistrations()
}

[Fact]
public void SelectAndRefreshSingleFeatureFlag()
public async Task SelectAndRefreshSingleFeatureFlag()
{
var mockResponse = new Mock<Response>();
var mockClient = new Mock<ConfigurationClient>(MockBehavior.Strict);
Expand Down Expand Up @@ -1258,7 +1258,7 @@ public void SelectAndRefreshSingleFeatureFlag()

// Sleep to let the cache for feature flag with label1 expire
Thread.Sleep(cacheExpiration);
refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

Assert.Equal("Browser", config["FeatureManagement:Feature1:EnabledFor:0:Name"]);
Assert.Equal("Chrome", config["FeatureManagement:Feature1:EnabledFor:0:Parameters:AllowedBrowsers:0"]);
Expand Down
20 changes: 10 additions & 10 deletions tests/Tests.AzureAppConfiguration/KeyVaultReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public void ThrowsWhenSecretRefreshIntervalIsTooShort()
}

[Fact]
public void SecretIsReturnedFromCacheIfSecretCacheHasNotExpired()
public async Task SecretIsReturnedFromCacheIfSecretCacheHasNotExpired()
{
IConfigurationRefresher refresher = null;
TimeSpan cacheExpirationTime = TimeSpan.FromSeconds(1);
Expand Down Expand Up @@ -745,7 +745,7 @@ Response<ConfigurationSetting> GetIfChanged(ConfigurationSetting setting, bool o
// Update sentinel key-value
sentinelKv.Value = "Value2";
Thread.Sleep(cacheExpirationTime);
refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

Assert.Equal("Value2", config["Sentinel"]);
Assert.Equal(_secretValue, config[_kv.Key]);
Expand All @@ -756,7 +756,7 @@ Response<ConfigurationSetting> GetIfChanged(ConfigurationSetting setting, bool o
}

[Fact]
public void CachedSecretIsInvalidatedWhenRefreshAllIsTrue()
public async Task CachedSecretIsInvalidatedWhenRefreshAllIsTrue()
{
IConfigurationRefresher refresher = null;
TimeSpan cacheExpirationTime = TimeSpan.FromSeconds(1);
Expand Down Expand Up @@ -817,7 +817,7 @@ Response<ConfigurationSetting> GetIfChanged(ConfigurationSetting setting, bool o
// Update sentinel key-value to trigger refresh operation
sentinelKv.Value = "Value2";
Thread.Sleep(cacheExpirationTime);
refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

Assert.Equal("Value2", config["Sentinel"]);
Assert.Equal(_secretValue, config[_kv.Key]);
Expand All @@ -828,7 +828,7 @@ Response<ConfigurationSetting> GetIfChanged(ConfigurationSetting setting, bool o
}

[Fact]
public void SecretIsReloadedFromKeyVaultWhenCacheExpires()
public async Task SecretIsReloadedFromKeyVaultWhenCacheExpires()
{
IConfigurationRefresher refresher = null;
TimeSpan cacheExpirationTime = TimeSpan.FromSeconds(1);
Expand Down Expand Up @@ -862,7 +862,7 @@ public void SecretIsReloadedFromKeyVaultWhenCacheExpires()

// Sleep to let the secret cache expire
Thread.Sleep(cacheExpirationTime);
refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

Assert.Equal(_secretValue, config[_kv.Key]);

Expand All @@ -871,7 +871,7 @@ public void SecretIsReloadedFromKeyVaultWhenCacheExpires()
}

[Fact]
public void SecretsWithDefaultRefreshInterval()
public async Task SecretsWithDefaultRefreshInterval()
{
IConfigurationRefresher refresher = null;
TimeSpan shortCacheExpirationTime = TimeSpan.FromSeconds(1);
Expand Down Expand Up @@ -906,7 +906,7 @@ public void SecretsWithDefaultRefreshInterval()

// Sleep to let the secret cache expire for both secrets
Thread.Sleep(shortCacheExpirationTime);
refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

Assert.Equal(_secretValue, config["TK1"]);
Assert.Equal(_secretValue, config["TK2"]);
Expand All @@ -916,7 +916,7 @@ public void SecretsWithDefaultRefreshInterval()
}

[Fact]
public void SecretsWithDifferentRefreshIntervals()
public async Task SecretsWithDifferentRefreshIntervals()
{
IConfigurationRefresher refresher = null;
TimeSpan shortCacheExpirationTime = TimeSpan.FromSeconds(1);
Expand Down Expand Up @@ -953,7 +953,7 @@ public void SecretsWithDifferentRefreshIntervals()

// Sleep to let the secret cache expire for one secret
Thread.Sleep(shortCacheExpirationTime);
refresher.RefreshAsync().Wait();
await refresher.RefreshAsync();

Assert.Equal(_secretValue, config["TK1"]);
Assert.Equal(_secretValue, config["TK2"]);
Expand Down
Loading

0 comments on commit 03be006

Please sign in to comment.