-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pick up CAF patch for ISO 8601, add new btest #360
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule caf
updated
9 files
+2 −2 | libcaf_core/CMakeLists.txt | |
+159 −0 | libcaf_core/caf/chrono.hpp | |
+1 −0 | libcaf_core/caf/detail/consumer.hpp | |
+4 −37 | libcaf_core/caf/detail/parse.hpp | |
+163 −0 | libcaf_core/caf/detail/parser/read_timestamp.hpp | |
+4 −14 | libcaf_core/caf/detail/print.hpp | |
+290 −0 | libcaf_core/src/chrono.cpp | |
+371 −0 | libcaf_core/test/chrono.cpp | |
+3 −3 | libcaf_core/test/logger.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. | ||
got 21 items | ||
OK: 2020-02-02T02:02:02+00:00 | ||
OK: 2020-02-02T02:02:02.1+00:00 | ||
OK: 2020-02-02T02:02:02.12+00:00 | ||
OK: 2020-02-02T02:02:02.123+00:00 | ||
OK: 2020-02-02T02:02:02.1234+00:00 | ||
OK: 2020-02-02T02:02:02.12345+00:00 | ||
OK: 2020-02-02T02:02:02.123456+00:00 | ||
OK: 2020-02-02T02:02:02+02:00 | ||
OK: 2020-02-02T02:02:02.1+02:00 | ||
OK: 2020-02-02T02:02:02.12+02:00 | ||
OK: 2020-02-02T02:02:02.123+02:00 | ||
OK: 2020-02-02T02:02:02.1234+02:00 | ||
OK: 2020-02-02T02:02:02.12345+02:00 | ||
OK: 2020-02-02T02:02:02.123456+02:00 | ||
OK: 2020-02-02T02:02:02-02:00 | ||
OK: 2020-02-02T02:02:02.1-02:00 | ||
OK: 2020-02-02T02:02:02.12-02:00 | ||
OK: 2020-02-02T02:02:02.123-02:00 | ||
OK: 2020-02-02T02:02:02.1234-02:00 | ||
OK: 2020-02-02T02:02:02.12345-02:00 | ||
OK: 2020-02-02T02:02:02.123456-02:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,286 @@ | ||
# @TEST-GROUP: web-socket | ||
# | ||
# @TEST-PORT: BROKER_WEB_SOCKET_PORT | ||
# | ||
# @TEST-EXEC: btest-bg-run node "broker-node --config-file=../node.cfg" | ||
# @TEST-EXEC: btest-bg-run recv "python3 ../recv.py >recv.out" | ||
# @TEST-EXEC: $SCRIPTS/wait-for-file recv/ready 15 || (btest-bg-wait -k 1 && false) | ||
# | ||
# @TEST-EXEC: btest-bg-run send "python3 ../send.py" | ||
# | ||
# @TEST-EXEC: $SCRIPTS/wait-for-file recv/done 30 || (btest-bg-wait -k 1 && false) | ||
# @TEST-EXEC: btest-diff recv/recv.out | ||
# | ||
# @TEST-EXEC: btest-bg-wait -k 1 | ||
|
||
@TEST-START-FILE node.cfg | ||
|
||
broker { | ||
disable-ssl = true | ||
} | ||
topics = ["/test"] | ||
verbose = true | ||
|
||
@TEST-END-FILE | ||
|
||
@TEST-START-FILE recv.py | ||
|
||
import asyncio, websockets, os, time, json, sys, re | ||
|
||
|
||
from datetime import datetime | ||
|
||
ws_port = os.environ['BROKER_WEB_SOCKET_PORT'].split('/')[0] | ||
|
||
ws_url = f'ws://localhost:{ws_port}/v1/messages/json' | ||
|
||
# Expected timestamps in the message. | ||
timestamps = [ | ||
# using UTC (note: 'Z' is not supported on older Python versions) | ||
'2020-02-02T02:02:02+00:00', | ||
'2020-02-02T02:02:02.1+00:00', | ||
'2020-02-02T02:02:02.12+00:00', | ||
'2020-02-02T02:02:02.123+00:00', | ||
'2020-02-02T02:02:02.1234+00:00', | ||
'2020-02-02T02:02:02.12345+00:00', | ||
'2020-02-02T02:02:02.123456+00:00', | ||
# using positive offset from UTC | ||
'2020-02-02T02:02:02+02:00', | ||
'2020-02-02T02:02:02.1+02:00', | ||
'2020-02-02T02:02:02.12+02:00', | ||
'2020-02-02T02:02:02.123+02:00', | ||
'2020-02-02T02:02:02.1234+02:00', | ||
'2020-02-02T02:02:02.12345+02:00', | ||
'2020-02-02T02:02:02.123456+02:00', | ||
# using negative offset from UTC | ||
'2020-02-02T02:02:02-02:00', | ||
'2020-02-02T02:02:02.1-02:00', | ||
'2020-02-02T02:02:02.12-02:00', | ||
'2020-02-02T02:02:02.123-02:00', | ||
'2020-02-02T02:02:02.1234-02:00', | ||
'2020-02-02T02:02:02.12345-02:00', | ||
'2020-02-02T02:02:02.123456-02:00', | ||
] | ||
|
||
# tells btest we're done by writing a file | ||
def write_done_file(): | ||
with open('done', 'w') as f: | ||
f.write('done') | ||
|
||
def parse_iso_timestamp(timestamp): | ||
# replace 'Z' and adjust offset format from '[+-]MM:SS' to '[+-]MMSS' | ||
# (note: Python versions >= 3.7 don't need this) | ||
timestamp = timestamp.replace('Z', '+0000') | ||
timestamp = re.sub(r'([+-]\d{2}):(\d{2})', r'\1\2', timestamp) | ||
# parse with or without fractional seconds | ||
formats = ["%Y-%m-%dT%H:%M:%S%z", "%Y-%m-%dT%H:%M:%S.%f%z"] | ||
for format in formats: | ||
try: | ||
dt = datetime.strptime(timestamp, format) | ||
return dt | ||
except ValueError: | ||
pass | ||
raise ValueError(f'failed to parse {timestamp}') | ||
|
||
def check_msg(msg): | ||
try: | ||
# iterate over the message and compare it to the expected values | ||
if msg['@data-type'] != 'vector': | ||
raise RuntimeError(f'unexpected data type for the message: {msg["@data-type"]}') | ||
items = msg['data'] | ||
num_items = len(items) | ||
if num_items != len(timestamps): | ||
raise RuntimeError(f'unexpected number of items: {len(items)} != {len(timestamps)}') | ||
print(f'got {num_items} items') | ||
for i in range(num_items): | ||
item = items[i] | ||
if item['@data-type'] != 'timestamp': | ||
raise RuntimeError(f'unexpected data type at index {i}: {item["@data-type"]} != timestamp') | ||
dt1 = parse_iso_timestamp(item['data']) | ||
dt2 = parse_iso_timestamp(timestamps[i]) | ||
if dt1 != dt2: | ||
raise RuntimeError(f'unexpected timestamp at index {i}: {item["data"]} != {timestamps[i]}') | ||
print(f'OK: {timestamps[i]}') | ||
except Exception as e: | ||
print(f'*** {e}') | ||
|
||
async def do_run(): | ||
# Try up to 30 times. | ||
connected = False | ||
for i in range(30): | ||
try: | ||
ws = await websockets.connect(ws_url) | ||
connected = True | ||
# send filter and wait for ack | ||
await ws.send('["/test"]') | ||
ack_json = await ws.recv() | ||
ack = json.loads(ack_json) | ||
if not 'type' in ack or ack['type'] != 'ack': | ||
print('*** unexpected ACK from server:') | ||
print(ack_json) | ||
sys.exit() | ||
# tell btest to start the sender now | ||
with open('ready', 'w') as f: | ||
f.write('ready') | ||
# get and verify the message | ||
msg_json = await ws.recv() | ||
msg = json.loads(msg_json) | ||
check_msg(msg) | ||
# tell btest we're done | ||
write_done_file() | ||
await ws.close() | ||
sys.exit() | ||
except: | ||
if not connected: | ||
print(f'failed to connect to {ws_url}, try again', file=sys.stderr) | ||
time.sleep(1) | ||
else: | ||
write_done_file() | ||
sys.exit() | ||
|
||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(do_run()) | ||
|
||
@TEST-END-FILE | ||
|
||
@TEST-START-FILE send.py | ||
|
||
import asyncio, websockets, os, json, sys | ||
|
||
ws_port = os.environ['BROKER_WEB_SOCKET_PORT'].split('/')[0] | ||
|
||
ws_url = f'ws://localhost:{ws_port}/v1/messages/json' | ||
|
||
# Message with timestamps using the local time zone. | ||
msg = { | ||
'type': 'data-message', | ||
'topic': '/test', | ||
'@data-type': "vector", | ||
'data': [ | ||
# UTC timestamps | ||
|
||
# timestamp without fractional seconds | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02Z" | ||
}, | ||
# timestamp with fractional seconds (1 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.1Z" | ||
}, | ||
# timestamp with fractional seconds (2 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.12Z" | ||
}, | ||
# timestamp with fractional seconds (3 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.123Z" | ||
}, | ||
# timestamp with fractional seconds (4 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.1234Z" | ||
}, | ||
# timestamp with fractional seconds (5 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.12345Z" | ||
}, | ||
# timestamp with fractional seconds (6 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.123456Z" | ||
}, | ||
|
||
# timestamps that use a positive offset from UTC. | ||
|
||
# timestamp without fractional seconds | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02+02" | ||
}, | ||
# timestamp with fractional seconds (1 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.1+0200" | ||
}, | ||
# timestamp with fractional seconds (2 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.12+02:00" | ||
}, | ||
# timestamp with fractional seconds (3 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.123+02:00" | ||
}, | ||
# timestamp with fractional seconds (4 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.1234+02:00" | ||
}, | ||
# timestamp with fractional seconds (5 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.12345+02:00" | ||
}, | ||
# timestamp with fractional seconds (6 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.123456+02:00" | ||
}, | ||
|
||
# timestamps that use a negative offset from UTC. | ||
|
||
# timestamp without fractional seconds | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02-02" | ||
}, | ||
# timestamp with fractional seconds (1 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.1-0200" | ||
}, | ||
# timestamp with fractional seconds (2 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.12-02:00" | ||
}, | ||
# timestamp with fractional seconds (3 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.123-02:00" | ||
}, | ||
# timestamp with fractional seconds (4 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.1234-02:00" | ||
}, | ||
# timestamp with fractional seconds (5 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.12345-02:00" | ||
}, | ||
# timestamp with fractional seconds (6 digit) | ||
{ | ||
'@data-type': "timestamp", | ||
"data": "2020-02-02T02:02:02.123456-02:00" | ||
}, | ||
], | ||
} | ||
|
||
async def do_run(): | ||
async with websockets.connect(ws_url) as ws: | ||
await ws.send('[]') | ||
await ws.recv() # wait for ACK | ||
await ws.send(json.dumps(msg)) | ||
await ws.close() | ||
|
||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(do_run()) | ||
|
||
@TEST-END-FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following up on our earlier conversation Dominik: you can safely assume 3.7+. We bumped our minimum requirement a while back, see here.
I'm about to submit a round of CI updates since Broker's setup has fallen behind compared to Zeek
master
and I believe at least the (EOL'd) Ubuntu 18.04 that's currently still configured ran Python 3.6.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it's not that easy: zeek/zeek#3239