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

Race condition with data items' initialization caused sporadic test failures #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions tests/IntegrationTests/ClientAgentCommunicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,22 @@ public ClientAgentCommunicationTests(
{
var adapterClient = new ShdrAdapterClient(adapterConfiguration, _agent, device);

// Adapter client initialized all its data items, setting them to UNAVAILABLE
// Lest creating race condition we should wait until all items are initialized in OnConnect (see ShdrClient.ListenForAdapter)
// The essence of race condition was that a data item might be sent via adapter EARLIER than adapter client initialized the same data item to UNAVAILABLE.
// As a result MTConnectAgent.FilterPeriod was discarding new value coming via adapter due to older timestamp assigned on sending.
// I have chosen ShdrClient.PingSent event, since ShdrClient.Listening was not called.
var waiter = new AutoResetEvent(false);
void DataItemsInitialized(object? sender, string msg)
{
adapterClient.PingSent -= DataItemsInitialized;
waiter.Set();
}

adapterClient.PingSent += DataItemsInitialized;
adapterClient.Start();

Assert.True(waiter.WaitOne(10000));
}
}
}
Expand Down