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

UMessage: validator and unit test #158

Merged

Conversation

billpittman
Copy link
Contributor

@billpittman billpittman commented Jun 13, 2024

UMessage: Validator and unit test.

@billpittman
Copy link
Contributor Author

@gregmedd Sorry I didn't see your message until this morning ... closed my browser.

@billpittman billpittman marked this pull request as ready for review June 13, 2024 20:10
@billpittman billpittman changed the title DRAFT - UMessage: validator and unit test UMessage: validator and unit test Jun 13, 2024
@gregmedd gregmedd linked an issue Jun 18, 2024 that may be closed by this pull request
Copy link
Contributor

@gregmedd gregmedd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are definitely some minor issues that could use clean-up in this PR. However, I don't know that any of the comments I'm adding are severe enough to block this change right now. I am considering capturing the feedback as issues and merging this code to unblock downstream work (e.g. up-transport-zenoh-cpp).

Comment on lines +29 to +31
return "The TTL, if present, indicates the ID has expired";
case Reason::PRIORITY_OUT_OF_RANGE:
return "The Priority, if set, is not within the allowable range";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't these errors only be returned when the field is present?

Suggested change
return "The TTL, if present, indicates the ID has expired";
case Reason::PRIORITY_OUT_OF_RANGE:
return "The Priority, if set, is not within the allowable range";
return "The TTL indicates the ID has expired";
case Reason::PRIORITY_OUT_OF_RANGE:
return "The Priority is not within the allowable range";

{
auto [valid, reason] = isValidRpcRequest(umessage);
if (valid) {
return {true, std::nullopt};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I'm pretty sure you can just do return {true, {}}, but I haven't tried it. It's not a big deal either way.

Comment on lines +95 to +101
if (!UPriority_IsValid(umessage.attributes().priority())) {
return {false, Reason::PRIORITY_OUT_OF_RANGE};
}

if (!UPayloadFormat_IsValid(umessage.attributes().payload_format())) {
return {false, Reason::PAYLOAD_FORMAT_OUT_OF_RANGE};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮 neat! I assume this interface is provided by protobuf for checking that enums are within range? That might be useful in #146 and #161

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggestion. I have now used this in #161

Comment on lines +238 to +240
if (!response.attributes().has_reqid()) {
return {false, Reason::REQID_MISMATCH};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check necessary? I think isValidRpcResponse() already checks it.

Comment on lines +247 to +251
if (request.attributes().priority() != response.attributes().priority()) {
return {false, Reason::PRIORITY_MISMATCH};
}

return {true, std::nullopt};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just occurred to me that there should be two more checks: The source of the request should match the sink of the response and the sink of the request should match the source of the request. A URI_MISMATCH reason could be added for this scenario.

src/datamodel/validator/UMessage.cpp Show resolved Hide resolved
Comment on lines +71 to +73
attributes.set_allocated_id(new UUID(id));
attributes.set_allocated_source(new UUri(source));
attributes.set_allocated_sink(new UUri(sink));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use set_allocated_ or new

Comment on lines +25 to +38
void SetUp() override {
source_.set_authority_name("10.0.0.1");
source_.set_ue_id(0x00010001);
source_.set_ue_version_major(1);
source_.set_resource_id(1);

sink_.set_authority_name("10.0.0.2");
sink_.set_ue_id(0x00010002);
sink_.set_ue_version_major(2);
sink_.set_resource_id(2);

reqId_.set_msb(0x1234);
reqId_.set_lsb(0x5678);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these don't change, do they need to be initialized for each individual test?

Comment on lines +85 to +92
uint64_t timestamp =
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();

id.set_msb((timestamp << 16) | (8ULL << 12) |
(0x123ULL)); // version 8 ; counter = 0x123
id.set_lsb((2ULL << 62) | (0xFFFFFFFFFFFFULL)); // variant 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just use the UUID builder here?

@gregmedd
Copy link
Contributor

None of the changes I requested would prevent us from moving forward. I'll file an immediate follow-up PR to address these changes since Bill is not currently available.

@gregmedd gregmedd merged commit 28f6271 into eclipse-uprotocol:main Jun 19, 2024
5 checks passed
@billpittman billpittman deleted the feature/validator/umessage branch June 24, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement and test datamodel::validator::UMessage
3 participants