Commit 180f7958 authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

erp5_officejs_drone_simulator: fix timeout

Timeout feature was broken by 2f7689d1 .

Add timeout check in tests.
parent 0556a362
...@@ -1043,8 +1043,7 @@ var GameManager = /** @class */ (function () { ...@@ -1043,8 +1043,7 @@ var GameManager = /** @class */ (function () {
}; };
GameManager.prototype._timeOut = function () { GameManager.prototype._timeOut = function () {
var seconds = Math.floor(this._game_duration / 1000); return this._totalTime - this._game_duration <= 0;
return this._totalTime - seconds <= 0;
}; };
GameManager.prototype._allDronesFinished = function () { GameManager.prototype._allDronesFinished = function () {
...@@ -1227,7 +1226,7 @@ var GameManager = /** @class */ (function () { ...@@ -1227,7 +1226,7 @@ var GameManager = /** @class */ (function () {
_this.finish_deferred = RSVP.defer(); _this.finish_deferred = RSVP.defer();
console.log("Simulation started."); console.log("Simulation started.");
this._game_duration = Date.now(); this._game_duration = Date.now();
this._totalTime = GAMEPARAMETERS.gameTime + this._game_duration; this._totalTime = GAMEPARAMETERS.gameTime * 1000 + this._game_duration;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.65026.25145.27272</string> </value> <value> <string>1015.15557.49327.13158</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1709560433.33</float> <float>1710511088.86</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -3,8 +3,9 @@ ...@@ -3,8 +3,9 @@
(function (window, rJS, domsugar, document) { (function (window, rJS, domsugar, document) {
"use strict"; "use strict";
var SIMULATION_SPEED = 10, var SIMULATION_SPEED = 1,
SIMULATION_TIME = 270, LOOP_INTERVAL = 1000 / 60,
SIMULATION_TIME = LOOP_INTERVAL / 1000,
MIN_LAT = 45.6364, MIN_LAT = 45.6364,
MAX_LAT = 45.65, MAX_LAT = 45.65,
MIN_LON = 14.2521, MIN_LON = 14.2521,
...@@ -74,7 +75,7 @@ ...@@ -74,7 +75,7 @@
' me.getCurrentPosition().longitude\n' + ' me.getCurrentPosition().longitude\n' +
' ).toFixed(8),\n' + ' ).toFixed(8),\n' +
' time_interval = timestamp - me.start_time,\n' + ' time_interval = timestamp - me.start_time,\n' +
' expected_interval = 1000 / 60,\n' + ' expected_interval = ' + LOOP_INTERVAL + ',\n' +
' expectedDistance = (me.getSpeed() * expected_interval / 1000).toFixed(8);\n' + ' expectedDistance = (me.getSpeed() * expected_interval / 1000).toFixed(8);\n' +
' assert(time_interval, Math.floor(expected_interval), "Timestamp");\n' + ' assert(time_interval, Math.floor(expected_interval), "Timestamp");\n' +
' assert(realDistance, expectedDistance, "Distance");\n' + ' assert(realDistance, expectedDistance, "Distance");\n' +
...@@ -84,7 +85,6 @@ ...@@ -84,7 +85,6 @@
' longitude: me.initialPosition.longitude,\n' + ' longitude: me.initialPosition.longitude,\n' +
' altitude: me.initialPosition.altitude\n' + ' altitude: me.initialPosition.altitude\n' +
' });\n' + ' });\n' +
' me.exit(me.land());\n' +
'};', '};',
DRAW = true, DRAW = true,
LOG = true, LOG = true,
...@@ -120,19 +120,19 @@ ...@@ -120,19 +120,19 @@
"script_content": DEFAULT_SCRIPT_CONTENT}; "script_content": DEFAULT_SCRIPT_CONTENT};
} }
map_json = { map_json = {
"height": parseInt(map_height, 10), "height": map_height,
"start_AMSL": parseFloat(start_AMSL), "start_AMSL": start_AMSL,
"min_lat": parseFloat(MIN_LAT), "min_lat": MIN_LAT,
"max_lat": parseFloat(MAX_LAT), "max_lat": MAX_LAT,
"min_lon": parseFloat(MIN_LON), "min_lon": MIN_LON,
"max_lon": parseFloat(MAX_LON), "max_lon": MAX_LON,
"flag_list": [], "flag_list": [],
"obstacle_list" : [], "obstacle_list" : [],
"enemy_list" : [], "enemy_list" : [],
"initial_position": { "initial_position": {
"longitude": parseFloat(INIT_LON), "longitude": INIT_LON,
"latitude": parseFloat(INIT_LAT), "latitude": INIT_LAT,
"altitude": parseFloat(INIT_ALT) "altitude": INIT_ALT
} }
}; };
operator_init_msg = { operator_init_msg = {
...@@ -142,20 +142,20 @@ ...@@ -142,20 +142,20 @@
game_parameters_json = { game_parameters_json = {
"debug_test_mode": true, "debug_test_mode": true,
"drone": { "drone": {
"maxAcceleration": parseInt(MAX_ACCELERATION, 10), "maxAcceleration": MAX_ACCELERATION,
"maxDeceleration": parseInt(MAX_DECELERATION, 10), "maxDeceleration": MAX_DECELERATION,
"minSpeed": parseInt(MIN_SPEED, 10), "minSpeed": MIN_SPEED,
"speed": parseFloat(DEFAULT_SPEED), "speed": DEFAULT_SPEED,
"maxSpeed": parseInt(MAX_SPEED, 10), "maxSpeed": MAX_SPEED,
"maxRoll": parseFloat(MAX_ROLL), "maxRoll": MAX_ROLL,
"minPitchAngle": parseFloat(MIN_PITCH), "minPitchAngle": MIN_PITCH,
"maxPitchAngle": parseFloat(MAX_PITCH), "maxPitchAngle": MAX_PITCH,
"maxSinkRate": parseFloat(MAX_SINK_RATE), "maxSinkRate": MAX_SINK_RATE,
"maxClimbRate": parseFloat(MAX_CLIMB_RATE), "maxClimbRate": MAX_CLIMB_RATE,
"list": DRONE_LIST "list": DRONE_LIST
}, },
"gameTime": parseInt(SIMULATION_TIME, 10), "gameTime": SIMULATION_TIME,
"simulation_speed": parseInt(SIMULATION_SPEED, 10), "simulation_speed": SIMULATION_SPEED,
"latency": { "latency": {
"information": 0, "information": 0,
"communication": 0 "communication": 0
...@@ -214,19 +214,24 @@ ...@@ -214,19 +214,24 @@
}) })
.push(function (result) { .push(function (result) {
var div = domsugar('div', { text: "CONSOLE LOG ENTRIES:" }), lines, var div = domsugar('div', { text: "CONSOLE LOG ENTRIES:" }), lines,
l, node; l, test_log_node = document.querySelector('.test_log');
document.querySelector('.container').parentNode.appendChild(div); document.querySelector('.container').parentNode.appendChild(div);
function createLogNode(message) { function appendToTestLog(test_log_node, message) {
var log_node = document.createElement("div"), var log_node = document.createElement("div"),
textNode = document.createTextNode(message); textNode = document.createTextNode(message);
log_node.appendChild(textNode); log_node.appendChild(textNode);
return log_node; test_log_node.appendChild(log_node);
} }
lines = result.console_log.split('\n'); lines = result.console_log.split('\n');
for (l = 0; l < lines.length; l += 1) { for (l = 0; l < lines.length; l += 1) {
node = createLogNode(lines[l]); if (lines[l] !== 'TIMEOUT!') {
document.querySelector('.test_log').appendChild(node); appendToTestLog(test_log_node, lines[l]);
} else {
appendToTestLog(test_log_node, 'Timeout: OK');
return;
}
} }
appendToTestLog(test_log_node, 'Timeout: FAILED');
}, function (error) { }, function (error) {
return gadget.notifySubmitted({message: "Error: " + error.message, return gadget.notifySubmitted({message: "Error: " + error.message,
status: 'error'}); status: 'error'});
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.60680.20078.34286</string> </value> <value> <string>1015.15807.32412.36915</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1709286290.59</float> <float>1710526066.91</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -763,8 +763,7 @@ var GameManager = /** @class */ (function () { ...@@ -763,8 +763,7 @@ var GameManager = /** @class */ (function () {
}; };
GameManager.prototype._timeOut = function () { GameManager.prototype._timeOut = function () {
var seconds = Math.floor(this._game_duration / 1000); return this._totalTime - this._game_duration <= 0;
return this._totalTime - seconds <= 0;
}; };
GameManager.prototype._allDronesFinished = function () { GameManager.prototype._allDronesFinished = function () {
...@@ -904,7 +903,7 @@ var GameManager = /** @class */ (function () { ...@@ -904,7 +903,7 @@ var GameManager = /** @class */ (function () {
_this.finish_deferred = RSVP.defer(); _this.finish_deferred = RSVP.defer();
console.log("Simulation started."); console.log("Simulation started.");
this._game_duration = Date.now(); this._game_duration = Date.now();
this._totalTime = GAMEPARAMETERS.gameTime + this._game_duration; this._totalTime = GAMEPARAMETERS.gameTime * 1000 + this._game_duration;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
......
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.65027.38618.31573</string> </value> <value> <string>1015.15533.18317.53657</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1709560536.57</float> <float>1710509638.96</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -3,11 +3,9 @@ ...@@ -3,11 +3,9 @@
(function (window, rJS, domsugar, document, URLSearchParams, Blob) { (function (window, rJS, domsugar, document, URLSearchParams, Blob) {
"use strict"; "use strict";
var SIMULATION_SPEED = 10, var SIMULATION_SPEED = 1,
SIMULATION_TIME = 270, LOOP_INTERVAL = 1000 / 60,
MAP_SIZE = 600, SIMULATION_TIME = LOOP_INTERVAL / 1000,
map_height = 700,
start_AMSL = 595,
DEFAULT_SPEED = 16, DEFAULT_SPEED = 16,
MAX_ACCELERATION = 6, MAX_ACCELERATION = 6,
MAX_DECELERATION = 1, MAX_DECELERATION = 1,
...@@ -19,7 +17,6 @@ ...@@ -19,7 +17,6 @@
MAX_CLIMB_RATE = 8, MAX_CLIMB_RATE = 8,
MAX_SINK_RATE = 3, MAX_SINK_RATE = 3,
NUMBER_OF_DRONES = 1, NUMBER_OF_DRONES = 1,
FLAG_WEIGHT = 5,
MIN_LAT = 45.6364, MIN_LAT = 45.6364,
MAX_LAT = 45.65, MAX_LAT = 45.65,
MIN_LON = 14.2521, MIN_LON = 14.2521,
...@@ -78,7 +75,7 @@ ...@@ -78,7 +75,7 @@
' me.getCurrentPosition().longitude\n' + ' me.getCurrentPosition().longitude\n' +
' ).toFixed(8),\n' + ' ).toFixed(8),\n' +
' time_interval = timestamp - me.start_time,\n' + ' time_interval = timestamp - me.start_time,\n' +
' expected_interval = 1000 / 60,\n' + ' expected_interval = ' + LOOP_INTERVAL + ',\n' +
' expectedDistance = (me.getSpeed() * expected_interval / 1000).toFixed(8);\n' + ' expectedDistance = (me.getSpeed() * expected_interval / 1000).toFixed(8);\n' +
' assert(time_interval.toFixed(4), expected_interval.toFixed(4), "Timestamp");\n' + ' assert(time_interval.toFixed(4), expected_interval.toFixed(4), "Timestamp");\n' +
' assert(realDistance, expectedDistance, "Distance");\n' + ' assert(realDistance, expectedDistance, "Distance");\n' +
...@@ -88,7 +85,6 @@ ...@@ -88,7 +85,6 @@
' longitude: me.initialPosition.longitude,\n' + ' longitude: me.initialPosition.longitude,\n' +
' altitude: me.initialPosition.altitude\n' + ' altitude: me.initialPosition.altitude\n' +
' });\n' + ' });\n' +
' me.exit(me.land());\n' +
'};', '};',
DRAW = true, DRAW = true,
LOG = true, LOG = true,
...@@ -175,35 +171,35 @@ ...@@ -175,35 +171,35 @@
game_parameters_json = { game_parameters_json = {
"debug_test_mode": true, "debug_test_mode": true,
"drone": { "drone": {
"maxAcceleration": parseInt(MAX_ACCELERATION, 10), "maxAcceleration": MAX_ACCELERATION,
"maxDeceleration": parseInt(MAX_DECELERATION, 10), "maxDeceleration": MAX_DECELERATION,
"minSpeed": parseInt(MIN_SPEED, 10), "minSpeed": MIN_SPEED,
"speed": parseFloat(DEFAULT_SPEED), "speed": DEFAULT_SPEED,
"maxSpeed": parseInt(MAX_SPEED, 10), "maxSpeed": MAX_SPEED,
"maxRoll": parseFloat(MAX_ROLL), "maxRoll": MAX_ROLL,
"minPitchAngle": parseFloat(MIN_PITCH), "minPitchAngle": MIN_PITCH,
"maxPitchAngle": parseFloat(MAX_PITCH), "maxPitchAngle": MAX_PITCH,
"maxSinkRate": parseFloat(MAX_SINK_RATE), "maxSinkRate": MAX_SINK_RATE,
"maxClimbRate": parseFloat(MAX_CLIMB_RATE) "maxClimbRate": MAX_CLIMB_RATE
}, },
"gameTime": parseInt(SIMULATION_TIME, 10), "gameTime": SIMULATION_TIME,
"simulation_speed": parseInt(SIMULATION_SPEED, 10), "simulation_speed": SIMULATION_SPEED,
"latency": { "latency": {
"information": 0, "information": 0,
"communication": 0 "communication": 0
}, },
"map": { "map": {
"min_lat": parseFloat(MIN_LAT), "min_lat": MIN_LAT,
"max_lat": parseFloat(MAX_LAT), "max_lat": MAX_LAT,
"min_lon": parseFloat(MIN_LON), "min_lon": MIN_LON,
"max_lon": parseFloat(MAX_LON), "max_lon": MAX_LON,
"height": parseInt(HEIGHT), "height": HEIGHT,
"start_AMSL": parseFloat(start_AMSL) "start_AMSL": start_AMSL
}, },
"initialPosition": { "initialPosition": {
"longitude": parseFloat(INIT_LON), "longitude": INIT_LON,
"latitude": parseFloat(INIT_LAT), "latitude": INIT_LAT,
"altitude": parseFloat(INIT_ALT) "altitude": INIT_ALT
}, },
"draw_flight_path": DRAW, "draw_flight_path": DRAW,
"temp_flight_path": true, "temp_flight_path": true,
...@@ -257,19 +253,27 @@ ...@@ -257,19 +253,27 @@
return form_gadget.getContent(); return form_gadget.getContent();
}) })
.push(function (result) { .push(function (result) {
var div = domsugar('div', { text: "CONSOLE LOG ENTRIES:" }); var div = domsugar('div', { text: "CONSOLE LOG ENTRIES:" }),
lines = result.console_log.split('\n'),
line_nb,
node,
test_log_node = document.querySelector('.test_log');;
document.querySelector('.container').parentNode.appendChild(div); document.querySelector('.container').parentNode.appendChild(div);
function createLogNode(message) { function appendToTestLog(test_log_node, message) {
var node = document.createElement("div"); var log_node = document.createElement("div"),
var textNode = document.createTextNode(message); textNode = document.createTextNode(message);
node.appendChild(textNode); log_node.appendChild(textNode);
return node; test_log_node.appendChild(log_node);
} }
var lines = result.console_log.split('\n'); for (line_nb = 0; line_nb < lines.length; line_nb += 1) {
for (var i = 0;i < lines.length;i++) { if (lines[line_nb] !== 'TIMEOUT!') {
var node = createLogNode(lines[i]); appendToTestLog(test_log_node, lines[line_nb]);
document.querySelector('.test_log').appendChild(node); } else {
appendToTestLog(test_log_node, 'Timeout: OK');
return;
}
} }
appendToTestLog(test_log_node, 'Timeout: FAILED');
}, function (error) { }, function (error) {
return gadget.notifySubmitted({message: "Error: " + error.message, return gadget.notifySubmitted({message: "Error: " + error.message,
status: 'error'}); status: 'error'});
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.60681.20667.37171</string> </value> <value> <string>1015.15809.60561.48213</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1709286436.53</float> <float>1710526207.55</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment