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