-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(minipipeline): reduce generated test cases churn
We add dns.nextdns.io to the QA suite, such that we don't get a wrong NXDOMAIN when trying to use it as the resolver. We optionally sort the test keys to ensure there's less churn in diffs produced when regnerating minipipeline test data. We fix ./script/updateminipipeline.bash to use ./script/go.bash for building as opposed to using go. Closes ooni/probe#2677
- Loading branch information
1 parent
add0707
commit 5e67aac
Showing
206 changed files
with
20,887 additions
and
12,058 deletions.
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
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,121 @@ | ||
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(outputs, 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(outputs, inputs...) | ||
|
||
// sort using complex sorting rule | ||
sort.SliceStable(outputs, func(i, j int) bool { | ||
left, right := outputs[i], outputs[j] | ||
|
||
if left.Address < right.Address { | ||
return true | ||
} | ||
if left.Address > right.Address { | ||
return false | ||
} | ||
|
||
return left.TransactionID < right.TransactionID | ||
}) | ||
|
||
return | ||
} | ||
|
||
// SortTCPConnectResults is like [SortDNSLookupResults] but for TCP connect results. | ||
func SortTCPConnectResults( | ||
inputs []*model.ArchivalTCPConnectResult) (outputs []*model.ArchivalTCPConnectResult) { | ||
// copy the original slice | ||
outputs = append(outputs, inputs...) | ||
|
||
// sort using complex sorting rule | ||
sort.SliceStable(outputs, func(i, j int) bool { | ||
left, right := outputs[i], outputs[j] | ||
|
||
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 | ||
} | ||
|
||
return left.TransactionID < right.TransactionID | ||
}) | ||
|
||
return | ||
} | ||
|
||
// SortTLSHandshakeResults is like [SortDNSLookupResults] but for TLS handshake results. | ||
func SortTLSHandshakeResults( | ||
inputs []*model.ArchivalTLSOrQUICHandshakeResult) (outputs []*model.ArchivalTLSOrQUICHandshakeResult) { | ||
// copy the original slice | ||
outputs = append(outputs, inputs...) | ||
|
||
// sort using complex sorting rule | ||
sort.SliceStable(outputs, func(i, j int) bool { | ||
left, right := outputs[i], outputs[j] | ||
|
||
if left.Address < right.Address { | ||
return true | ||
} | ||
if left.Address > right.Address { | ||
return false | ||
} | ||
|
||
return left.TransactionID < right.TransactionID | ||
}) | ||
|
||
return | ||
} |
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,133 @@ | ||
package minipipeline | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/ooni/probe-cli/v3/internal/model" | ||
) | ||
|
||
func TestSortDNSLookupResults(t *testing.T) { | ||
newfailurestring := func(s string) *string { | ||
return &s | ||
} | ||
|
||
inputGen := func() []*model.ArchivalDNSLookupResult { | ||
return []*model.ArchivalDNSLookupResult{ | ||
{ | ||
Engine: "udp", | ||
Failure: newfailurestring("dns_no_answer"), | ||
QueryType: "AAAA", | ||
ResolverAddress: "1.1.1.1:53", | ||
TransactionID: 5, | ||
}, | ||
{ | ||
Engine: "udp", | ||
Failure: nil, | ||
QueryType: "A", | ||
ResolverAddress: "1.1.1.1:53", | ||
TransactionID: 5, | ||
}, | ||
{ | ||
Engine: "udp", | ||
Failure: newfailurestring("dns_no_answer"), | ||
QueryType: "AAAA", | ||
ResolverAddress: "8.8.8.8:53", | ||
TransactionID: 3, | ||
}, | ||
{ | ||
Engine: "udp", | ||
Failure: nil, | ||
QueryType: "A", | ||
ResolverAddress: "8.8.8.8:53", | ||
TransactionID: 3, | ||
}, | ||
{ | ||
Engine: "doh", | ||
Failure: newfailurestring("dns_no_answer"), | ||
QueryType: "AAAA", | ||
ResolverAddress: "https://dns.google/dns-query", | ||
TransactionID: 2, | ||
}, | ||
{ | ||
Engine: "doh", | ||
Failure: nil, | ||
QueryType: "A", | ||
ResolverAddress: "https://dns.google/dns-query", | ||
TransactionID: 2, | ||
}, | ||
{ | ||
Engine: "getaddrinfo", | ||
QueryType: "ANY", | ||
Failure: nil, | ||
TransactionID: 1, | ||
}, | ||
} | ||
} | ||
|
||
expect := []*model.ArchivalDNSLookupResult{ | ||
{ | ||
Engine: "doh", | ||
Failure: nil, | ||
QueryType: "A", | ||
ResolverAddress: "https://dns.google/dns-query", | ||
TransactionID: 2, | ||
}, | ||
{ | ||
Engine: "doh", | ||
Failure: newfailurestring("dns_no_answer"), | ||
QueryType: "AAAA", | ||
ResolverAddress: "https://dns.google/dns-query", | ||
TransactionID: 2, | ||
}, | ||
{ | ||
Engine: "getaddrinfo", | ||
QueryType: "ANY", | ||
Failure: nil, | ||
TransactionID: 1, | ||
}, | ||
{ | ||
Engine: "udp", | ||
Failure: nil, | ||
QueryType: "A", | ||
ResolverAddress: "8.8.8.8:53", | ||
TransactionID: 3, | ||
}, | ||
{ | ||
Engine: "udp", | ||
Failure: newfailurestring("dns_no_answer"), | ||
QueryType: "AAAA", | ||
ResolverAddress: "8.8.8.8:53", | ||
TransactionID: 3, | ||
}, | ||
{ | ||
Engine: "udp", | ||
Failure: nil, | ||
QueryType: "A", | ||
ResolverAddress: "1.1.1.1:53", | ||
TransactionID: 5, | ||
}, | ||
{ | ||
Engine: "udp", | ||
Failure: newfailurestring("dns_no_answer"), | ||
QueryType: "AAAA", | ||
ResolverAddress: "1.1.1.1:53", | ||
TransactionID: 5, | ||
}, | ||
} | ||
|
||
input := inputGen() | ||
output := SortDNSLookupResults(input) | ||
|
||
t.Run("the input should not have mutated", func(t *testing.T) { | ||
if diff := cmp.Diff(inputGen(), input); diff != "" { | ||
t.Fatal(diff) | ||
} | ||
}) | ||
|
||
t.Run("the output should be consistent with expectations", func(t *testing.T) { | ||
if diff := cmp.Diff(expect, output); diff != "" { | ||
t.Fatal(diff) | ||
} | ||
}) | ||
} |
Oops, something went wrong.