A small service builds a summary from an incoming stream of events and publishes the result to a shared counter.
Requirements
build_summary must read all lines from &mut dyn BufRead, build a summary, and return Result<Summary, SummaryError>.
- Each non-empty line has the format
level|message.
- For a line with level
warn, add an entry to warnings; for level info, add an entry to notes.
- If an invalid line or a read error is encountered, the function must return an error and must not change the service counters.
- Updating the shared counter of successful summaries happens only after the summary has been fully and successfully built.
- While parsing the input, the state lock must not be held longer than needed for reading and updating the counter.
Reproduction
- Run the tests for the
src/lib.rs file.
- Pass a stream with one valid line and one
warn|... line.
- Pass a stream with an invalid line, for example:
info|ok
broken-line
- Pass a stream that returns a read error after the first record.
Expected behavior
- For valid input,
Summary is returned with the collected fields.
- For invalid input,
Err is returned.
- For a read error,
Err is returned, and the shared successful-summary counter is not changed.
- After a successful call, the counter increases by exactly
1.
- The state lock does not interfere with repeated calls and does not capture reading the entire stream at once.