refactor(tracex): do not depend on strings for event names (#777)
Rather than matching a string, match a type. This is more robust considering future refactorings. We're confident the names did not change in _this_ refactoring because we're still testing the same strings in the tests. Part of https://github.com/ooni/probe/issues/2121
This commit is contained in:
@@ -171,8 +171,8 @@ func (r runner) measure(
|
||||
// of the latest connect time. We should have one sample in most
|
||||
// cases, because the connection should be persistent.
|
||||
for _, ev := range r.saver.Read() {
|
||||
if ev.Name == netxlite.ConnectOperation {
|
||||
connectTime = ev.Duration.Seconds()
|
||||
if _, ok := ev.(*tracex.EventConnectOperation); ok {
|
||||
connectTime = ev.Value().Duration.Seconds()
|
||||
}
|
||||
}
|
||||
current.ConnectTime = connectTime
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/mockable"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/tracex"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
func TestRunnerLoopLocateFailure(t *testing.T) {
|
||||
@@ -108,7 +107,7 @@ func TestRunnerLoopMeasureFailure(t *testing.T) {
|
||||
func TestRunnerLoopCollectFailure(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
saver := new(tracex.Saver)
|
||||
saver.Write(tracex.Event{Name: netxlite.ConnectOperation, Duration: 150 * time.Millisecond})
|
||||
saver.Write(&tracex.EventConnectOperation{V: &tracex.EventValue{Duration: 150 * time.Millisecond}})
|
||||
r := runner{
|
||||
callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
httpClient: &http.Client{
|
||||
@@ -152,7 +151,7 @@ func TestRunnerLoopCollectFailure(t *testing.T) {
|
||||
|
||||
func TestRunnerLoopSuccess(t *testing.T) {
|
||||
saver := new(tracex.Saver)
|
||||
saver.Write(tracex.Event{Name: netxlite.ConnectOperation, Duration: 150 * time.Millisecond})
|
||||
saver.Write(&tracex.EventConnectOperation{V: &tracex.EventValue{Duration: 150 * time.Millisecond}})
|
||||
r := runner{
|
||||
callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
httpClient: &http.Client{
|
||||
|
||||
Reference in New Issue
Block a user