ooni-probe-cli/pkg
Simone Basso 120f2b9fbf
fix(oonimkall): improve channel management pattern (#621)
1. add eof channel to event emitter and use this channel as signal
that we shouldn't be sending anymore instead of using a pattern where
we use a timer to decide sending has timed out (because we're using
a buffered channel, it is still possible for some evetns to end up
in the channel if there is space, but this is not a concern, because
the events will be deleted when the channel itself is gone);

2. refactor all tests where we assumed the output channel was closed
to actually use a parallel "eof" channel and use it as signal we
should not be sending anymore (not strictly required but still the
right thing to do in terms of using consistent patterns);

3. modify how we construct a runner so that it passes to the
event emitter an "eof" channel and closes this channel when the
main goroutine running the task is terminating;

4. modify the task to signal events such as "task goroutine started"
and "task goroutine stopped" using channels, which helps to write
much more correct tests;

5. take advantage of the previous change to improve the test that
ensures we're not blocking for a small number of events and also
improve the name of such a test to reflect what it's testing.

The related issue in term of fixing the channel usage pattern is
https://github.com/ooni/probe/issues/1438.

Regarding improving testability, instead, the correct reference
issue is https://github.com/ooni/probe/issues/1903.

There are possibly more changes to apply here to improve this package
and its testability, but let's land this diff first and then see
how much time is left for further improvements.

I've run unit and integration tests with `-race` locally.

This diff will need to be backported to `release/3.11`.
2021-12-01 15:40:25 +01:00
..
oonimkall fix(oonimkall): improve channel management pattern (#621) 2021-12-01 15:40:25 +01:00
.gitignore refactor: move more commands to internal/cmd (#207) 2021-02-03 12:23:15 +01:00
README.md doc: ensure all top dirs have an explanatory README (#214) 2021-02-03 16:54:00 +01:00

Directory github.com/ooni/probe-cli/pkg

This directory contains public Go packages.