Skip to content

Commit 4afd189

Browse files
committed
Resolve minor copilot feedback
1 parent d321343 commit 4afd189

6 files changed

Lines changed: 28 additions & 18 deletions

File tree

gcs/src/components/toolbar/simulationModal.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export default function SimulationModal() {
150150
: emitStartSimulation(),
151151
)
152152
}}
153-
loading={simulationStatus == SimulationStatus.Starting}
153+
loading={simulationStatus === SimulationStatus.Starting}
154154
>
155155
{isSimulationRunning ? "Stop Simulation" : "Start Simulation"}
156156
</Button>

gcs/src/redux/middleware/emitters.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ export function handleEmitters(socket, store, action) {
203203
callback: () => {
204204
const storeState = store.getState()
205205
const simParams = storeState.droneConnection.simParams
206-
console.log(simParams)
207206
socket.socket.emit("start_docker_simulation", {
208207
port: simParams.port,
209208
vehicleType: simParams.vehicleType,

gcs/src/redux/middleware/socketMiddleware.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,10 @@ const socketMiddleware = (store) => {
432432
if (msg.success && msg.running) {
433433
const storeState = store.getState()
434434
if (storeState.droneConnection.simParams.connectAfterStart) {
435+
const port = storeState.droneConnection.simParams.port
435436
store.dispatch(
436437
emitConnectToDrone({
437-
port: "tcp:127.0.0.1:5760",
438+
port: `tcp:127.0.0.1:${port}`,
438439
baud: 115200,
439440
wireless: true,
440441
connectionType: ConnectionType.Network,

gcs/src/redux/slices/droneConnectionSlice.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ const droneConnectionSlice = createSlice({
178178
},
179179
setSimulationParam: (state, action) => {
180180
const { key, value } = action.payload
181-
state.simParams[key] = value === "" ? null : value
181+
state.simParams[key] =
182+
value === "" || value === undefined ? null : value
182183
},
183184

184185
// Emits

radio/app/endpoints/simulation.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_docker_client():
1717
return None
1818

1919

20-
def ensure_image(client) -> bool:
20+
def pull_image_if_needed(client) -> bool:
2121
"""
2222
Checks if the client contains the given image.
2323
If not it attempts to download it.
@@ -63,7 +63,7 @@ def ensure_image(client) -> bool:
6363

6464
def build_command(data):
6565
"""
66-
Parses tbe socketio data into the form required for the docker command.
66+
Parses the socketio data into the form required for the docker command.
6767
6868
Args:
6969
data: The parameters that the simulator should start with.
@@ -115,7 +115,7 @@ def container_already_running(client, container_name) -> bool:
115115
def wait_for_container_running_result(container, timeout=30):
116116
"""
117117
Waits for if the container runs successfully and thus prints:
118-
"YOU CAN NOW CONNECT"
118+
"YOU CAN NOW CONNECT" (With the spaces missing)
119119
120120
Args:
121121
container: The container to wait for.
@@ -173,16 +173,27 @@ def start_docker_simulation(data) -> None:
173173
)
174174
return
175175

176-
image_result = ensure_image(client)
176+
image_result = pull_image_if_needed(client)
177177
if image_result is False:
178178
return # Error already given in function
179179

180180
if container_already_running(client, CONTAINER_NAME):
181181
return # Error already given in function
182182

183-
try:
183+
if "port" in data:
184184
port = data["port"]
185+
else:
186+
socketio.emit(
187+
"simulation_result",
188+
{
189+
"success": False,
190+
"running": False,
191+
"message": "Invalid port",
192+
},
193+
)
194+
return
185195

196+
try:
186197
container = client.containers.run(
187198
IMAGE_NAME,
188199
name=CONTAINER_NAME,

radio/tests/test_simulation.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from flask_socketio.test_client import SocketIOTestClient
22
import docker
3+
from docker.errors import DockerException
34
from . import falcon_test
45

56
client = docker.from_env()
@@ -13,27 +14,25 @@ def cleanup_container():
1314
container = client.containers.get("fgcs_ardupilot_sitl")
1415
container.stop()
1516
container.remove()
16-
except docker.errors.NotFound:
17-
pass
17+
except DockerException:
18+
pass # Container does not exist and therefore no cleanup required
1819

1920

2021
@falcon_test()
2122
def test_start_docker_simulation_success(socketio_client: SocketIOTestClient):
2223
"""
2324
Test successfully starting the simulation using Docker.
2425
"""
26+
cleanup_container()
27+
2528
socketio_client.emit("start_docker_simulation", {"port": 5763})
2629
result = socketio_client.get_received()[-1]
2730

2831
assert result["name"] == "simulation_result"
2932
assert result["args"][0]["success"] is True
3033
assert "Simulation started" in result["args"][0]["message"]
3134

32-
# Cleanup
33-
socketio_client.emit("stop_docker_simulation")
34-
stop_result = socketio_client.get_received()[-1]
35-
36-
assert stop_result["args"][0]["success"] is True
35+
cleanup_container()
3736

3837

3938
@falcon_test()
@@ -73,6 +72,7 @@ def test_stop_docker_simulation(socketio_client: SocketIOTestClient):
7372
client.containers.run(
7473
"kushmakkapati/ardupilot_sitl",
7574
name="fgcs_ardupilot_sitl",
75+
ports={5765: 5765},
7676
detach=True,
7777
tty=True,
7878
)
@@ -84,8 +84,6 @@ def test_stop_docker_simulation(socketio_client: SocketIOTestClient):
8484
assert result["args"][0]["success"] is True
8585
assert "Simulation stopped" in result["args"][0]["message"]
8686

87-
cleanup_container()
88-
8987

9088
@falcon_test()
9189
def test_build_command(socketio_client: SocketIOTestClient):

0 commit comments

Comments
 (0)