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:
parent
8f7e3803eb
commit
c740be987b
16 changed files with 533 additions and 340 deletions
|
|
@ -10,7 +10,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
// SaverDialer saves events occurring during the dial
|
||||
|
|
@ -52,14 +51,13 @@ func (d *SaverDialer) DialContext(ctx context.Context, network, address string)
|
|||
start := time.Now()
|
||||
conn, err := d.Dialer.DialContext(ctx, network, address)
|
||||
stop := time.Now()
|
||||
d.Saver.Write(Event{
|
||||
d.Saver.Write(&EventConnectOperation{&EventValue{
|
||||
Address: address,
|
||||
Duration: stop.Sub(start),
|
||||
Err: err,
|
||||
Name: netxlite.ConnectOperation,
|
||||
Proto: network,
|
||||
Time: stop,
|
||||
})
|
||||
}})
|
||||
return conn, err
|
||||
}
|
||||
|
||||
|
|
@ -124,14 +122,13 @@ func (c *saverConn) Read(p []byte) (int, error) {
|
|||
start := time.Now()
|
||||
count, err := c.Conn.Read(p)
|
||||
stop := time.Now()
|
||||
c.saver.Write(Event{
|
||||
c.saver.Write(&EventReadOperation{&EventValue{
|
||||
Data: p[:count],
|
||||
Duration: stop.Sub(start),
|
||||
Err: err,
|
||||
NumBytes: count,
|
||||
Name: netxlite.ReadOperation,
|
||||
Time: stop,
|
||||
})
|
||||
}})
|
||||
return count, err
|
||||
}
|
||||
|
||||
|
|
@ -139,14 +136,13 @@ func (c *saverConn) Write(p []byte) (int, error) {
|
|||
start := time.Now()
|
||||
count, err := c.Conn.Write(p)
|
||||
stop := time.Now()
|
||||
c.saver.Write(Event{
|
||||
c.saver.Write(&EventWriteOperation{&EventValue{
|
||||
Data: p[:count],
|
||||
Duration: stop.Sub(start),
|
||||
Err: err,
|
||||
NumBytes: count,
|
||||
Name: netxlite.WriteOperation,
|
||||
Time: stop,
|
||||
})
|
||||
}})
|
||||
return count, err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue