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

Fix test_message_conversion.py #645

Merged
merged 12 commits into from
Dec 10, 2021

Conversation

kenji-miyake
Copy link
Contributor

@kenji-miyake kenji-miyake commented Sep 24, 2021

Public Changes

None

Description

Fixed test_message_conversion.py.
Since it has some bugs in the application code, I'll fix them in another PR #646.

Related: #643

@amacneil
Copy link
Member

Glad to see #651 caught some new missing test dependencies.

fyi @jtbandes

@kenji-miyake kenji-miyake marked this pull request as ready for review October 8, 2021 09:22
Copy link
Member

@amacneil amacneil left a comment

Choose a reason for hiding this comment

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

thanks! needs rebase before merging

@kenji-miyake
Copy link
Contributor Author

@amacneil Thank you! How do we merge this?

  1. Close this and merge Fix message conversion #646 instead
  2. Apply fixes in Fix message conversion #646 first and add tests
  3. Merge this (temporarily breaks CI), quickly rebase and merge Fix message conversion #646

for msg in [{"data": data_value}]:
inst = ros_loader.get_message_instance(msgtype)
c.populate_instance(msg, inst)
self.assertEqual(inst.data, bytes([data_value]))
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is right. std_msgs/Byte holds a single byte, why should it be a bytes instance?

Copy link
Contributor Author

@kenji-miyake kenji-miyake Oct 17, 2021

Choose a reason for hiding this comment

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

I'm not so familiar with this, but as far as I know, it's because rclpy defines so.

image

https://design.ros2.org/articles/generated_interfaces_python.html

In [1]: from example_interfaces.msg import Byte                                                                                                                                                                    

In [2]: Byte().data                                                                                                                                                                                                
Out[2]: b'\x00'

In [3]: Byte().data == bytes([0])                                                                                                                                                                                  
Out[3]: True

In [4]: Byte().data == 0                                                                                                                                                                                             
Out[4]: False

@jtbandes
Copy link
Member

As for how to merge this PR: I think it's fine to merge this PR first (once approved), just disable the failing tests using unittest.skip. Then the skip can be removed in #646.

Comment on lines 188 to 191
msg = {"sec": 3, "nanosec": 5}
self.do_test(msg, "builtin_interfaces/Time")

msg = {"times": [{"secs": 3, "nsecs": 5}, {"secs": 2, "nsecs": 7}]}
msg = {"times": [{"sec": 3, "nanosec": 5}, {"sec": 2, "nanosec": 7}]}
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean the JSON format of time/duration fields is changing for ROS 2? Will clients need to update their code? I think we need to maintain backward compatibility with the secs/nsecs format if that is the format existing JSON clients are expecting.

Copy link
Contributor Author

@kenji-miyake kenji-miyake Oct 17, 2021

Choose a reason for hiding this comment

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

Does this mean the JSON format of time/duration fields is changing for ROS 2?

As a test spec, yes.
As an application spec, no. It's already changed.

To test this, please run the following commands.

Case 1. Working

// Terminal 1
$ ros2 run rosbridge_server rosbridge_websocket
// normal outputs

// Terminal 2
$ curl -sL https://github.com/tier4/rosbridge_suite/raw/add-test-scripts/test_scripts/time.py | python
publish: {'sec': 1, 'nanosec': 2}
subscribe: {'sec': 1, 'nanosec': 2}
publish: {'sec': 1, 'nanosec': 2}
subscribe: {'sec': 1, 'nanosec': 2}

Case 2. Not working

// Terminal 1
$ ros2 run rosbridge_server rosbridge_websocket
[ERROR 1634483257.554689935] [rosbridge_websocket]: [Client 4] [id: publish:/time:3] publish: 'Time' object has no attribute 'secs'
[ERROR 1634483258.559444873] [rosbridge_websocket]: [Client 4] [id: publish:/time:4] publish: 'Time' object has no attribute 'secs'

// Terminal 2
$ curl -sL https://github.com/tier4/rosbridge_suite/raw/add-test-scripts/test_scripts/time_old_format.py | python
publish: {'secs': 1, 'nsecs': 2}
publish: {'secs': 1, 'nsecs': 2}

Copy link
Member

Choose a reason for hiding this comment

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

Even though it's already changed, we could still choose to change it back (and we should bump the major version of the package if it's not backward compatible). Do you think users of the library will be confused by the difference in behavior between ROS 1/2? If someone upgrades from ROS 1 to ROS 2 their websocket client will start receiving values. Should we change it back to secs/nsecs or at least change the publish side to accept both forms?

cc @defunctzombie @amacneil for thoughts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jtbandes I'll leave the decision to the maintainers, but my personal (and selfish) thought is, since our company has completely moved to ROS2, either one is fine.

Do you think users of the library will be confused by the difference in behavior between ROS 1/2?

Yes, I remember we had to fix some web application code for ROS2, but it wasn't so big confusion.

But anyway, I think clients should change the data format when they receive the data because rosbridge outputs the same data for each client. Is this correct or does rosbridge change output data depending on the client ROS version?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not following the comments in this thread. Is the statement that rosbridge currently outputs sec/nsec and this is confusing for ros2 users and we should change to sec/nanosec? Or that rosbridge outputs sec/nanosec and this is confusing for ros1 users?

What is the specific change (if any) being requested of the api/protocol?

Copy link
Member

Choose a reason for hiding this comment

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

Currently it outputs secs/nsecs for ROS 1 and sec/nanosec for ROS 2. This PR just changes the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is just changing a test then we should merge the PR to have tests and tackle API changes in separate discussions.

@jtbandes
Copy link
Member

jtbandes commented Dec 9, 2021

Can you please rebase on #686 ? These newly added tests were not running in CI, and they might need more changes to be able to pass CI.

@kenji-miyake
Copy link
Contributor Author

Hmm, It seems the test is running at least in this PR. @jtbandes Do you know why?
https://github.com/RobotWebTools/rosbridge_suite/runs/3867023090?check_suite_focus=true
image

But anyway, I'll rebase related PRs later.

@jtbandes
Copy link
Member

Hm, maybe only some tests are affected, not sure why. I just merged that PR so you should be able to rebase on ros2 now. Thanks for your patience!

@kenji-miyake
Copy link
Contributor Author

Rebased. The tests won't pass because there is no logic change.

@jtbandes
Copy link
Member

Yep, that makes sense. Can you use @unittest.skip or @pytest.mark.xfail to disable the tests that are failing? Then we can merge this PR, and you can re-enable them in the other PR.

Kenji Miyake added 11 commits December 10, 2021 13:56
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
@kenji-miyake kenji-miyake marked this pull request as draft December 10, 2021 05:05
@kenji-miyake
Copy link
Contributor Author

@jtbandes Yes it's possible, but before that, we have to agree with the test specifications around Time related to this discussion.
#645 (comment)

Should I add tests for both secs/nsecs and sec/nanosec?

@jtbandes
Copy link
Member

I think it's fine to keep sec/nanosec behavior for ROS 2 because that's what the builtin_interfaces/Time and Duration use. That's what you were already planning to do with these PRs, right?

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
@kenji-miyake
Copy link
Contributor Author

kenji-miyake commented Dec 10, 2021

@jtbandes That's right, but I'm not sure it's enough.
For example, if there are only tests for sec/nanosec, the test passes even if I completely remove secs/nsecs from the code.
Like 21ecfe6 in #646

Anyway, I skipped invalid tests and the tests passed. Is that okay for you?

@kenji-miyake kenji-miyake marked this pull request as ready for review December 10, 2021 05:27
@jtbandes
Copy link
Member

jtbandes commented Dec 10, 2021

the test passes even if I completely remove secs/nsecs from the code

I see. Just trying to understand the current behavior... is rosbridge currently accepting both secs/nsecs and sec/nanosec for any time/duration fields in op: publish? If so, removing it would be a breaking change and I see why we would want to cover it in the test. In that case keeping the current behavior (accepting both secs/nsecs and sec/nanosec) seems fine, otherwise we would need to bump the package major version (and/or add some features to the protocol for clients to detect the server version).

On the subscriber side, is it right that rosbridge will always send sec/nanosec to subscribers (since the initial ros2 conversion)?

Anyway, I think these issues can be addressed in #646. If you don't mind, I can merge this PR now.

By the way, if you would like to discuss any of these issues/PRs in a faster communication channel, we have a Slack workspace at http://foxglove.dev/slack with a #ros2 channel. Feel free to ping us anytime in there 🙂 I'm also a member of the ros discord server.

@jtbandes jtbandes merged commit cf57ed9 into RobotWebTools:ros2 Dec 10, 2021
@kenji-miyake
Copy link
Contributor Author

Anyway, I think these issues can be addressed in #646. If you don't mind, I can merge this PR now.

@jtbandes Yes, I'm okay if maintainers are okay with test specs. (Oh, merged while I'm writing, thank you!)
Actually, #646 has some mixed fixes, so I'll split them into separated small problems.

is rosbridge currently accepting both secs/nsecs and sec/nanosec for any time/duration fields in op: publish?

I'm sorry, I'm not familiar with this behavior. 🥲

@kenji-miyake kenji-miyake deleted the fix-rostest-message-conversion branch December 10, 2021 05:53
@jtbandes
Copy link
Member

is rosbridge currently accepting both secs/nsecs and sec/nanosec for any time/duration fields in op: publish?

I'm sorry, I'm not familiar with this behavior. 🥲

Me neither 😆 But I thought maybe that's what this code is trying to do (convert a JSON message from the ws client into a ROS time/duration msg).

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.

None yet

4 participants