120f2b9fbf
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`. |
||
---|---|---|
.. | ||
.gitignore | ||
chanlogger.go | ||
event.go | ||
eventemitter_test.go | ||
eventemitter.go | ||
experiment_test.go | ||
experiment.go | ||
README.md | ||
runner_integration_test.go | ||
runner_internal_test.go | ||
runner.go | ||
session_integration_test.go | ||
session_test.go | ||
session.go | ||
sessioncontext_test.go | ||
sessioncontext.go | ||
sessionlogger_test.go | ||
sessionlogger.go | ||
settings.go | ||
task_integration_test.go | ||
task.go | ||
uuid_test.go | ||
uuid.go | ||
webconnectivity_integration_test.go | ||
webconnectivity_test.go | ||
webconnectivity.go |
Package github.com/ooni/probe-cli/pkg/oonimkall
Package oonimkall implements APIs used by OONI mobile apps. We expose these APIs to mobile apps using gomobile.
We expose two APIs: the task API, which is derived from the
API originally exposed by Measurement Kit, and the session API,
which is a Go API that mobile apps can use via gomobile
.
This package is named oonimkall because it contains a partial reimplementation of the mkall API implemented by Measurement Kit in, e.g., mkall-ios.
The basic tenet of the task API is that you define an experiment task you wanna run using a JSON, then you start a task for it, and you receive events as serialized JSONs. In addition to this functionality, we also include extra APIs used by OONI mobile.
The basic tenet of the session API is that you create an instance
of Session
and use it to perform the operations you need.