-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathXmppQoSMessagingTests.cs
More file actions
82 lines (67 loc) · 2.14 KB
/
XmppQoSMessagingTests.cs
File metadata and controls
82 lines (67 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Waher.Networking.XMPP.Events;
namespace Waher.Networking.XMPP.Test
{
[TestClass]
public class XmppQoSMessagingTests : CommunicationTests
{
[ClassInitialize]
public static void ClassInitialize(TestContext _)
{
SetupSnifferAndLog();
}
[ClassCleanup]
public static async Task ClassCleanup()
{
await DisposeSnifferAndLog();
}
[TestMethod]
public async Task QoS_Test_01_Unacknowledged_Service()
{
await this.QoSTest(QoSLevel.Unacknowledged);
}
[TestMethod]
public async Task QoS_Test_02_Acknowledged_Service()
{
await this.QoSTest(QoSLevel.Acknowledged);
}
[TestMethod]
public async Task QoS_Test_03_Assured_Service()
{
await this.QoSTest(QoSLevel.Assured);
}
private async Task QoSTest(QoSLevel Level)
{
await this.ConnectClients();
ManualResetEvent Received = new(false);
ManualResetEvent Delivered = new(false);
this.client2.OnNormalMessage += (Sender, e) => { Received.Set(); return Task.CompletedTask; };
await this.client1.SendMessage(Level, MessageType.Normal, this.client2.FullJID, string.Empty, "Hello", string.Empty, "en",
string.Empty, string.Empty, (Sender, e) => { Delivered.Set(); return Task.CompletedTask; }, null);
Assert.IsTrue(Delivered.WaitOne(10000), "Message not delivered properly.");
Assert.IsTrue(Received.WaitOne(10000), "Message not received properly.");
}
[TestMethod]
public async Task QoS_Test_04_Timeout()
{
ManualResetEvent Done = new(false);
IqResultEventArgs e2 = null;
await this.ConnectClients();
this.client2.RegisterIqGetHandler("test", "test", (Sender, e) =>
{
// Do nothing. Do not return result or error.
return Task.CompletedTask;
}, false);
await this.client1.SendIqGet(this.client2.FullJID, "<test:test xmlns:test='test'/>", (Sender, e) =>
{
e2 = e;
Done.Set();
return Task.CompletedTask;
}, null, 1000, 3, true, int.MaxValue);
Assert.IsTrue(Done.WaitOne(20000), "Retry function not working properly.");
Assert.IsFalse(e2.Ok, "Request not properly cancelled.");
}
}
}