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

replace info with launch testing #351

Closed
wants to merge 11 commits into from
Closed

Conversation

Karsten1987
Copy link
Collaborator

fixes #271 by replacing the end to end tests in rosbag2_tests with launch_testing.

Signed-off-by: Karsten Knese [email protected]

Signed-off-by: Karsten Knese <[email protected]>
Signed-off-by: Karsten Knese <[email protected]>
Signed-off-by: Karsten Knese <[email protected]>
@Karsten1987
Copy link
Collaborator Author

to get an idea about windows:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Signed-off-by: Karsten Knese <[email protected]>
Signed-off-by: Karsten Knese <[email protected]>
@Karsten1987
Copy link
Collaborator Author

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@Karsten1987
Copy link
Collaborator Author

so this doesn't sound good:

18:38:53 3: [WARNING] [ros2-1]: 'SIGINT' sent to process[ros2-1] not supported on Windows, escalating to 'SIGTERM'
18:38:53 3: [INFO] [ros2-1]: sending signal 'SIGTERM' to process[ros2-1]

@hidmic the test_play_end_to_end.py is timing out. It might be related to the above warning/error. Do you have any idea on how to work around this?

Any help is appreciated. I'd like to have this sorted out before digging deeper into porting all tests to launch testing.

Signed-off-by: Karsten Knese <[email protected]>
Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

About SIGINT not being sent on Windows, that is (unfortunately) expected. There is no equivalent in Windows, and thus launch (not the testing framework but the process management infrastructure itself) escalates to a SIGTERM equivalent (see here).

@wjwwood do you recall why CTRL_C_EVENT was never an option in Windows? I recall it wouldn't work right away, but that's as far as my memory goes.

r'\| Count: 3 \| Serialization Format: cdr\n'
r'\s+Topic: /array_topic \| Type: test_msgs/Arrays '
r'\| Count: 4 \| Serialization Format: cdr'))
launch_testing.asserts.assertInStdout(proc_output, p, rosbag_info_process)
Copy link
Contributor

Choose a reason for hiding this comment

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

@Karsten1987 FYI you can also assert on command.output, and there's launch_testing.tools.output.expect_output to aid that if you want.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but expect_output does not accept a regex pattern, does it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeap, it does. All these assertIn* functions use expect_output under the hood.

with launch_testing.tools.launch_process(
launch_service, rosbag_info_process, proc_info, proc_output) as command:
assert command.wait_for_shutdown(timeout=3)
assert command.exit_code == launch_testing.asserts.EXIT_OK
Copy link
Contributor

Choose a reason for hiding this comment

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

@Karsten1987 nit: I'd move this statement outside the context manager scope

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

how do I access the exit code if the command is out of scope?

Copy link
Contributor

Choose a reason for hiding this comment

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

command doesn't leave scope after the with statement is over :)

try:
shutil.rmtree(dir_path)
except OSError as e:
print("Error: %s : %s" % (dir_path, e.strerror))
Copy link
Contributor

Choose a reason for hiding this comment

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

@Karsten1987 you may want to use setUp() and tearDown() methods to create and destroy temporary resources.

with launch_testing.tools.launch_process(
launch_service, rosbag_record_process, proc_info, proc_output) as command:
time.sleep(10)
proc_info.assertWaitForShutdown(rosbag_record_process, timeout=5)
Copy link
Contributor

Choose a reason for hiding this comment

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

@Karsten1987 FYI you can use command.wait_for_shutdown too.

@hidmic
Copy link
Contributor

hidmic commented Apr 7, 2020

@hidmic the test_play_end_to_end.py is timing out. It might be related to the above warning/error. Do you have any idea on how to work around this?

Hmm, I looked at it for a while but I don't see how it got into that state. Exit codes are unrelated. Can you reproduce in a Windows box? If you run launch_test with -v that may help us understand what is happening.

@wjwwood
Copy link
Member

wjwwood commented Apr 7, 2020

@wjwwood do you recall why CTRL_C_EVENT was never an option in Windows? I recall it wouldn't work right away, but that's as far as my memory goes.

No I don’t remember the details, only that it is asymmetric between windows and Linux.

Signed-off-by: Karsten Knese <[email protected]>
@Karsten1987
Copy link
Collaborator Author

Are you guys aware of any workarounds for the ctrl-c dilemma? I just played around locally with stuff like shown here: https://gist.github.com/rdp/f51fb274d69c5c31b6be

Which works pretty decently and rosbag behaves accurately, meaning it receives the ctrl-c and writes the bagfiles correctly. I found the equivalent in python using ctypes:
https://stackoverflow.com/a/58802146/4583130

Would you have an idea if that route is somewhat feasible?

@Karsten1987
Copy link
Collaborator Author

After talking with @hidmic I've tried a couple of more things (CTRL_C_EVENT instead of SIGTERM, playing around with creationflags (https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags)) but that all seemed to lead into a deep rabbit hole which is most likely not worth it.

In order to stabilize the end to end tests, I have a couple of ideas I'd like to run by you (i.e. @emersonknapp, @piraka9011, @zmichaels11).

  • introduce a new CLI option which dictates the duration of recording (could possibly also be used for replaying). That would allow the record e2e tests to automatically stop after n seconds and we wouldn't need to rely on a custom ctrl-c event.
  • convert the internal Rosbag2Node into a lifecycle node. I think this could help us overcome parts of the flaky discovery problems we encounter especially in the replay tests. In the configure step of the lifecycle node, we could prepare and advertise the publishers on the system. Likewise, the subscriptions in the test can be started. After that, the activate step really only triggers the call to publish.
  • similar to the approach above, I've started work a while ago on a CLI option called --paused where the rosbag would start to prepare everything, but don't publish. Either by a service call or spacebar the replay would start. As a gut feeling, I am in favor of the lifecycle node though.

Any opinions?

@piraka9011
Copy link
Contributor

piraka9011 commented Apr 10, 2020

I too played around with this ctrl-c business on windows (See this branch, specifically, this file). However, my approach kills colcon test when it attempts to raise ctrl-c (I opened an issue here).

I came to the conclusion that the right way to go about this is to introduce keyboard commands to control the rosbag2 node, specifically things like s/stop, q/quit and p/pause.

The lifecycle node approach is also good, it allows a user to programmatically control the rosbag2 node. I think keyboard/cli/lifecycle node approaches are all valid and we should decide what is the most useful approach (probably lifecycle).

Your first approach is the fastest to develop IMO and a good short term solution to the issue.

@piraka9011
Copy link
Contributor

FYI, Also played around with the windows creation flags, trying out different combinations one by one...
Unfortunately it did not resolve the issue 🙃

@zmichaels11
Copy link
Contributor

Instead of invoking the ros2 cli, can the tests instead just invoke the commands that the cli runs?

@Karsten1987
Copy link
Collaborator Author

I think keyboard/cli/lifecycle node approaches are all valid and we should decide what is the most useful approach (probably lifecycle).

I don't see them as mutual exclusive. I could see how the lifecycle generally offers a way to steer the communication and the keyboard inputs are really only a trigger to the state transitions of that lifecycle. That would make sense to me.

However, my approach kills colcon test when it attempts to raise ctrl-c

I ran into the same thing. The closest I came to a solution was trying to use CREATE_NEW_CONSOLE, but this also didn't really yield any results.

Instead of invoking the ros2 cli, can the tests instead just invoke the commands that the cli runs?

I guess we could tackle the e2e tests starting from rosbag2_transport. Cause, really, the CLI is only forwarding the command line options to the constructor of the transport class.

@emersonknapp
Copy link
Collaborator

closing as stale. can reopen if anyone wants to take on this work

@MichaelOrlov MichaelOrlov deleted the end_to_end_launch_testing branch July 13, 2024 07:02
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.

Resolve workarounds in rosbag2_tests for Windows
6 participants