Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/Microsoft.Azure.Devices.Edge.Test.Common/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Microsoft.Azure.Devices.Edge.Test.Common
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Edge.Test.Common;
using Microsoft.Azure.Devices.Edge.Util;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -138,6 +140,8 @@ IEnumerable<Registry> GetAndValidateRegistries()

public Dictionary<string, EdgeDevice> DeleteList { get; } = new Dictionary<string, EdgeDevice>();

public Dictionary<string, LeafDevice> LeafDeleteList { get; } = new Dictionary<string, LeafDevice>();

public Option<string> DpsIdScope { get; }

public Option<string> DpsGroupKey { get; }
Expand Down
133 changes: 49 additions & 84 deletions test/Microsoft.Azure.Devices.Edge.Test/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,12 @@ public async Task QuickstartCerts()
Option.None<string>(),
this.device.NestedEdge.IsNestedEdge);

await TryFinally.DoAsync(
async () =>
{
DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await leaf.InvokeDirectMethodAsync(token);
},
async () =>
{
await leaf.DeleteIdentityAsync(token);
});
Context.Current.LeafDeleteList.TryAdd(leafDeviceId, leaf);

DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await leaf.InvokeDirectMethodAsync(token);
}

[Test]
Expand Down Expand Up @@ -79,19 +73,12 @@ public async Task QuickstartChangeSasKey()
Option.None<string>(),
this.device.NestedEdge.IsNestedEdge);

await TryFinally.DoAsync(
async () =>
{
DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await leaf.InvokeDirectMethodAsync(token);
},
async () =>
{
await leaf.Close();
await leaf.DeleteIdentityAsync(token);
});
Context.Current.LeafDeleteList.TryAdd(leafDeviceId, leaf);

DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await leaf.InvokeDirectMethodAsync(token);

// Re-create the leaf with the same device ID, for our purposes this is
// the equivalent of updating the SAS keys
Expand All @@ -109,19 +96,10 @@ await TryFinally.DoAsync(
Option.None<string>(),
this.device.NestedEdge.IsNestedEdge);

await TryFinally.DoAsync(
async () =>
{
DateTime seekTime = DateTime.Now;
await leafUpdated.SendEventAsync(token);
await leafUpdated.WaitForEventsReceivedAsync(seekTime, token);
await leafUpdated.InvokeDirectMethodAsync(token);
},
async () =>
{
await leafUpdated.Close();
await leafUpdated.DeleteIdentityAsync(token);
});
seekTime = DateTime.Now;
await leafUpdated.SendEventAsync(token);
await leafUpdated.WaitForEventsReceivedAsync(seekTime, token);
await leafUpdated.InvokeDirectMethodAsync(token);
}

[Test]
Expand Down Expand Up @@ -155,40 +133,33 @@ public async Task RouteMessageL3LeafToL4Module()
Option.None<string>(),
Context.Current.NestedEdge);

await TryFinally.DoAsync(
async () =>
{
// Send a message from the leaf device
DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
Log.Verbose($"Sent message from {leafDeviceId}");

// Verify that the message was received/resent by the relayer module on L4
await Profiler.Run(
() => this.IotHub.ReceiveEventsAsync(
parentDeviceId,
seekTime,
data =>
{
data.SystemProperties.TryGetValue("iothub-connection-device-id", out object devId);
data.SystemProperties.TryGetValue("iothub-connection-module-id", out object modId);
data.Properties.TryGetValue("leaf-message-id", out object msgId);

Log.Verbose($"Received event for '{devId + "/" + modId}' with message ID '{msgId}'");

return devId != null && devId.ToString().Equals(parentDeviceId)
&& modId.ToString().Equals(relayerModuleId);
},
token),
"Received events from module '{Device}' on Event Hub '{EventHub}'",
parentDeviceId + "/" + relayerModuleId,
this.IotHub.EventHubName);
},
async () =>
{
await leaf.Close();
await leaf.DeleteIdentityAsync(token);
});
Context.Current.LeafDeleteList.TryAdd(leafDeviceId, leaf);

// Send a message from the leaf device
DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
Log.Verbose($"Sent message from {leafDeviceId}");

// Verify that the message was received/resent by the relayer module on L4
await Profiler.Run(
() => this.IotHub.ReceiveEventsAsync(
parentDeviceId,
seekTime,
data =>
{
data.SystemProperties.TryGetValue("iothub-connection-device-id", out object devId);
data.SystemProperties.TryGetValue("iothub-connection-module-id", out object modId);
data.Properties.TryGetValue("leaf-message-id", out object msgId);

Log.Verbose($"Received event for '{devId + "/" + modId}' with message ID '{msgId}'");

return devId != null && devId.ToString().Equals(parentDeviceId)
&& modId.ToString().Equals(relayerModuleId);
},
token),
"Received events from module '{Device}' on Event Hub '{EventHub}'",
parentDeviceId + "/" + relayerModuleId,
this.IotHub.EventHubName);
}

[Test]
Expand Down Expand Up @@ -226,18 +197,12 @@ public async Task DisableReenableParentEdge()
Option.None<string>(),
this.device.NestedEdge.IsNestedEdge);

await TryFinally.DoAsync(
async () =>
{
DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await leaf.InvokeDirectMethodAsync(token);
},
async () =>
{
await leaf.DeleteIdentityAsync(token);
});
Context.Current.LeafDeleteList.TryAdd(leafDeviceId, leaf);

DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await leaf.InvokeDirectMethodAsync(token);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public async Task TransparentGateway(
token,
Option.None<string>(),
this.device.NestedEdge.IsNestedEdge);

Context.Current.LeafDeleteList.TryAdd(leafDeviceId, leaf);
}
catch (Exception) when (!parentId.HasValue)
{
Expand All @@ -58,18 +60,10 @@ public async Task TransparentGateway(

Assert.NotNull(leaf);

await TryFinally.DoAsync(
async () =>
{
DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await leaf.InvokeDirectMethodAsync(token);
},
async () =>
{
await leaf.DeleteIdentityAsync(token);
});
DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await leaf.InvokeDirectMethodAsync(token);
}

[Test]
Expand Down Expand Up @@ -112,6 +106,8 @@ public async Task GrandparentScopeDevice(
token,
Option.None<string>(),
this.device.NestedEdge.IsNestedEdge);

Context.Current.LeafDeleteList.TryAdd(leafDeviceId, leaf);
}
catch (Exception) when (!parentId.HasValue)
{
Expand All @@ -125,19 +121,10 @@ public async Task GrandparentScopeDevice(

Assert.NotNull(leaf);

await TryFinally.DoAsync(
async () =>
{
DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await leaf.InvokeDirectMethodAsync(token);
},
async () =>
{
await leaf.DeleteIdentityAsync(token);
await Task.CompletedTask;
});
DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await leaf.InvokeDirectMethodAsync(token);
}
}
}
18 changes: 6 additions & 12 deletions test/Microsoft.Azure.Devices.Edge.Test/PlugAndPlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,12 @@ public async Task PlugAndPlayDeviceClient(Protocol protocol)
Option.Some(TestModelId),
Context.Current.NestedEdge);

await TryFinally.DoAsync(
async () =>
{
DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await this.ValidateIdentity(leafDeviceId, Option.None<string>(), TestModelId, token);
},
async () =>
{
await leaf.DeleteIdentityAsync(token);
});
Context.Current.LeafDeleteList.TryAdd(leafDeviceId, leaf);

DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await this.ValidateIdentity(leafDeviceId, Option.None<string>(), TestModelId, token);
}

[TestCase(Protocol.Mqtt)]
Expand Down
5 changes: 5 additions & 0 deletions test/Microsoft.Azure.Devices.Edge.Test/SetupFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public Task AfterAllAsync() => TryFinally.DoAsync(
await device.MaybeDeleteIdentityAsync(token);
}

foreach (var leaf in Context.Current.LeafDeleteList.Values)
{
await leaf.DeleteIdentityAsync(token);
}

// Remove packages installed by this run.
await this.daemon.UninstallAsync(token);

Expand Down
18 changes: 6 additions & 12 deletions test/Microsoft.Azure.Devices.Edge.Test/X509Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,12 @@ public async Task X509ManualProvision()
Option.None<string>(),
Context.Current.NestedEdge);

await TryFinally.DoAsync(
async () =>
{
DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await leaf.InvokeDirectMethodAsync(token);
},
async () =>
{
await leaf.DeleteIdentityAsync(token);
});
Context.Current.LeafDeleteList.TryAdd(leafDeviceId, leaf);

DateTime seekTime = DateTime.Now;
await leaf.SendEventAsync(token);
await leaf.WaitForEventsReceivedAsync(seekTime, token);
await leaf.InvokeDirectMethodAsync(token);
}
}
}