Skip to content

Commit

Permalink
Don't recycle Duration object
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmorato committed Dec 18, 2024
1 parent 5c91b11 commit dd27cf3
Showing 1 changed file with 40 additions and 48 deletions.
88 changes: 40 additions & 48 deletions Tests/OpenDDSharp.UnitTest/DataReaderCDRTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,6 @@ public void TestRead()
using var evt = new ManualResetEventSlim(false);

// Initialize entities
var duration = new Duration { Seconds = 5 };
var drQos = new DataReaderQos
{
Reliability =
Expand Down Expand Up @@ -1266,7 +1265,7 @@ public void TestRead()
var result = dataWriter.Write(new TestInclude { Id = "1" });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand All @@ -1288,7 +1287,7 @@ public void TestRead()
result = dataWriter.Write(new TestInclude { Id = "1", ShortField = 2, IncludeField = new IncludeStruct { Message = "Test"} });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand Down Expand Up @@ -1355,7 +1354,6 @@ public void TestTake()
using var evt = new ManualResetEventSlim(false);

// Initialize entities
var duration = new Duration { Seconds = 5 };
var drQos = new DataReaderQos
{
Reliability =
Expand Down Expand Up @@ -1396,7 +1394,7 @@ public void TestTake()
var result = dataWriter.Write(new TestInclude { Id = "1" });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);
Assert.IsTrue(evt.Wait(1_500));

Expand Down Expand Up @@ -1428,7 +1426,7 @@ public void TestTake()
result = dataWriter.Write(new TestInclude { Id = "2", ShortField = i });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand Down Expand Up @@ -1465,7 +1463,7 @@ public void TestTake()
result = dataWriter.Write(new TestInclude { Id = "3", ShortField = i });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand Down Expand Up @@ -1514,7 +1512,6 @@ public void TestReadInstance()

// Initialize entities
ReturnCode result;
var duration = new Duration { Seconds = 5 };
var drQos = new DataReaderQos
{
Reliability =
Expand Down Expand Up @@ -1559,7 +1556,7 @@ public void TestReadInstance()
result = dataWriter.Write(new TestInclude { Id = i.ToString() });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand All @@ -1570,7 +1567,7 @@ public void TestReadInstance()
result = dataWriter.Write(new TestInclude { Id = i.ToString(), ShortField = i });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand Down Expand Up @@ -1663,7 +1660,6 @@ public void TestTakeInstance()

// Initialize entities
ReturnCode result;
var duration = new Duration { Seconds = 5 };
var drQos = new DataReaderQos
{
Reliability =
Expand Down Expand Up @@ -1708,7 +1704,7 @@ public void TestTakeInstance()
result = dataWriter.Write(new TestInclude { Id = i.ToString() });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand All @@ -1719,7 +1715,7 @@ public void TestTakeInstance()
result = dataWriter.Write(new TestInclude { Id = i.ToString(), ShortField = i });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand Down Expand Up @@ -1818,7 +1814,6 @@ public void TestReadNextInstance()

// Initialize entities
ReturnCode result;
var duration = new Duration { Seconds = 5 };
var drQos = new DataReaderQos
{
Reliability =
Expand Down Expand Up @@ -1858,31 +1853,31 @@ public void TestReadNextInstance()
found = writer.WaitForSubscriptions(1, 5_000);
Assert.IsTrue(found);

// // Write two samples of three different instances
// for (short i = 1; i <= 3; i++)
// {
// evt.Reset();
// TestHelper.CreateWaitSetThread(evt, statusCondition);
//
// result = dataWriter.Write(new TestInclude { Id = i.ToString() });
// Assert.AreEqual(ReturnCode.Ok, result);
//
// result = dataWriter.WaitForAcknowledgments(duration);
// Assert.AreEqual(ReturnCode.Ok, result);
//
// Assert.IsTrue(evt.Wait(1_500));
//
// evt.Reset();
// TestHelper.CreateWaitSetThread(evt, statusCondition);
//
// result = dataWriter.Write(new TestInclude { Id = i.ToString(), ShortField = i });
// Assert.AreEqual(ReturnCode.Ok, result);
//
// result = dataWriter.WaitForAcknowledgments(duration);
// Assert.AreEqual(ReturnCode.Ok, result);
//
// Assert.IsTrue(evt.Wait(1_500));
// }
// Write two samples of three different instances
for (short i = 1; i <= 3; i++)
{
evt.Reset();
TestHelper.CreateWaitSetThread(evt, statusCondition);

result = dataWriter.Write(new TestInclude { Id = i.ToString() });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));

evt.Reset();
TestHelper.CreateWaitSetThread(evt, statusCondition);

result = dataWriter.Write(new TestInclude { Id = i.ToString(), ShortField = i });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
}

// Read next instance with the simplest overload
var data = new List<TestInclude>();
Expand Down Expand Up @@ -1950,7 +1945,6 @@ public void TestTakeNextInstance()

// Initialize entities
ReturnCode result;
var duration = new Duration { Seconds = 5 };
var drQos = new DataReaderQos
{
Reliability =
Expand Down Expand Up @@ -1995,7 +1989,7 @@ public void TestTakeNextInstance()
result = dataWriter.Write(new TestInclude { Id = i.ToString() });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand All @@ -2006,7 +2000,7 @@ public void TestTakeNextInstance()
result = dataWriter.Write(new TestInclude { Id = i.ToString(), ShortField = i });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand Down Expand Up @@ -2078,7 +2072,6 @@ public void TestReadNextSample()

// Initialize entities
ReturnCode result;
var duration = new Duration { Seconds = 5 };
var drQos = new DataReaderQos
{
Reliability =
Expand Down Expand Up @@ -2123,7 +2116,7 @@ public void TestReadNextSample()
result = dataWriter.Write(new TestInclude { Id = i.ToString() });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand All @@ -2134,7 +2127,7 @@ public void TestReadNextSample()
result = dataWriter.Write(new TestInclude { Id = i.ToString(), ShortField = i });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand Down Expand Up @@ -2191,7 +2184,6 @@ public void TestTakeNextSample()

// Initialize entities
ReturnCode result;
var duration = new Duration { Seconds = 5 };
var drQos = new DataReaderQos
{
Reliability =
Expand Down Expand Up @@ -2236,7 +2228,7 @@ public void TestTakeNextSample()
result = dataWriter.Write(new TestInclude { Id = i.ToString() });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand All @@ -2247,7 +2239,7 @@ public void TestTakeNextSample()
result = dataWriter.Write(new TestInclude { Id = i.ToString(), ShortField = i });
Assert.AreEqual(ReturnCode.Ok, result);

result = dataWriter.WaitForAcknowledgments(duration);
result = dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 });
Assert.AreEqual(ReturnCode.Ok, result);

Assert.IsTrue(evt.Wait(1_500));
Expand Down

0 comments on commit dd27cf3

Please sign in to comment.