feat(tunnel): introduce persistent tunnel state dir (#294)

* feat(tunnel): introduce persistent tunnel state dir

This diff introduces a persistent state directory for tunnels, so that
we can bootstrap them more quickly after the first time.

Part of https://github.com/ooni/probe/issues/985

* fix: make tunnel dir optional

We have many tests where it does not make sense to explicitly
provide a tunnel dir because we're not using tunnels.

This should simplify setting up a session.

* fix(tunnel): repair tests

* final changes

* more cleanups
This commit is contained in:
Simone Basso 2021-04-05 11:27:41 +02:00 committed by GitHub
commit 8fe4e5410d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 166 additions and 105 deletions

View file

@ -11,19 +11,23 @@ import (
)
func TestPsiphonStartWithCancelledContext(t *testing.T) {
// TODO(bassosimone): this test can use a mockable session so we
// can move it inside of the internal tests.
ctx, cancel := context.WithCancel(context.Background())
cancel()
cancel() // fail immediately
sess, err := engine.NewSession(engine.SessionConfig{
Logger: log.Log,
SoftwareName: "ooniprobe-engine",
SoftwareVersion: "0.0.1",
SoftwareName: "miniooni",
SoftwareVersion: "0.1.0-dev",
TunnelDir: "testdata",
})
if err != nil {
t.Fatal(err)
}
tunnel, err := tunnel.Start(ctx, &tunnel.Config{
Name: "psiphon",
Session: sess,
Name: "psiphon",
Session: sess,
TunnelDir: "testdata",
})
if !errors.Is(err, context.Canceled) {
t.Fatal("not the error we expected")
@ -41,13 +45,15 @@ func TestPsiphonStartStop(t *testing.T) {
Logger: log.Log,
SoftwareName: "ooniprobe-engine",
SoftwareVersion: "0.0.1",
TunnelDir: "testdata",
})
if err != nil {
t.Fatal(err)
}
tunnel, err := tunnel.Start(context.Background(), &tunnel.Config{
Name: "psiphon",
Session: sess,
Name: "psiphon",
Session: sess,
TunnelDir: "testdata",
})
if err != nil {
t.Fatal(err)