-
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e67aac
fix(minipipeline): reduce generated test cases churn
bassosimone 48cddf1
x
bassosimone c86ed33
Update internal/minipipeline/sorting.go
bassosimone fb4156c
x
bassosimone 09efdc0
Merge branch 'issue/2677' of github.com:ooni/probe-cli into issue/2677
bassosimone 650d5d0
x
bassosimone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -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 | ||
} | ||
|
||
|
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,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 | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We don't need this function because we set the field after all measurements have completed.