Skip to content

Commit

Permalink
Update tests to consider event timestamps.
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Gras committed Apr 6, 2023
1 parent b99edc6 commit 8745708
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions tests/cpp/zeek.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@ TEST(event) {
zeek::Event ev("test", vector(args));
zeek::Event ev2(std::move(ev));
CHECK_EQUAL(ev2.name(), "test");
CHECK_EQUAL(ev2.ts(), 0);
CHECK_EQUAL(ev2.args(), args);
}

TEST(event_ts) {
auto args = vector{1, "s", port(42, port::protocol::tcp)};
zeek::Event ev("test", 12, vector(args));
zeek::Event ev2(std::move(ev));
CHECK_EQUAL(ev2.name(), "test");
CHECK_EQUAL(ev2.ts(), 12);
CHECK_EQUAL(ev2.args(), args);
}
16 changes: 13 additions & 3 deletions tests/python/zeek.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import broker

from zeek_common import run_zeek_path, run_zeek
from datetime import datetime

ZeekPing = """
redef Broker::default_connect_retry=1secs;
Expand Down Expand Up @@ -45,7 +46,13 @@
event pong(s: string, n: int)
{
send_event(s);
local ts = time_to_double(current_event_time());
if ( ts == 23.0 * n )
send_event(s);
else if ( ts == 0.0 && s == "done" )
send_event(s);
else
send_event(fmt("Unexpected timestamp: %s", ts));
}
"""

Expand All @@ -69,14 +76,17 @@ def test_ping(self):
if i == 5:
expected_arg = expected_arg.encode('utf-8') + b'\x82'

ts_now = datetime.now().timestamp()

self.assertEqual(ev.name(), "ping")
self.assertLess(ts_now - ev.timestamp(), 1.0)
self.assertEqual(s, expected_arg)
self.assertEqual(c, i)

if i < 3:
ev = broker.zeek.Event("pong", s + "X", c)
ev = broker.zeek.Event("pong", s + "X", c, ts=(23.0 * c))
elif i < 5:
ev = broker.zeek.Event("pong", s.encode('utf-8') + b'X', c)
ev = broker.zeek.Event("pong", s.encode('utf-8') + b'X', c, ts=(23.0 * c))
else:
ev = broker.zeek.Event("pong", 'done', c)

Expand Down

0 comments on commit 8745708

Please sign in to comment.