[ntcore] Match standard handle layout, only allow 16 instances (#3577)

Now that there are only 16 instances, store them all statically.

Make tests more reliable by using different ports for each connection in listener tests.
This commit is contained in:
Peter Johnson
2021-09-17 12:11:00 -07:00
committed by GitHub
parent 263a248119
commit 161e211734
7 changed files with 44 additions and 75 deletions

View File

@@ -41,9 +41,9 @@ class ConnectionListenerTest {
}
/** Connect to the server. */
private void connect() {
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
m_clientInst.startClient("127.0.0.1", 10000);
private void connect(int port) {
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", port);
m_clientInst.startClient("127.0.0.1", port);
// wait for client to report it's started, then wait another 0.1 sec
try {
@@ -66,7 +66,7 @@ class ConnectionListenerTest {
assertNotSame(handle, 0, "bad listener handle");
// trigger a connect event
connect();
connect(10020);
// get the event
assertTrue(m_serverInst.waitForConnectionListenerQueue(1.0));
@@ -106,16 +106,19 @@ class ConnectionListenerTest {
assertFalse(events[0].connected);
}
private static int threadedPort = 10001;
@ParameterizedTest
@DisabledOnOs(OS.WINDOWS)
@ValueSource(strings = {"127.0.0.1", "127.0.0.1 ", " 127.0.0.1 "})
void testThreaded(String address) {
m_serverInst.startServer("connectionlistenertest.ini", address, 10000);
m_serverInst.startServer("connectionlistenertest.ini", address, threadedPort);
List<ConnectionNotification> events = new ArrayList<>();
final int handle = m_serverInst.addConnectionListener(events::add, false);
// trigger a connect event
m_clientInst.startClient(address, 10000);
m_clientInst.startClient(address, threadedPort);
threadedPort++;
// wait for client to report it's started, then wait another 0.1 sec
try {

View File

@@ -35,8 +35,8 @@ class EntryListenerTest {
}
private void connect() {
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
m_clientInst.startClient("127.0.0.1", 10000);
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10010);
m_clientInst.startClient("127.0.0.1", 10010);
// Use connection listener to ensure we've connected
int poller = NetworkTablesJNI.createConnectionListenerPoller(m_clientInst.getHandle());

View File

@@ -22,17 +22,16 @@ class ConnectionListenerTest : public ::testing::Test {
nt::DestroyInstance(client_inst);
}
void Connect();
void Connect(unsigned int port);
protected:
NT_Inst server_inst;
NT_Inst client_inst;
};
void ConnectionListenerTest::Connect() {
nt::StartServer(server_inst, "connectionlistenertest.ini", "127.0.0.1",
10000);
nt::StartClient(client_inst, "127.0.0.1", 10000);
void ConnectionListenerTest::Connect(unsigned int port) {
nt::StartServer(server_inst, "connectionlistenertest.ini", "127.0.0.1", port);
nt::StartClient(client_inst, "127.0.0.1", port);
// wait for client to report it's started, then wait another 0.1 sec
while ((nt::GetNetworkMode(client_inst) & NT_NET_MODE_STARTING) != 0) {
@@ -50,7 +49,7 @@ TEST_F(ConnectionListenerTest, Polled) {
ASSERT_NE(handle, 0u);
// trigger a connect event
Connect();
Connect(10000);
// get the event
ASSERT_TRUE(nt::WaitForConnectionListenerQueue(server_inst, 1.0));
@@ -85,7 +84,7 @@ TEST_F(ConnectionListenerTest, Threaded) {
false);
// trigger a connect event
Connect();
Connect(10001);
ASSERT_TRUE(nt::WaitForConnectionListenerQueue(server_inst, 1.0));

View File

@@ -35,16 +35,16 @@ class EntryListenerTest : public ::testing::Test {
nt::DestroyInstance(client_inst);
}
void Connect();
void Connect(unsigned int port);
protected:
NT_Inst server_inst;
NT_Inst client_inst;
};
void EntryListenerTest::Connect() {
nt::StartServer(server_inst, "entrylistenertest.ini", "127.0.0.1", 10000);
nt::StartClient(client_inst, "127.0.0.1", 10000);
void EntryListenerTest::Connect(unsigned int port) {
nt::StartServer(server_inst, "entrylistenertest.ini", "127.0.0.1", port);
nt::StartClient(client_inst, "127.0.0.1", port);
// Use connection listener to ensure we've connected
NT_ConnectionListenerPoller poller =
@@ -81,7 +81,7 @@ TEST_F(EntryListenerTest, EntryNewLocal) {
}
TEST_F(EntryListenerTest, DISABLED_EntryNewRemote) {
Connect();
Connect(10010);
if (HasFatalFailure()) {
return;
}
@@ -135,7 +135,7 @@ TEST_F(EntryListenerTest, PrefixNewLocal) {
}
TEST_F(EntryListenerTest, DISABLED_PrefixNewRemote) {
Connect();
Connect(10011);
if (HasFatalFailure()) {
return;
}