btest/input/raw: Fix reread test

This seems to have relied on the reading file twice behavior simply
testing that 16 lines are observed. Switch to using two separate
files and doing a system("mv ...") to trigger the REREAD logic, there's
not force_update() needed and it wouldn't do anything if the file
hadn't changed anyway.
This commit is contained in:
Arne Welzel 2023-05-17 21:20:34 +02:00
parent d8b5bdf758
commit 09b956562e
2 changed files with 40 additions and 298 deletions

View file

@ -13,10 +13,16 @@ sdf
3rw43wRRERLlL#RWERERERE.
@TEST-END-FILE
@TEST-START-FILE input2.log
Beginning of input2.log
3rw43wRRERLlL#RWERERERE.
game over
@TEST-END-FILE
redef Threading::heartbeat_interval = 100msec;
redef exit_only_after_terminate = T;
global outfile: file;
global try: count;
module A;
@ -24,13 +30,27 @@ type Val: record {
s: string;
};
event line(description: Input::EventDescription, tpe: Input::Event, s: string)
global end_of_datas = 0;
event Input::end_of_data(name: string, source: string)
{
print outfile, description;
print outfile, tpe;
print outfile, s;
try = try + 1;
if ( try == 16 )
++end_of_datas;
if ( end_of_datas > 1 )
return;
print outfile, "end_of_data, updating input.log";
# This should be recognized by the raw reader as file update (inode change)
# and the new file is reread.
system("mv ../input2.log ../input.log");
}
global lines = 0;
event A::line(description: Input::EventDescription, tpe: Input::Event, s: string)
{
++lines;
print outfile, lines, tpe, s, |s|;
if ( s == "game over" )
{
Input::remove("input");
close(outfile);
@ -40,8 +60,6 @@ event line(description: Input::EventDescription, tpe: Input::Event, s: string)
event zeek_init()
{
try = 0;
outfile = open("../out");
Input::add_event([$source="../input.log", $reader=Input::READER_RAW, $mode=Input::REREAD, $name="input", $fields=Val, $ev=line, $want_record=F]);
Input::force_update("input");
Input::add_event([$source="../input.log", $reader=Input::READER_RAW, $mode=Input::REREAD, $name="input", $fields=Val, $ev=A::line, $want_record=F]);
}