diff --git a/e2e/test/iothub/service/RegistryManagerE2ETests.cs b/e2e/test/iothub/service/RegistryManagerE2ETests.cs index e9533c2526..e67c6ca723 100644 --- a/e2e/test/iothub/service/RegistryManagerE2ETests.cs +++ b/e2e/test/iothub/service/RegistryManagerE2ETests.cs @@ -392,50 +392,32 @@ public async Task RegistryManager_ConfigurationOperations_Work() public async Task RegistryManager_Query_Works() { // arrange - using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString); - string deviceId = $"{_idPrefix}{Guid.NewGuid()}"; - - try - { - Device device = await registryManager - .AddDeviceAsync(new Device(deviceId)) - .ConfigureAwait(false); - // act + using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString); + string deviceId = TestConfiguration.IoTHub.X509ChainDeviceName; - IQuery query = null; - IEnumerable twins = null; - for (int i = 0; i < 30; ++i) - { - string queryText = $"select * from devices where deviceId = '{deviceId}'"; - query = registryManager.CreateQuery(queryText); + Device device = await registryManager + .GetDeviceAsync(deviceId) + .ConfigureAwait(false); + device.Should().NotBeNull($"Device {deviceId} should already exist in hub setup for E2E tests"); - twins = await query.GetNextAsTwinAsync().ConfigureAwait(false); + // act - if (twins.Any()) - { - break; - } + string queryText = $"select * from devices where deviceId = '{deviceId}'"; + IQuery query = registryManager.CreateQuery(queryText); + IEnumerable twins = await query.GetNextAsTwinAsync().ConfigureAwait(false); - // A new device may not return immediately from a query, so give it some time and some retries to appear - await Task.Delay(250).ConfigureAwait(false); - } + // assert - // assert - twins.Count().Should().Be(1, "only asked for 1 device by its Id"); - twins.First().DeviceId.Should().Be(deviceId, "The Id of the device returned should match"); - query.HasMoreResults.Should().BeFalse("We've processed the single, expected result"); - } - finally - { - await registryManager.RemoveDeviceAsync(deviceId).ConfigureAwait(false); - } + twins.Count().Should().Be(1, "only asked for 1 device by its Id"); + twins.First().DeviceId.Should().Be(deviceId, "The Id of the device returned should match"); + query.HasMoreResults.Should().BeFalse("We've processed the single, expected result"); } [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++) @@ -458,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); @@ -468,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/e2e/test/iothub/service/RegistryManagerImportDevicesTests.cs b/e2e/test/iothub/service/RegistryManagerImportDevicesTests.cs index 2ccc77d349..4a7f0ba1e6 100644 --- a/e2e/test/iothub/service/RegistryManagerImportDevicesTests.cs +++ b/e2e/test/iothub/service/RegistryManagerImportDevicesTests.cs @@ -43,6 +43,7 @@ public class RegistryManagerImportDevicesTests : E2EMsTestBase [DataRow(StorageAuthenticationType.KeyBased, false)] [DataRow(StorageAuthenticationType.IdentityBased, false)] [DataRow(StorageAuthenticationType.IdentityBased, true)] + [Ignore("Waiting on IcM 279379774 to be resolved, estimated early Jan 2022")] public async Task RegistryManager_ImportDevices(StorageAuthenticationType storageAuthenticationType, bool isUserAssignedMsi) { // arrange 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 {