-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(qatool): reduce generated test cases churn #1505
Changes from 5 commits
5e67aac
48cddf1
c86ed33
fb4156c
09efdc0
650d5d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,8 +253,16 @@ func (t *CleartextFlow) httpTransaction(ctx context.Context, network, address, a | |
|
||
// Implementation note: we want to emit http_transaction_start when we actually start doing | ||
// HTTP things such that it's possible to correctly classify network events | ||
t.TestKeys.AppendNetworkEvents(measurexlite.NewAnnotationArchivalNetworkEvent( | ||
trace.Index(), started, "http_transaction_start", trace.Tags()..., | ||
t.TestKeys.AppendNetworkEvents(measurexlite.NewArchivalNetworkEvent( | ||
trace.Index(), | ||
started, | ||
"http_transaction_start", | ||
network, | ||
address, | ||
0, | ||
nil, | ||
started, | ||
trace.Tags()..., | ||
)) | ||
|
||
resp, err := txp.RoundTrip(req) | ||
|
@@ -272,8 +280,16 @@ func (t *CleartextFlow) httpTransaction(ctx context.Context, network, address, a | |
} | ||
|
||
finished := trace.TimeSince(trace.ZeroTime()) | ||
t.TestKeys.AppendNetworkEvents(measurexlite.NewAnnotationArchivalNetworkEvent( | ||
trace.Index(), finished, "http_transaction_done", trace.Tags()..., | ||
t.TestKeys.AppendNetworkEvents(measurexlite.NewArchivalNetworkEvent( | ||
trace.Index(), | ||
finished, | ||
"http_transaction_done", | ||
network, | ||
address, | ||
0, | ||
nil, | ||
finished, | ||
trace.Tags()..., | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is such that we have the endpoints in this event (because... why not? It helps with sorting and I don't see why omitting a piece of information we know would ever be wrong). |
||
)) | ||
|
||
ev := measurexlite.NewArchivalHTTPRequestResult( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,8 +308,16 @@ func (t *SecureFlow) httpTransaction(ctx context.Context, network, address, alpn | |
|
||
// Implementation note: we want to emit http_transaction_start when we actually start doing | ||
// HTTP things such that it's possible to correctly classify network events | ||
t.TestKeys.AppendNetworkEvents(measurexlite.NewAnnotationArchivalNetworkEvent( | ||
trace.Index(), started, "http_transaction_start", trace.Tags()..., | ||
t.TestKeys.AppendNetworkEvents(measurexlite.NewArchivalNetworkEvent( | ||
trace.Index(), | ||
started, | ||
"http_transaction_start", | ||
network, | ||
address, | ||
0, | ||
nil, | ||
started, | ||
trace.Tags()..., | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is such that we have the endpoints in this event (because... why not? It helps with sorting and I don't see why omitting a piece of information we know would ever be wrong). |
||
)) | ||
|
||
resp, err := txp.RoundTrip(req) | ||
|
@@ -327,8 +335,16 @@ func (t *SecureFlow) httpTransaction(ctx context.Context, network, address, alpn | |
} | ||
|
||
finished := trace.TimeSince(trace.ZeroTime()) | ||
t.TestKeys.AppendNetworkEvents(measurexlite.NewAnnotationArchivalNetworkEvent( | ||
trace.Index(), finished, "http_transaction_done", trace.Tags()..., | ||
t.TestKeys.AppendNetworkEvents(measurexlite.NewArchivalNetworkEvent( | ||
trace.Index(), | ||
finished, | ||
"http_transaction_done", | ||
network, | ||
address, | ||
0, | ||
nil, | ||
finished, | ||
trace.Tags()..., | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is such that we have the endpoints in this event (because... why not? It helps with sorting and I don't see why omitting a piece of information we know would ever be wrong). |
||
)) | ||
|
||
ev := measurexlite.NewArchivalHTTPRequestResult( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,13 +291,6 @@ func (tk *TestKeys) WithDNSWhoami(fun func(*DNSWhoamiInfo)) { | |
tk.mu.Unlock() | ||
} | ||
|
||
// SetClientResolver sets the ClientResolver field. | ||
func (tk *TestKeys) SetClientResolver(value string) { | ||
tk.mu.Lock() | ||
tk.ClientResolver = value | ||
tk.mu.Unlock() | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this function because we set the field after all measurements have completed. |
||
// AppendConnPriorityLogEntry appends an entry to ConnPriorityLog. | ||
func (tk *TestKeys) AppendConnPriorityLogEntry(entry *ConnPriorityLogEntry) { | ||
tk.mu.Lock() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,17 @@ func (thx *tlsHandshakerTrace) Handshake( | |
func (tx *Trace) OnTLSHandshakeStart(now time.Time, remoteAddr string, config *tls.Config) { | ||
t := now.Sub(tx.ZeroTime()) | ||
select { | ||
case tx.networkEvent <- NewAnnotationArchivalNetworkEvent( | ||
tx.Index(), t, "tls_handshake_start", tx.tags...): | ||
case tx.networkEvent <- NewArchivalNetworkEvent( | ||
tx.Index(), | ||
t, | ||
"tls_handshake_start", | ||
"tcp", | ||
remoteAddr, | ||
0, | ||
nil, | ||
t, | ||
tx.tags..., | ||
): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is such that we have the endpoints in this event (because... why not? It helps with sorting and I don't see why omitting a piece of information we know would ever be wrong). |
||
default: // buffer is full | ||
} | ||
} | ||
|
@@ -70,8 +79,17 @@ func (tx *Trace) OnTLSHandshakeDone(started time.Time, remoteAddr string, config | |
} | ||
|
||
select { | ||
case tx.networkEvent <- NewAnnotationArchivalNetworkEvent( | ||
tx.Index(), t, "tls_handshake_done", tx.tags...): | ||
case tx.networkEvent <- NewArchivalNetworkEvent( | ||
tx.Index(), | ||
t, | ||
"tls_handshake_done", | ||
"tcp", | ||
remoteAddr, | ||
0, | ||
nil, | ||
t, | ||
tx.tags..., | ||
): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is such that we have the endpoints in this event (because... why not? It helps with sorting and I don't see why omitting a piece of information we know would ever be wrong). |
||
default: // buffer is full | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,21 +51,23 @@ func NewLinearWebAnalysis(input *WebObservationsContainer) (output []*WebObserva | |
output = append(output, entry) | ||
} | ||
|
||
// sort in descending order | ||
// sort using complex sorting rule | ||
sort.SliceStable(output, func(i, j int) bool { | ||
left, right := output[i], output[j] | ||
|
||
// We use -1 as the default value such that observations with undefined | ||
// TagDepth sort at the end of the generated list. | ||
if left.TagDepth.UnwrapOr(-1) > right.TagDepth.UnwrapOr(-1) { | ||
return true | ||
} else if left.TagDepth.UnwrapOr(-1) < right.TagDepth.UnwrapOr(-1) { | ||
} | ||
if left.TagDepth.UnwrapOr(-1) < right.TagDepth.UnwrapOr(-1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We prefer a coding style without |
||
return false | ||
} | ||
|
||
if left.Type > right.Type { | ||
return true | ||
} else if left.Type < right.Type { | ||
} | ||
if left.Type < right.Type { | ||
return false | ||
} | ||
|
||
|
@@ -74,7 +76,8 @@ func NewLinearWebAnalysis(input *WebObservationsContainer) (output []*WebObserva | |
const defaultFailureValue = "unknown_failure" | ||
if left.Failure.UnwrapOr(defaultFailureValue) < right.Failure.UnwrapOr(defaultFailureValue) { | ||
return true | ||
} else if left.Failure.UnwrapOr(defaultFailureValue) > right.Failure.UnwrapOr(defaultFailureValue) { | ||
} | ||
if left.Failure.UnwrapOr(defaultFailureValue) > right.Failure.UnwrapOr(defaultFailureValue) { | ||
return false | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package minipipeline | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/ooni/probe-cli/v3/internal/model" | ||
) | ||
|
||
// SortDNSLookupResults sorts and returns a copy of the DNS lookup results to avoid too-much | ||
// timing dependent churn when generating testcases for the minipipeline. | ||
func SortDNSLookupResults(inputs []*model.ArchivalDNSLookupResult) (outputs []*model.ArchivalDNSLookupResult) { | ||
// copy the original slice | ||
outputs = append([]*model.ArchivalDNSLookupResult{}, inputs...) | ||
|
||
// sort using complex sorting rule | ||
sort.SliceStable(outputs, func(i, j int) bool { | ||
left, right := outputs[i], outputs[j] | ||
|
||
// we sort groups by resolver type to avoid the churn caused by parallel runs | ||
if left.Engine < right.Engine { | ||
return true | ||
} | ||
if left.Engine > right.Engine { | ||
return false | ||
} | ||
|
||
// within the same group, we sort by ascending transaction ID | ||
if left.TransactionID < right.TransactionID { | ||
return true | ||
} | ||
if left.TransactionID > right.TransactionID { | ||
return false | ||
} | ||
|
||
// we want entries that are successful to appear first | ||
fsget := func(value *string) string { | ||
if value == nil { | ||
return "" | ||
} | ||
return *value | ||
} | ||
return fsget(left.Failure) < fsget(right.Failure) | ||
}) | ||
|
||
return | ||
} | ||
|
||
// SortNetworkEvents is like [SortDNSLookupResults] but for network events. | ||
func SortNetworkEvents(inputs []*model.ArchivalNetworkEvent) (outputs []*model.ArchivalNetworkEvent) { | ||
// copy the original slice | ||
outputs = append([]*model.ArchivalNetworkEvent{}, inputs...) | ||
|
||
// sort using complex sorting rule | ||
sort.SliceStable(outputs, func(i, j int) bool { | ||
left, right := outputs[i], outputs[j] | ||
|
||
// we sort by endpoint address to significantly reduce the churn | ||
if left.Address < right.Address { | ||
return true | ||
} | ||
if left.Address > right.Address { | ||
return false | ||
} | ||
|
||
// if the address is the same, then we group by transaction | ||
if left.TransactionID < right.TransactionID { | ||
return true | ||
} | ||
if left.TransactionID > right.TransactionID { | ||
return false | ||
} | ||
|
||
// with same transaction, we sort by increasing time | ||
return left.T < right.T | ||
}) | ||
|
||
return | ||
} | ||
|
||
// SortTCPConnectResults is like [SortDNSLookupResults] but for TCP connect results. | ||
func SortTCPConnectResults( | ||
inputs []*model.ArchivalTCPConnectResult) (outputs []*model.ArchivalTCPConnectResult) { | ||
// copy the original slice | ||
outputs = append([]*model.ArchivalTCPConnectResult{}, inputs...) | ||
|
||
// sort using complex sorting rule | ||
sort.SliceStable(outputs, func(i, j int) bool { | ||
left, right := outputs[i], outputs[j] | ||
|
||
// we sort by endpoint address to significantly reduce the churn | ||
if left.IP < right.IP { | ||
return true | ||
} | ||
if left.IP > right.IP { | ||
return false | ||
} | ||
if left.Port < right.Port { | ||
return true | ||
} | ||
if left.Port > right.Port { | ||
return false | ||
} | ||
|
||
// if the address is the same, then we group by transaction | ||
if left.TransactionID < right.TransactionID { | ||
return true | ||
} | ||
if left.TransactionID > right.TransactionID { | ||
return false | ||
} | ||
|
||
// with same transaction, we sort by increasing time | ||
return left.T < right.T | ||
}) | ||
|
||
return | ||
} | ||
|
||
// SortTLSHandshakeResults is like [SortDNSLookupResults] but for TLS handshake results. | ||
func SortTLSHandshakeResults( | ||
inputs []*model.ArchivalTLSOrQUICHandshakeResult) (outputs []*model.ArchivalTLSOrQUICHandshakeResult) { | ||
// copy the original slice | ||
outputs = append([]*model.ArchivalTLSOrQUICHandshakeResult{}, inputs...) | ||
|
||
// sort using complex sorting rule | ||
sort.SliceStable(outputs, func(i, j int) bool { | ||
left, right := outputs[i], outputs[j] | ||
|
||
// we sort by endpoint address to significantly reduce the churn | ||
if left.Address < right.Address { | ||
bassosimone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return true | ||
} | ||
if left.Address > right.Address { | ||
return false | ||
} | ||
|
||
// if the address is the same, then we group by transaction | ||
if left.TransactionID < right.TransactionID { | ||
return true | ||
} | ||
if left.TransactionID > right.TransactionID { | ||
return false | ||
} | ||
|
||
// with same transaction, we sort by increasing time | ||
return left.T < right.T | ||
}) | ||
|
||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is such that we have the endpoints in this event (because... why not? It helps with sorting and I don't see why omitting a piece of information we know would ever be wrong).