From 2adc6b84181150496a2b8a94968fdba28d90c25e Mon Sep 17 00:00:00 2001 From: Dmitry Hohlin Date: Sat, 24 Mar 2018 06:59:13 +0300 Subject: [PATCH 1/2] Fixed test Broker_Send_Many --- PushSharp.Tests/BrokerTests.cs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/PushSharp.Tests/BrokerTests.cs b/PushSharp.Tests/BrokerTests.cs index 92308707..8074e785 100644 --- a/PushSharp.Tests/BrokerTests.cs +++ b/PushSharp.Tests/BrokerTests.cs @@ -22,13 +22,21 @@ public void Broker_Send_Many () var succeeded = 0; var failed = 0; var attempted = 0; - + var locker = new object(); + var broker = new TestServiceBroker (); broker.OnNotificationFailed += (notification, exception) => { - failed++; + lock (locker) + { + failed++; + } }; - broker.OnNotificationSucceeded += (notification) => { - succeeded++; + broker.OnNotificationSucceeded += (notification) => + { + lock (locker) + { + succeeded++; + } }; broker.Start (); broker.ChangeScale (1); @@ -38,10 +46,10 @@ public void Broker_Send_Many () for (int i = 1; i <= 1000; i++) { attempted++; broker.QueueNotification (new TestNotification { TestId = i }); - } - + } + broker.Stop (); - + c.StopAndLog ("Test Took {0} ms"); Assert.AreEqual (attempted, succeeded); From 5a4dd8ec1c6629c810fe845498a97c12d69682b9 Mon Sep 17 00:00:00 2001 From: Dmitry Hohlin Date: Sat, 24 Mar 2018 07:01:23 +0300 Subject: [PATCH 2/2] ServiceWorker release references to completed tasks. Fixes #854 --- PushSharp.Core/ServiceBroker.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PushSharp.Core/ServiceBroker.cs b/PushSharp.Core/ServiceBroker.cs index 4b87f7b1..c5c681d1 100644 --- a/PushSharp.Core/ServiceBroker.cs +++ b/PushSharp.Core/ServiceBroker.cs @@ -179,6 +179,9 @@ public void Start () // Let's wait for the continuation not the task itself toSend.Add (cont); + + // release references to completed tasks + toSend.RemoveAll(task => task.IsCompleted); } if (toSend.Count <= 0)