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 {