Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel twin ops on disconnect #3287

Merged
merged 29 commits into from
Apr 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5ebb0fe
Cancel pending twin operations on disconnect
Apr 19, 2023
d831d48
Add/update logging
Apr 19, 2023
9ea0ec6
Reduce concurrent dictionaries to one per protocol
Apr 19, 2023
8fce7e6
Fix twin patch response
Apr 19, 2023
19a8e0a
Unify twin update and logging in long haul
Apr 19, 2023
9dd4909
Improve error handling in long haul
Apr 19, 2023
2eee027
Fix old task cleanup
Apr 20, 2023
9b86af4
Add retry to long haul init
Apr 20, 2023
a6d0f39
merge
Apr 20, 2023
0a6014b
Rearrange methods
Apr 20, 2023
287a8fa
Fix method name
Apr 20, 2023
1593b03
PR feedback from Bryce
Apr 20, 2023
eb8b7b3
Cancel pending twin operations on disconnect
Apr 19, 2023
99b9b7d
Add/update logging
Apr 19, 2023
586e53d
Reduce concurrent dictionaries to one per protocol
Apr 19, 2023
b8d858f
Fix twin patch response
Apr 19, 2023
4f68177
Unify twin update and logging in long haul
Apr 19, 2023
348e82b
Improve error handling in long haul
Apr 19, 2023
ed93221
Fix old task cleanup
Apr 20, 2023
3b2654e
Add retry to long haul init
Apr 20, 2023
c74dc83
merge
Apr 20, 2023
365968c
Rearrange methods
Apr 20, 2023
0eabbb1
Fix method name
Apr 20, 2023
fcd79d3
PR feedback from Bryce
Apr 20, 2023
af27f20
PR feedback
Apr 20, 2023
0fb999d
adding cancellation toke for InitializeAsync in module client
tmahmood-microsoft Apr 20, 2023
d418081
Merge branch 'drwill/cancel-twinops-on-disconnect' of https://github.…
tmahmood-microsoft Apr 20, 2023
f45d3fc
Fix MQTT twin response
Apr 20, 2023
04fa965
Add unit tests for payload conventions
Apr 20, 2023
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
Prev Previous commit
Add unit tests for payload conventions
David R. Williamson committed Apr 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 04fa96586b88ec26b8ae6bdd829c0dbf797b5676
5 changes: 5 additions & 0 deletions e2e/LongHaul/device/SystemHealthTelemetry.cs
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
using System.Linq;
using System.Net.NetworkInformation;
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace Microsoft.Azure.Devices.LongHaul.Device
{
@@ -23,15 +24,19 @@ public SystemHealthTelemetry(int port)
TcpPortFilter.Add(port);
}

[JsonProperty("processCpuUsagePercent")]
[JsonPropertyName("processCpuUsagePercent")]
public double ProcessCpuUsagePercent { get; set; } = UpdateCpuUsage();

[JsonProperty("totalAssignedMemoryBytes")]
[JsonPropertyName("totalAssignedMemoryBytes")]
public long TotalAssignedMemoryBytes { get; set; } = s_currentProcess.WorkingSet64;

[JsonProperty("totalGCBytes")]
[JsonPropertyName("totalGCBytes")]
public long TotalGCBytes { get; set; } = GC.GetTotalMemory(false);

[JsonProperty("activeTcpConnections")]
[JsonPropertyName("activeTcpConnections")]
public long ActiveTcpConnections { get; set; } = UpdateTcpConnections();

4 changes: 4 additions & 0 deletions e2e/LongHaul/device/SystemProperties.cs
Original file line number Diff line number Diff line change
@@ -3,17 +3,21 @@

using System.Runtime.InteropServices;
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace Microsoft.Azure.Devices.LongHaul.Device
{
internal class SystemProperties
{
[JsonProperty("systemArchitecture")]
[JsonPropertyName("systemArchitecture")]
public string SystemArchitecture { get; set; } = RuntimeInformation.OSArchitecture.ToString();

[JsonProperty("osVersion")]
[JsonPropertyName("osVersion")]
public string OsVersion { get; set; } = RuntimeInformation.OSDescription;

[JsonProperty("frameworkDescription")]
[JsonPropertyName("frameworkDescription")]
public string FrameworkDescription { get; set; } = RuntimeInformation.FrameworkDescription;

2 changes: 2 additions & 0 deletions e2e/LongHaul/device/TelemetryBase.cs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

using System;
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace Microsoft.Azure.Devices.LongHaul.Device
{
@@ -11,6 +12,7 @@ internal abstract class TelemetryBase
/// <summary>
/// The date/time the event occurred, in UTC.
/// </summary>
[JsonProperty("eventDateTimeUtc")]
[JsonPropertyName("eventDateTimeUtc")]
public DateTime? EventDateTimeUtc { get; set; } = DateTime.UtcNow;
}
89 changes: 88 additions & 1 deletion iothub/device/tests/DefaultPayloadConventionTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
@@ -15,6 +16,7 @@ namespace Microsoft.Azure.Devices.Client.Tests
[TestCategory("Unit")]
public class DefaultPayloadConventionTests
{
private static readonly DefaultPayloadConvention s_cut = DefaultPayloadConvention.Instance;
private static readonly string s_dateTimeString = "2023-01-31T10:37:08.4599400";
private static readonly string s_serializedPayloadString = "{\"time\":\"2023-01-31T10:37:08.4599400\"}";

@@ -38,12 +40,97 @@ public void DefaultPayloadConvention_DateTime_DeserializesProperly()
string jsonStr = $@"{{""time"":""{s_dateTimeString}""}}";

// act
JObject payload = DefaultPayloadConvention.Instance.GetObject<JObject>(jsonStr);
JObject payload = s_cut.GetObject<JObject>(jsonStr);

//assert
payload.ToString(Formatting.None).Should().Be(s_serializedPayloadString);
}

[TestMethod]
public void DefaultPayloadConvention_RoundtripsInt()
{
// arrange
const int expected = 1;

// act
s_cut.GetObject<int>(s_cut.GetObjectBytes(expected))
.Should()
.Be(expected);
}

[TestMethod]
public void DefaultPayloadConvention_RoundtripsBool()
{
// arrange
bool expected = true;

// act
s_cut.GetObject<bool>(s_cut.GetObjectBytes(expected))
.Should()
.Be(expected);
}

[TestMethod]
public void DefaultPayloadConvention_RoundtripsDateTimeOffset()
{
// arrange
DateTimeOffset expected = DateTimeOffset.UtcNow;

// act
s_cut.GetObject<DateTimeOffset>(s_cut.GetObjectBytes(expected))
.Should()
.Be(expected);
}

[TestMethod]
public void DefaultPayloadConvention_RoundtripsDateTime()
{
// arrange
DateTime expected = DateTime.UtcNow;

// act
s_cut.GetObject<DateTime>(s_cut.GetObjectBytes(expected))
.Should()
.Be(expected);
}

[TestMethod]
public void DefaultPayloadConvention_RoundtripsString()
{
// arrange
const string expected = nameof(DefaultPayloadConvention_RoundtripsString);

// act
s_cut.GetObject<string>(s_cut.GetObjectBytes(expected))
.Should()
.Be(expected);
}

[TestMethod]
public void DefaultPayloadConvention_RoundtripsCustomType()
{
// arrange
var expected = new CustomType
{
IntProp = 1,
StringProp = Guid.NewGuid().ToString(),
};

// act
s_cut.GetObject<CustomType>(s_cut.GetObjectBytes(expected))
.Should()
.BeEquivalentTo(expected);
}

private class CustomType
{
[JsonProperty("intProp")]
public int IntProp { get; set; }

[JsonProperty("stringProp")]
public string StringProp { get; set; }
}

private class TestDateTime
{
[JsonProperty("time")]
102 changes: 102 additions & 0 deletions iothub/device/tests/SystemTextJsonPayloadConventionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Text.Json.Serialization;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.Azure.Devices.Client.Tests
{
[TestClass]
[TestCategory("Unit")]
public class SystemTextJsonPayloadConventionTests
{
private static readonly SystemTextJsonPayloadConvention s_cut = SystemTextJsonPayloadConvention.Instance;

[TestMethod]
public void SystemTextJsonPayloadConvention_RoundtripsInt()
{
// arrange
const int expected = 1;

// act
s_cut.GetObject<int>(s_cut.GetObjectBytes(expected))
.Should()
.Be(expected);
}

[TestMethod]
public void SystemTextJsonPayloadConvention_RoundtripsBool()
{
// arrange
bool expected = true;

// act
s_cut.GetObject<bool>(s_cut.GetObjectBytes(expected))
.Should()
.Be(expected);
}

[TestMethod]
public void SystemTextJsonPayloadConvention_RoundtripsDateTimeOffset()
{
// arrange
DateTimeOffset expected = DateTimeOffset.UtcNow;

// act
s_cut.GetObject<DateTimeOffset>(s_cut.GetObjectBytes(expected))
.Should()
.Be(expected);
}

[TestMethod]
public void SystemTextJsonPayloadConvention_RoundtripsDateTime()
{
// arrange
DateTime expected = DateTime.UtcNow;

// act
s_cut.GetObject<DateTime>(s_cut.GetObjectBytes(expected))
.Should()
.Be(expected);
}

[TestMethod]
public void SystemTextJsonPayloadConvention_RoundtripsString()
{
// arrange
const string expected = nameof(SystemTextJsonPayloadConvention_RoundtripsString);

// act
s_cut.GetObject<string>(s_cut.GetObjectBytes(expected))
.Should()
.Be(expected);
}

[TestMethod]
public void SystemTextJsonPayloadConvention_RoundtripsCustomType()
{
// arrange
var expected = new CustomType
{
IntProp = 1,
StringProp = Guid.NewGuid().ToString(),
};

// act
s_cut.GetObject<CustomType>(s_cut.GetObjectBytes(expected))
.Should()
.BeEquivalentTo(expected);
}

private class CustomType
{
[JsonPropertyName("intProp")]
public int IntProp { get; set; }

[JsonPropertyName("stringProp")]
public string StringProp{ get; set; }
}
}
}