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

[fix] TestDispose refactoring #200

Merged
merged 2 commits into from
Oct 17, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci_standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ jobs:

- name: Test OpenDDSharp
shell: bash
run: dotnet test ${{ github.workspace }}/Tests/OpenDDSharp.UnitTest/OpenDDSharp.UnitTest.csproj --blame-crash --no-build --no-restore --verbosity detailed --configuration ${{ env.BuildConfiguration }} --runtime linux-x64 --collect "XPlat code coverage" --logger "trx;LogFileName=test-results.trx" --logger "console;verbosity=detailed""console;verbosity=detailed" --settings ${{ github.workspace }}/Tests.runsettings --test-adapter-path "${{ github.workspace }}/packages/coverlet.collector/6.0.0/build/netstandard1.0/"
run: dotnet test ${{ github.workspace }}/Tests/OpenDDSharp.UnitTest/OpenDDSharp.UnitTest.csproj --no-build --no-restore --verbosity detailed --configuration ${{ env.BuildConfiguration }} --runtime linux-x64 --collect "XPlat code coverage" --logger "trx;LogFileName=test-results.trx" --logger "console;verbosity=detailed""console;verbosity=detailed" --settings ${{ github.workspace }}/Tests.runsettings --test-adapter-path "${{ github.workspace }}/packages/coverlet.collector/6.0.0/build/netstandard1.0/"
working-directory: ${{ github.workspace }}
env:
DDS_ROOT: "${{ github.workspace }}/ext/OpenDDS_Linux"
Expand Down
72 changes: 42 additions & 30 deletions Tests/OpenDDSharp.UnitTest/DataWriterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,44 +1071,65 @@ public void TestDispose()

var drQos = new DataReaderQos();
qos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;
var listener = new MyDataReaderListener();
var dataReader = subscriber.CreateDataReader(_topic, drQos, listener);
var dataReader = subscriber.CreateDataReader(_topic, drQos);
Assert.IsNotNull(dataReader);
var statusCondition = dataReader.StatusCondition;
statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus;

var dr = new TestStructDataReader(dataReader);

var evtDisposed = new ManualResetEventSlim(false);
var evtAlive = new ManualResetEventSlim(false);

var countDisposed = 0;
Timestamp timestamp = default;
listener.DataAvailable += (reader) =>
var waitSet = new WaitSet();
waitSet.AttachCondition(statusCondition);
var thread = new Thread(() =>
{
var samples = new List<TestStruct>();
var infos = new List<SampleInfo>();
var dr = new TestStructDataReader(reader);
var ret = dr.Take(samples, infos);
if (ret != ReturnCode.Ok || !infos.Any())
var isSet = false;
while (!isSet)
{
return;
}
ICollection<Condition> conditions = new List<Condition>();
waitSet.Wait(conditions);

foreach (var info in infos)
{
if (info.InstanceState == InstanceStateKind.NotAliveDisposedInstanceState)
if (!conditions.Any(cond => cond == statusCondition && cond.TriggerValue))
{
countDisposed++;
if (countDisposed == 3)
{
timestamp = info.SourceTimestamp;
}
continue;
}

evtDisposed.Set();
var samples = new List<TestStruct>();
var infos = new List<SampleInfo>();
var ret = dr.Take(samples, infos);
if (ret != ReturnCode.Ok || !infos.Any())
{
continue;
}
else if (info.InstanceState == InstanceStateKind.AliveInstanceState)

foreach (var info in infos)
{
evtAlive.Set();
if (info.InstanceState == InstanceStateKind.NotAliveDisposedInstanceState)
{
countDisposed++;
if (countDisposed == 3)
{
timestamp = info.SourceTimestamp;
isSet = true;
}

evtDisposed.Set();
}
else if (info.InstanceState == InstanceStateKind.AliveInstanceState)
{
evtAlive.Set();
}
}
}
})
{
IsBackground = true,
};
thread.Start();

// Wait for discovery
Assert.IsTrue(writer.WaitForSubscriptions(1, 10_000));
Expand Down Expand Up @@ -1199,15 +1220,6 @@ public void TestDispose()
evtDisposed.Dispose();
evtAlive.Dispose();

// Clean up entities
foreach (var d in listener.DataAvailable.GetInvocationList())
{
var del = (Action<DataReader>)d;
listener.DataAvailable -= del;
}
Assert.AreEqual(ReturnCode.Ok, dataReader.SetListener(null, StatusMask.AllStatusMask));
listener.Dispose();

Assert.AreEqual(ReturnCode.Ok, dataReader.DeleteContainedEntities());
Assert.AreEqual(ReturnCode.Ok, subscriber.DeleteDataReader(dataReader));
Assert.AreEqual(ReturnCode.Ok, subscriber.DeleteContainedEntities());
Expand Down
Loading