ooni-probe-cli/pkg/oonimkall
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
..
.gitignore refactor: we don't wanna export pkg/oonimkall/tasks (#216) 2021-02-03 19:48:23 +01:00
chanlogger.go [forwardport] refactor(oonimkall): merge internal/task into oonimkall (#617) (#618) 2021-11-26 20:21:42 +01:00
event.go [forwardport] refactor(oonimkall): merge internal/task into oonimkall (#617) (#618) 2021-11-26 20:21:42 +01:00
eventemitter_test.go fix(oonimkall): improve channel management pattern (#621) 2021-12-01 15:40:25 +01:00
eventemitter.go fix(oonimkall): improve channel management pattern (#621) 2021-12-01 15:40:25 +01:00
experiment_test.go refactor: flatten and separate (#353) 2021-06-04 10:34:18 +02:00
experiment.go oonimkall: mobile api for running WebConnectivity (#223) 2021-03-18 08:44:58 +01:00
README.md refactor: start building an Android package (#205) 2021-02-03 10:51:14 +01:00
runner_integration_test.go [forwardport] refactor(oonimkall): merge internal/task into oonimkall (#617) (#618) 2021-11-26 20:21:42 +01:00
runner_internal_test.go fix(oonimkall): improve channel management pattern (#621) 2021-12-01 15:40:25 +01:00
runner.go fix(oonimkall): improve channel management pattern (#621) 2021-12-01 15:40:25 +01:00
session_integration_test.go fix: skip two integration tests in short mode (#451) 2021-09-05 11:58:02 +02:00
session_test.go refactor: start building an Android package (#205) 2021-02-03 10:51:14 +01:00
session.go refactor: flatten and separate (#353) 2021-06-04 10:34:18 +02:00
sessioncontext_test.go refactor: flatten and separate (#353) 2021-06-04 10:34:18 +02:00
sessioncontext.go refactor: start building an Android package (#205) 2021-02-03 10:51:14 +01:00
sessionlogger_test.go refactor: start building an Android package (#205) 2021-02-03 10:51:14 +01:00
sessionlogger.go refactor: start building an Android package (#205) 2021-02-03 10:51:14 +01:00
settings.go [forwardport] refactor(oonimkall): merge internal/task into oonimkall (#617) (#618) 2021-11-26 20:21:42 +01:00
task_integration_test.go fix(oonimkall): improve channel management pattern (#621) 2021-12-01 15:40:25 +01:00
task.go fix(oonimkall): improve channel management pattern (#621) 2021-12-01 15:40:25 +01:00
uuid_test.go refactor: start building an Android package (#205) 2021-02-03 10:51:14 +01:00
uuid.go refactor: start building an Android package (#205) 2021-02-03 10:51:14 +01:00
webconnectivity_integration_test.go oonimkall: mobile api for running WebConnectivity (#223) 2021-03-18 08:44:58 +01:00
webconnectivity_test.go refactor: flatten and separate (#353) 2021-06-04 10:34:18 +02:00
webconnectivity.go refactor: flatten and separate (#353) 2021-06-04 10:34:18 +02:00

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.