feat: dnsping using step-by-step (#831)

Reference issue for this pull request: https://github.com/ooni/probe/issues/2159

This diff refactors the `dnsping` experiment to use the [step-by-step measurement style](https://github.com/ooni/probe-cli/blob/master/docs/design/dd-003-step-by-step.md).

Co-authored-by: decfox <decfox@github.com>
Co-authored-by: Simone Basso <bassosimone@gmail.com>
This commit is contained in:
DecFox
2022-07-08 23:12:24 +05:30
committed by GitHub
parent 8aad36a257
commit 5501b2201a
16 changed files with 747 additions and 77 deletions
+8
View File
@@ -15,6 +15,9 @@ import (
type Trace struct {
MockTimeNow func() time.Time
MockOnDNSRoundTripForLookupHost func(started time.Time, reso model.Resolver, query model.DNSQuery,
response model.DNSResponse, addrs []string, err error, finished time.Time)
MockOnConnectDone func(
started time.Time, network, domain, remoteAddr string, err error, finished time.Time)
@@ -30,6 +33,11 @@ func (t *Trace) TimeNow() time.Time {
return t.MockTimeNow()
}
func (t *Trace) OnDNSRoundTripForLookupHost(started time.Time, reso model.Resolver, query model.DNSQuery,
response model.DNSResponse, addrs []string, err error, finished time.Time) {
t.MockOnDNSRoundTripForLookupHost(started, reso, query, response, addrs, err, finished)
}
func (t *Trace) OnConnectDone(
started time.Time, network, domain, remoteAddr string, err error, finished time.Time) {
t.MockOnConnectDone(started, network, domain, remoteAddr, err, finished)
+24
View File
@@ -4,6 +4,8 @@ import (
"crypto/tls"
"testing"
"time"
"github.com/ooni/probe-cli/v3/internal/model"
)
func TestTrace(t *testing.T) {
@@ -19,6 +21,28 @@ func TestTrace(t *testing.T) {
}
})
t.Run("OnDNSRoundTripForLookupHost", func(t *testing.T) {
var called bool
tx := &Trace{
MockOnDNSRoundTripForLookupHost: func(started time.Time, reso model.Resolver, query model.DNSQuery,
response model.DNSResponse, addrs []string, err error, finished time.Time) {
called = true
},
}
tx.OnDNSRoundTripForLookupHost(
time.Now(),
&Resolver{},
&DNSQuery{},
&DNSResponse{},
[]string{},
nil,
time.Now(),
)
if !called {
t.Fatal("not called")
}
})
t.Run("OnConnectDone", func(t *testing.T) {
var called bool
tx := &Trace{