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

software/js-drone: process all logs

Process all available logs to avoid delay in log printing.
parent 0e9402eb
...@@ -42,4 +42,4 @@ md5sum = dfa140d70d8a9cadc6cee865be4e8c26 ...@@ -42,4 +42,4 @@ md5sum = dfa140d70d8a9cadc6cee865be4e8c26
[worker] [worker]
_update_hash_filename_ = drone-scripts/worker.js.jinja2 _update_hash_filename_ = drone-scripts/worker.js.jinja2
md5sum = 5e642dc35d86b7d7636532ffc9cc2bdb md5sum = 39c25f9083151a18318ed8ee4ad4fdbe
...@@ -235,8 +235,9 @@ import { evalScript, fdopen, loadFile, open } from "std"; ...@@ -235,8 +235,9 @@ import { evalScript, fdopen, loadFile, open } from "std";
if (clientId !== undefined) { if (clientId !== undefined) {
log = getLog(); log = getLog();
if (log.length > 0) { while (log.length > 0) {
user_me.writeWebsocketMessage(JSON.stringify({log: log})); user_me.writeWebsocketMessage(JSON.stringify({log: log}));
log = getLog();
} }
} }
......
...@@ -31,7 +31,9 @@ import os ...@@ -31,7 +31,9 @@ import os
import socket import socket
import struct import struct
import time import time
import websocket
from contextlib import closing
from websocket import create_connection
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
...@@ -277,58 +279,30 @@ class SubscriberTestCase(SlapOSInstanceTestCase): ...@@ -277,58 +279,30 @@ class SubscriberTestCase(SlapOSInstanceTestCase):
self.assertIn(expected_string, f.readlines()) self.assertIn(expected_string, f.readlines())
def test_pubsub_subscription(self): def test_pubsub_subscription(self):
ws = websocket.WebSocket() with closing(create_connection(self.websocket_server_address, timeout=5)) as conn:
ws.connect(self.websocket_server_address, timeout=5)
# Check if first message is 'Unknown instruction IP' where IP is client IPv6 address # Check if first message is 'Unknown instruction IP' where IP is client IPv6 address
self.assertIn( self.assertIn(
b'Unknown instruction %s' % ws.sock.getsockname()[0].encode(), b'Unknown instruction %s' % conn.sock.getsockname()[0].encode(),
ws.recv_frame().data, conn.recv_frame().data,
) )
self.assertIn( self.assertIn(
b'\\u001b[32minfo/userland\\u001b[0m\\tfieldsSize 3\\n"}', b'\\u001b[32minfo/userland\\u001b[0m\\tfieldsSize 3\\n"}',
ws.recv_frame().data, ws.recv_frame().data,
) )
self.assertEqual(
ws.recv_frame().data,
b''.join((
b'{"drone_dict":{"0":{"latitude":',
b'"%.6f","longitude":"%.6f","altitude":"%.2f",' % (0, 0, 0),
b'"yaw":"%.2f","speed":"%.2f","climbRate":"%.2f",' % (0, 0, 0),
b'"timestamp":%d}}}' % 0,
)),
)
self.assertIn( self.assertIn(
b'\\u001b[32minfo/client\\u001b[0m\\tReceived position of drone 0: %.6f ? %.6f ? %.2f m %.2f m\\n"}' % (0, 0 , 0, 0), b'\\u001b[32minfo/client\\u001b[0m\\tReceived position of drone 0: %.6f ? %.6f ? %.2f m %.2f m\\n"}' % (0, 0 , 0, 0),
ws.recv_frame().data, ws.recv_frame().data,
) )
self.assertEqual(
ws.recv_frame().data,
b''.join((
b'{"drone_dict":{"0":{"latitude":',
b'"%.6f","longitude":"%.6f","altitude":"%.2f",' % (0, 0, 0),
b'"yaw":"%.2f","speed":"%.2f","climbRate":"%.2f",' % (0, 0, 0),
b'"timestamp":%d}}}' % 0,
)),
)
self.assertIn( self.assertIn(
b'\\u001b[32minfo/client\\u001b[0m\\tReceived speed of drone 0: %.2f ? %.2f m/s %.2f m/s\\n"}' % (0, 0 , 0), b'\\u001b[32minfo/client\\u001b[0m\\tReceived speed of drone 0: %.2f ? %.2f m/s %.2f m/s\\n"}' % (0, 0 , 0),
ws.recv_frame().data, ws.recv_frame().data,
) )
self.assertEqual(
ws.recv_frame().data,
b''.join((
b'{"drone_dict":{"0":{"latitude":',
b'"%.6f","longitude":"%.6f","altitude":"%.2f",' % (0, 0, 0),
b'"yaw":"%.2f","speed":"%.2f","climbRate":"%.2f",' % (0, 0, 0),
b'"timestamp":%d}}}' % 0,
)),
)
self.assertIn( self.assertIn(
b'\\u001b[32minfo/userland\\u001b[0m\\tfieldsSize 1\\n"}', b'\\u001b[32minfo/userland\\u001b[0m\\tfieldsSize 1\\n"}',
ws.recv_frame().data, ws.recv_frame().data,
) )
self.assertEqual( self.assertEqual(
ws.recv_frame().data, conn.recv_frame().data,
b''.join(( b''.join((
b'{"drone_dict":{"0":{"latitude":', b'{"drone_dict":{"0":{"latitude":',
b'"%.6f","longitude":"%.6f","altitude":"%.2f",' % (0, 0, 0), b'"%.6f","longitude":"%.6f","altitude":"%.2f",' % (0, 0, 0),
...@@ -338,13 +312,17 @@ class SubscriberTestCase(SlapOSInstanceTestCase): ...@@ -338,13 +312,17 @@ class SubscriberTestCase(SlapOSInstanceTestCase):
) )
self.send_ua_networkMessage() self.send_ua_networkMessage()
time.sleep(0.1) time.sleep(0.1)
self.assertEqual(ws.recv_frame().data, MESSAGE_CONTENT.replace(b'\\', b'')) self.assertEqual(conn.recv_frame().data, MESSAGE_CONTENT.replace(b'\\', b''))
self.assertIn( self.assertIn(
b'\\u001b[32minfo/client\\u001b[0m\\tReceived position of drone 0: %.6f ? %.6f ? %.2f m %.2f m\\n"}' % POSITION_ARRAY_OUTPUT_VALUES, b'\\u001b[32minfo/client\\u001b[0m\\tReceived position of drone 0: %.6f ? %.6f ? %.2f m %.2f m\\n"}' % POSITION_ARRAY_OUTPUT_VALUES,
ws.recv_frame().data, conn.recv_frame().data,
)
self.assertIn(
b'\\u001b[32minfo/client\\u001b[0m\\tReceived speed of drone 0: %.2f ? %.2f m/s %.2f m/s\\n"}' % SPEED_ARRAY_VALUES,
conn.recv_frame().data,
) )
self.assertEqual( self.assertEqual(
ws.recv_frame().data, conn.recv_frame().data,
b''.join(( b''.join((
b'{"drone_dict":{"0":{"latitude":', b'{"drone_dict":{"0":{"latitude":',
b'"%.6f","longitude":"%.6f","altitude":"%.2f",' % POSITION_ARRAY_OUTPUT_VALUES[:-1], b'"%.6f","longitude":"%.6f","altitude":"%.2f",' % POSITION_ARRAY_OUTPUT_VALUES[:-1],
...@@ -352,8 +330,3 @@ class SubscriberTestCase(SlapOSInstanceTestCase): ...@@ -352,8 +330,3 @@ class SubscriberTestCase(SlapOSInstanceTestCase):
b'"timestamp":%d}}}' % POSITION_ARRAY_INPUT_VALUES[-1], b'"timestamp":%d}}}' % POSITION_ARRAY_INPUT_VALUES[-1],
)), )),
) )
self.assertIn(
b'\\u001b[32minfo/client\\u001b[0m\\tReceived speed of drone 0: %.2f ? %.2f m/s %.2f m/s\\n"}' % SPEED_ARRAY_VALUES,
ws.recv_frame().data,
)
ws.close()
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