Skip to content

Commit

Permalink
Add integration test to run all example code, enable rx_proc.daemon
Browse files Browse the repository at this point in the history
Needed to modify some of the example code ports to match up with the
integration test script
  • Loading branch information
julianneswinoga committed May 19, 2024
1 parent 0f814e5 commit 274a431
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
6 changes: 3 additions & 3 deletions examples/simple_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def gui_callback(gui_data, event_pipe):
event_pipe.child_send(child_data)

"""
Start FlightGear with `--native-gui=socket,out,30,localhost,5504,udp --native-gui=socket,in,30,localhost,5505,udp`
Start FlightGear with `--native-gui=socket,out,30,localhost,5505,udp --native-gui=socket,in,30,localhost,5506,udp`
"""
if __name__ == '__main__': # NOTE: This is REQUIRED on Windows!
gui_conn = GuiConnection()
gui_event_pipe = gui_conn.connect_rx('localhost', 5504, gui_callback)
gui_event_pipe = gui_conn.connect_rx('localhost', 5505, gui_callback)
# Note: I couldn't get FlightGear to do anything with the returned data on this interface
# I think it's just ignoring everything. Technically you can send data back though.
# gui_conn.connect_tx('localhost', 5505)
# gui_conn.connect_tx('localhost', 5506)
gui_conn.start() # Start the GUI RX loop

while True:
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from flightgear_python.fg_if import HTTPConnection

"""
Start FlightGear with `--httpd=5050`
Start FlightGear with `--httpd=8080`
"""
http_conn = HTTPConnection('localhost', 5050)
http_conn = HTTPConnection('localhost', 8080)
pprint(http_conn.list_props('/', recurse_limit=0)) # List the top-level properties, no recursion
while True:
alt_ft = http_conn.get_prop('/position/altitude-ft')
Expand Down
1 change: 1 addition & 0 deletions flightgear_python/fg_if.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def start(self):
Start the RX/TX loop with FlightGear
"""
self.rx_proc = mp.Process(target=self._rx_process)
self.rx_proc.daemon = True # rx_proc should exit when parent exits
self.rx_proc.start()
_ = self.event_pipe.parent_recv() # Wait for child to actually run

Expand Down
24 changes: 24 additions & 0 deletions tests/test_integration_run_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import runpy
import multiprocess as mp
from pathlib import Path

import pytest
import _pytest.outcomes

pytestmark = pytest.mark.fg_integration


@pytest.mark.timeout(10) # Examples have infinite loops
@pytest.mark.parametrize('example_script_path', Path(__file__, '..', '..', 'examples').resolve().glob('*.py'))
def test_gui_rx_and_tx_integration(example_script_path: Path):
try:
runpy.run_path(str(example_script_path), run_name='__main__')
except _pytest.outcomes.Failed as py_fail:
# Timeout is expected, otherwise it's a real error
if 'timeout' not in py_fail.msg.lower():
raise py_fail
# With rx_proc.daemon this isn't strictly necessary, but without manually
# calling terminate the callback process still seem to be running. So this
# is still a good thing to do.
for mp_child in mp.active_children():
mp_child.terminate()

0 comments on commit 274a431

Please sign in to comment.