-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(measurexlite): Trace now implements MeasuringNetwork (#1262)
This diff is still yak shaving for ooni/probe#2531 but produces some nice side effects. Now, we can either use netxlite.Netx or measurexlite.Trace as a dependency for measuring code. The cost of this change is (1) switching some functions to use a `model.DebugLogger`, which is not an issue, and (2) adding some optional wrappers to other functions. I made these functions to ignore the wrappers and documented this limitation, because measurexlite code does not need this functionality. It is a bit debateable whether this is the best way to implement this change, but I am doing this because I would like to see these wrappers gone when we stop using legacy/netx in the codebase, so I think it's fine to ignore them, to better signal they're deprecated stuff. This change is absolutely in line with the original spirit of measurexlite because it's now much simpler to write code for netxlite and then upgrade to measurexlite. I noticed this possibility yesterday while working on a much larger diff, and now I am committing this smaller diff to start the working day.
- Loading branch information
1 parent
f837d61
commit 90366e5
Showing
6 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package measurexlite | ||
|
||
import "github.com/ooni/probe-cli/v3/internal/model" | ||
|
||
func (tx *Trace) NewUDPListener() model.UDPListener { | ||
return tx.Netx.NewUDPListener() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package measurexlite | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/ooni/probe-cli/v3/internal/mocks" | ||
"github.com/ooni/probe-cli/v3/internal/model" | ||
) | ||
|
||
func TestNewUDPListener(t *testing.T) { | ||
// Make sure that we're forwarding the call to the measuring network. | ||
expectListener := &mocks.UDPListener{} | ||
trace := NewTrace(0, time.Now()) | ||
trace.Netx = &mocks.MeasuringNetwork{ | ||
MockNewUDPListener: func() model.UDPListener { | ||
return expectListener | ||
}, | ||
} | ||
listener := trace.NewUDPListener() | ||
if listener != expectListener { | ||
t.Fatal("unexpected listener") | ||
} | ||
} |