Skip to content

Commit

Permalink
Recreate does not work as expected either
Browse files Browse the repository at this point in the history
I changed the reconnect test to be extremely obvious as to why it does not work, you should get an error if you never successfully connected before and then you reconnect, but you don't because of the condition inside reconnect to only reconnect if connected. As I said before, I think that reconnect should try to reconnect regardless of whether or not you are currently connected. In fact, if I were to put a condition in there, I would make it return if it were already connected, not if it wasn't. Also, the reconnect and recreate functions should not modify the status property because that is set in the keepalive function.

The Recreate function has the exact same problem so the test fails when you call recreate because the old session is the exact same object as the new session.
  • Loading branch information
jmbeach committed Aug 5, 2016
1 parent d7b5cb9 commit eb55e39
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tests/UaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Opc.Ua.Client;
using Opc.Ua;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Hylasoft.Opc.Tests
{
Expand Down Expand Up @@ -194,26 +195,39 @@ public void UaTestKeepAliveNotifyDisconnect()
}

[Test]
public void UaTestKeepAliveReConnect()
public void UaTestReConnect()
{
var client = new TestExtendUaClient(new Uri(ConfigurationManager.AppSettings["UATestEndpoint"]));
/* Should throw error because session should not be
* initialized without calling connect */
Assert.Throws<System.NullReferenceException>(() => client.ReConnect());
}

[Test]
public void UaTestSessionRecreate()
{
var client = new TestExtendUaClient(new Uri(ConfigurationManager.AppSettings["UATestEndpoint"]));
client.Connect();
var i = 0;
Session oldSession = null;
client.ServerConnectionLost += (object sender, EventArgs e) =>
{
i++;
Assert.AreEqual(OpcStatus.NotConnected, client.Status);
client.ReConnect();
// store the session to make sure a new one is created
oldSession = client.SessionExtended;
client.RecreateSession();
// put server back in good working order
client.SessionExtended.OperationTimeout = 200;
client.SessionExtended.KeepAliveInterval = 100;
};
client.SessionExtended.OperationTimeout = 0;
client.SessionExtended.KeepAliveInterval = 10;
Thread.Sleep(100);
Assert.Greater(i, 0);
// Give some time to call reconnect
// Give some time to call recreate
Thread.Sleep(100);
Assert.AreEqual(OpcStatus.Connected, client.Status);
Assert.AreNotSame(oldSession, client.SessionExtended);
}
}
}

0 comments on commit eb55e39

Please sign in to comment.