Speed up integration tests (#1138)

This commit is contained in:
Tom Limoncelli 2021-05-02 11:25:57 -04:00 committed by GitHub
parent a0bbc66983
commit 68dee3a8c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
"time"
"github.com/StackExchange/dnscontrol/v3/models" "github.com/StackExchange/dnscontrol/v3/models"
"github.com/StackExchange/dnscontrol/v3/pkg/nameservers" "github.com/StackExchange/dnscontrol/v3/pkg/nameservers"
@ -22,6 +23,7 @@ var providerToRun = flag.String("provider", "", "Provider to run")
var startIdx = flag.Int("start", 0, "Test number to begin with") var startIdx = flag.Int("start", 0, "Test number to begin with")
var endIdx = flag.Int("end", 0, "Test index to stop after") var endIdx = flag.Int("end", 0, "Test index to stop after")
var verbose = flag.Bool("verbose", false, "Print corrections as you run them") var verbose = flag.Bool("verbose", false, "Print corrections as you run them")
var printElapsed = flag.Bool("elapsed", false, "Print elapsed time for each testgroup")
func init() { func init() {
testing.Init() testing.Init()
@ -239,6 +241,7 @@ func runTests(t *testing.T, prv providers.DNSServiceProvider, domainName string,
curGroup := -1 curGroup := -1
for gIdx, group := range testGroups { for gIdx, group := range testGroups {
start := time.Now()
// Abide by -start -end flags // Abide by -start -end flags
curGroup++ curGroup++
@ -256,7 +259,9 @@ func runTests(t *testing.T, prv providers.DNSServiceProvider, domainName string,
// Run the tests. // Run the tests.
for _, tst := range group.tests { for _, tst := range group.tests {
makeChanges(t, prv, dc, tst, fmt.Sprintf("%02d:%s", gIdx, group.Desc), true, origConfig) makeChanges(t, prv, dc, tst, fmt.Sprintf("%02d:%s", gIdx, group.Desc), true, origConfig)
if t.Failed() { if t.Failed() {
break break
} }
@ -265,6 +270,11 @@ func runTests(t *testing.T, prv providers.DNSServiceProvider, domainName string,
// Remove all records so next group starts with a clean slate. // Remove all records so next group starts with a clean slate.
makeChanges(t, prv, dc, tc("Empty"), "Post cleanup", false, nil) makeChanges(t, prv, dc, tc("Empty"), "Post cleanup", false, nil)
elapsed := time.Since(start)
if *printElapsed {
fmt.Printf("ELAPSED %02d %7.2f %q\n", gIdx, elapsed.Seconds(), group.Desc)
}
} }
} }
@ -798,8 +808,8 @@ func makeTests(t *testing.T) []*TestGroup {
tc("TXT with 0-octel string", txt("foo1", "")), tc("TXT with 0-octel string", txt("foo1", "")),
// https://github.com/StackExchange/dnscontrol/issues/598 // https://github.com/StackExchange/dnscontrol/issues/598
// RFC1035 permits this, but rarely do provider support it. // RFC1035 permits this, but rarely do provider support it.
clear(), //clear(),
tc("Create a 253-byte TXT", txt("foo253", strings.Repeat("A", 253))), //tc("Create a 253-byte TXT", txt("foo253", strings.Repeat("A", 253))),
clear(), clear(),
tc("Create a 254-byte TXT", txt("foo254", strings.Repeat("B", 254))), tc("Create a 254-byte TXT", txt("foo254", strings.Repeat("B", 254))),
clear(), clear(),
@ -807,8 +817,8 @@ func makeTests(t *testing.T) []*TestGroup {
clear(), clear(),
tc("Create a 256-byte TXT", txt("foo256", strings.Repeat("D", 256))), tc("Create a 256-byte TXT", txt("foo256", strings.Repeat("D", 256))),
clear(), clear(),
tc("Create a 257-byte TXT", txt("foo257", strings.Repeat("E", 257))), //tc("Create a 257-byte TXT", txt("foo257", strings.Repeat("E", 257))),
clear(), //clear(),
tc("Create TXT with single-quote", txt("foosq", "quo'te")), tc("Create TXT with single-quote", txt("foosq", "quo'te")),
clear(), clear(),
tc("Create TXT with backtick", txt("foobt", "blah`blah")), tc("Create TXT with backtick", txt("foobt", "blah`blah")),
@ -816,16 +826,17 @@ func makeTests(t *testing.T) []*TestGroup {
tc("Create TXT with double-quote", txt("foodq", `quo"te`)), tc("Create TXT with double-quote", txt("foodq", `quo"te`)),
clear(), clear(),
tc("Create TXT with ws at end", txt("foows1", "with space at end ")), tc("Create TXT with ws at end", txt("foows1", "with space at end ")),
clear(), gentxt("0"), clear(),
clear(), gentxt("1"), gentxt("0"),
clear(), gentxt("10"), gentxt("1"),
clear(), gentxt("11"), gentxt("10"),
clear(), gentxt("100"), gentxt("11"),
clear(), gentxt("101"), gentxt("100"),
clear(), gentxt("110"), gentxt("101"),
clear(), gentxt("111"), gentxt("110"),
clear(), gentxt("1hh"), gentxt("111"),
clear(), gentxt("1hh0"), gentxt("1hh"),
gentxt("1hh0"),
), ),
testgroup("long TXT", testgroup("long TXT",
@ -875,7 +886,7 @@ func makeTests(t *testing.T) []*TestGroup {
), ),
// Test the ability to change TXT records on the SAME labels accurately. // Test the ability to change TXT records on the SAME labels accurately.
testgroup("TXTMulti", testgroup("TXTMulti-same",
tc("Create TXTMulti 1", tc("Create TXTMulti 1",
txtmulti("foo", []string{"simple"}), txtmulti("foo", []string{"simple"}),
), ),
@ -947,6 +958,8 @@ func makeTests(t *testing.T) []*TestGroup {
"NS1", // Free acct only allows 50 records, therefore we skip "NS1", // Free acct only allows 50 records, therefore we skip
"CLOUDFLAREAPI", // Infinite pagesize but due to slow speed, skipping. "CLOUDFLAREAPI", // Infinite pagesize but due to slow speed, skipping.
"MSDNS", // No paging done. No need to test. "MSDNS", // No paging done. No need to test.
"NAMEDOTCOM", // Their API is so damn slow. We'll add it back as needed.
"GANDI_V5", // Their API is so damn slow. We'll add it back as needed.
), ),
tc("99 records", manyA("rec%04d", "1.2.3.4", 99)...), tc("99 records", manyA("rec%04d", "1.2.3.4", 99)...),
tc("100 records", manyA("rec%04d", "1.2.3.4", 100)...), tc("100 records", manyA("rec%04d", "1.2.3.4", 100)...),