Skip to content

Commit

Permalink
fixed uuid issues and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
wsobel committed Jul 2, 2024
1 parent 97eb79d commit 2a79f47
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/mtconnect/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ namespace mtconnect {
return;
}

m_context.pause([=](config::AsyncContext &context) {
auto callback = [=](config::AsyncContext &context) {
try
{
bool changed = false;
Expand Down Expand Up @@ -513,7 +513,14 @@ namespace mtconnect {
LOG(error) << "Error detail: " << f.what();
cerr << f.what() << endl;
}
});
};

// Gets around a race condition in the loading of adapaters and setting of
// UUID.
if (m_context.isRunning() && !m_context.isPauased())
m_context.pause(callback);
else
callback(m_context);
}

bool Agent::receiveDevice(device_model::DevicePtr device, bool version)
Expand Down
8 changes: 8 additions & 0 deletions src/mtconnect/configuration/async_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ namespace mtconnect::configuration {
/// @brief removes the copy constructor
AsyncContext(const AsyncContext &) = delete;
~AsyncContext() {}

/// @brief is the context running
/// @returns running status
auto isRunning() { return m_running; }

/// @brief return the paused state
/// @returns the paused state
auto isPauased() { return m_paused; }

/// @brief Testing only: method to remove the run guard from the context
void removeGuard() { m_guard.reset(); }
Expand Down
13 changes: 13 additions & 0 deletions test_package/agent_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,8 @@ TEST_F(AgentTest, adapter_should_receive_commands)
ASSERT_FALSE(device->preserveUuid());

m_agentTestHelper->m_adapter->parseBuffer("* uuid: MK-1234\n");
m_agentTestHelper->m_ioContext.run_for(2000ms);

m_agentTestHelper->m_adapter->parseBuffer("* manufacturer: Big Tool\n");
m_agentTestHelper->m_adapter->parseBuffer("* serialNumber: XXXX-1234\n");
m_agentTestHelper->m_adapter->parseBuffer("* station: YYYY\n");
Expand All @@ -1674,8 +1676,12 @@ TEST_F(AgentTest, adapter_should_receive_commands)
ASSERT_XML_PATH_EQUAL(doc, "//m:Description@station", "YYYY");
}

device = agent->getDeviceByName("LinuxCNC");
ASSERT_TRUE(device);

device->setPreserveUuid(true);
m_agentTestHelper->m_adapter->parseBuffer("* uuid: XXXXXXX\n");
m_agentTestHelper->m_ioContext.run_for(1000ms);

{
PARSE_XML_RESPONSE("/probe");
Expand Down Expand Up @@ -1735,13 +1741,20 @@ TEST_F(AgentTest, adapter_should_receive_device_commands)
ASSERT_EQ(string(*device2->getUuid()), device);

m_agentTestHelper->m_adapter->parseBuffer("* uuid: new-uuid\n");

device2 = agent->getDeviceByName("Device2");
ASSERT_TRUE(device2);

ASSERT_EQ("new-uuid", string(*device2->getUuid()));

m_agentTestHelper->m_adapter->parseBuffer("* device: device-1\n");
device = GetOption<string>(m_agentTestHelper->m_adapter->getOptions(), configuration::Device);
ASSERT_EQ(string(*device1->getUuid()), device);

m_agentTestHelper->m_adapter->parseBuffer("* uuid: another-uuid\n");
device1 = agent->getDeviceByName("Device1");
ASSERT_TRUE(device1);

ASSERT_EQ("another-uuid", string(*device1->getUuid()));
}

Expand Down
11 changes: 6 additions & 5 deletions test_package/config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ Adapters {
ASSERT_TRUE(exec) << "Cannot find DataItem with id exec";

auto pipeline = dynamic_cast<AdapterPipeline *>(adapter->getPipeline());
ASSERT_EQ("LinuxCNC", pipeline->getDevice());
ASSERT_EQ("000", pipeline->getDevice());
}
m_config->stop();
};
Expand Down Expand Up @@ -1600,7 +1600,7 @@ Port = 0
ASSERT_TRUE(exec) << "Cannot find DataItem with id exc";

auto pipeline = dynamic_cast<AdapterPipeline *>(adapter->getPipeline());
ASSERT_EQ("LinuxCNC", pipeline->getDevice());
ASSERT_EQ("000", pipeline->getDevice());
}
m_config->stop();
};
Expand Down Expand Up @@ -1770,7 +1770,7 @@ Port = 0
ASSERT_TRUE(device2) << "Cannot find LinuxCNC device";

auto pipeline = dynamic_cast<AdapterPipeline *>(adapter->getPipeline());
ASSERT_EQ("AnotherCNC", pipeline->getDevice());
ASSERT_EQ("001", pipeline->getDevice());
}
m_config->stop();
};
Expand Down Expand Up @@ -2000,7 +2000,7 @@ Port = 0
ASSERT_TRUE(device2) << "Cannot find LinuxCNC device";

auto pipeline = dynamic_cast<AdapterPipeline *>(adapter->getPipeline());
ASSERT_EQ("AnotherCNC", pipeline->getDevice());
ASSERT_EQ("001", pipeline->getDevice());
}

shutdownTimer.expires_from_now(3s);
Expand Down Expand Up @@ -2268,14 +2268,15 @@ AgentDeviceUUID = SOME_UUID
{
string config(R"DOC(
SchemaVersion=2.3
Port = 0
Adapters {
Simplest {
UUID = NEW-UUID
Port = 7878
}
}
)DOC");

m_config->setDebug(true);
m_config->loadConfig(config);

Expand Down

0 comments on commit 2a79f47

Please sign in to comment.