From 0e21312b380ef3919849df5762c3f8b5d13c69d5 Mon Sep 17 00:00:00 2001 From: "David R. Williamson" Date: Thu, 6 Jan 2022 14:14:28 -0800 Subject: [PATCH] fix(iot-svc): update debug assert (#2264) * fix(iot-svc): update debug assert * Temporarily disable import devices/configs test (#2263) * fix(iot-svc): update debug assert * Reduce modules in ModulesClient_GetModulesOnDevice to 2 --- e2e/test/iothub/service/RegistryManagerE2ETests.cs | 7 +++++-- iothub/device/src/IotHubConnectionString.Core.cs | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/e2e/test/iothub/service/RegistryManagerE2ETests.cs b/e2e/test/iothub/service/RegistryManagerE2ETests.cs index 6a730651e5..e67c6ca723 100644 --- a/e2e/test/iothub/service/RegistryManagerE2ETests.cs +++ b/e2e/test/iothub/service/RegistryManagerE2ETests.cs @@ -417,7 +417,7 @@ public async Task RegistryManager_Query_Works() [LoggedTestMethod] public async Task ModulesClient_GetModulesOnDevice() { - int moduleCount = 5; + const int moduleCount = 2; string testDeviceId = $"IdentityLifecycleDevice{Guid.NewGuid()}"; string[] testModuleIds = new string[moduleCount]; for (int i = 0; i < moduleCount; i++) @@ -440,6 +440,9 @@ public async Task ModulesClient_GetModulesOnDevice() new Module(testDeviceId, testModuleIds[i])).ConfigureAwait(false); } + // Give the hub a moment + await Task.Delay(250).ConfigureAwait(false); + // List the modules on the test device IEnumerable modulesOnDevice = await client.GetModulesOnDeviceAsync(testDeviceId).ConfigureAwait(false); @@ -450,7 +453,7 @@ public async Task ModulesClient_GetModulesOnDevice() Assert.AreEqual(moduleCount, moduleIdsOnDevice.Count); for (int i = 0; i < moduleCount; i++) { - Assert.IsTrue(moduleIdsOnDevice.Contains(testModuleIds[i])); + moduleIdsOnDevice.Should().Contain(testModuleIds[i]); } } finally diff --git a/iothub/device/src/IotHubConnectionString.Core.cs b/iothub/device/src/IotHubConnectionString.Core.cs index 70edd63dd0..543ea47c5f 100644 --- a/iothub/device/src/IotHubConnectionString.Core.cs +++ b/iothub/device/src/IotHubConnectionString.Core.cs @@ -19,11 +19,14 @@ Task IAuthorizationProvider.GetPasswordAsync() if (Logging.IsEnabled) Logging.Enter(this, $"{nameof(IotHubConnectionString)}.{nameof(IAuthorizationProvider.GetPasswordAsync)}"); - Debug.Assert(TokenRefresher != null); + Debug.Assert( + !string.IsNullOrWhiteSpace(SharedAccessSignature) + || TokenRefresher != null, + "The token refresher and the shared access signature can't both be null"); return !string.IsNullOrWhiteSpace(SharedAccessSignature) ? Task.FromResult(SharedAccessSignature) - : TokenRefresher.GetTokenAsync(Audience); + : TokenRefresher?.GetTokenAsync(Audience); } finally {