Skip to content

Commit

Permalink
Update to truly test DurableSubscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Archie-Miller committed Sep 3, 2024
1 parent e14101d commit 80fd979
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
10 changes: 8 additions & 2 deletions Applications/ConsoleReferenceClient/ClientSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,14 @@ public void EnableEvents(ISession session, uint timeToRun)
/// <summary>
/// Create Subscription and MonitoredItems for DataChanges
/// </summary>
public void SubscribeToDataChanges(ISession session, uint minLifeTime, bool enableDurableSubscriptions)
public bool SubscribeToDataChanges(ISession session, uint minLifeTime, bool enableDurableSubscriptions)
{
bool isDurable = false;

if (session == null || session.Connected == false)
{
m_output.WriteLine("Session not connected!");
return;
return isDurable;
}

try
Expand Down Expand Up @@ -385,6 +387,8 @@ public void SubscribeToDataChanges(ISession session, uint minLifeTime, bool enab

if (subscription.SetSubscriptionDurable(1, out revisedLifetimeInHours))
{
isDurable = true;

m_output.WriteLine("Subscription {0} is now durable, Revised Lifetime {1} in hours.",
subscription.Id, revisedLifetimeInHours);
}
Expand Down Expand Up @@ -480,6 +484,8 @@ public void SubscribeToDataChanges(ISession session, uint minLifeTime, bool enab
{
m_output.WriteLine("Subscribe error: {0}", ex.Message);
}

return isDurable;
}
#endregion

Expand Down
27 changes: 18 additions & 9 deletions Applications/ConsoleReferenceClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,31 +381,40 @@ await samples.SubscribeAllValuesAsync(uaClient,
}
else
{
int quitTimeout = 30_000;
int quitTimeout = 65_000;
if (enableDurableSubscriptions)
{
quitTimeout = 300_000;
quitTimeout = 150_000;
}

NodeId sessionNodeId = uaClient.Session.SessionId;
// Run tests for available methods on reference server.
samples.ReadNodes(uaClient.Session);
samples.WriteNodes(uaClient.Session);
samples.Browse(uaClient.Session);
samples.CallMethod(uaClient.Session);
samples.EnableEvents(uaClient.Session, (uint)quitTimeout);
samples.SubscribeToDataChanges(uaClient.Session, 120_000, enableDurableSubscriptions);
bool isDurable = samples.SubscribeToDataChanges(
uaClient.Session, 60_000, enableDurableSubscriptions);
if ( isDurable )
{
// Need to control the reconnect
uaClient.ReconnectPeriod = 200_000;
}

output.WriteLine("Waiting...");

// Wait for some DataChange notifications from MonitoredItems
int waitCounters = 0;
int closeSessionTime = uaClient.ReconnectPeriod * 35;
int restartSessionTime = uaClient.ReconnectPeriod * 65;
while (!quit && waitCounters < quitTimeout)
int checkForWaitTime = 1000;
int closeSessionTime = checkForWaitTime * 35;
int restartSessionTime = checkForWaitTime * 65;
bool stopNotQuit = false;
while (!quit && !stopNotQuit && waitCounters < quitTimeout)
{
quit = quitEvent.WaitOne(uaClient.ReconnectPeriod);
waitCounters += uaClient.ReconnectPeriod;
if (enableDurableSubscriptions)
quit = quitEvent.WaitOne(checkForWaitTime);
waitCounters += checkForWaitTime;
if (isDurable)
{
if (waitCounters == closeSessionTime)
{
Expand Down
2 changes: 1 addition & 1 deletion Applications/ConsoleReferenceClient/UAClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private void Session_KeepAlive(ISession session, KeepAliveEventArgs e)
try
{
// check for events from discarded sessions.
if (!m_session.Equals(session))
if (m_session == null || !m_session.Equals(session))
{
return;
}
Expand Down

0 comments on commit 80fd979

Please sign in to comment.