From 0972548c138cce837f5ae55f2ed4b67ff8ffc5d5 Mon Sep 17 00:00:00 2001 From: Gary <982483+gmalouf@users.noreply.github.com> Date: Tue, 26 Sep 2023 18:03:50 -0400 Subject: [PATCH] tests: Address flakiness with TestMergePrimarySecondaryRelayAddressListsPartialOverlap (#5758) --- network/wsNetwork_test.go | 107 ++++++++++--------------- tools/network/dnssec/config_windows.go | 2 +- 2 files changed, 42 insertions(+), 67 deletions(-) diff --git a/network/wsNetwork_test.go b/network/wsNetwork_test.go index 31a4144dc0..8159b6a898 100644 --- a/network/wsNetwork_test.go +++ b/network/wsNetwork_test.go @@ -4351,85 +4351,60 @@ func TestMergePrimarySecondaryRelayAddressListsMinOverlap(t *testing.T) { }) } -type MergeTestDNSInputs struct { - dedupExpStr string - - primaryDomainSuffix string - - secondaryDomainSuffix string -} - -func mergePrimarySecondaryRelayAddressListsPartialOverlapTestInputsGen() *rapid.Generator[*MergeTestDNSInputs] { - - algorandNetBase := rapid.Custom(func(t *rapid.T) *MergeTestDNSInputs { - //unused/satisfying rapid expectation - rapid.String().Draw(t, "algorandNetBase") - //.algorand.network?backup=.algorand.net - // dedup=.algorand-.(network|net) - return &MergeTestDNSInputs{ - dedupExpStr: "(algorand-.(network|net))", - primaryDomainSuffix: "algorand-.network", - secondaryDomainSuffix: "algorand-.net", - } - }) - - algorandNetInverse := rapid.Custom(func(t *rapid.T) *MergeTestDNSInputs { - //unused/satisfying rapid expectation - rapid.String().Draw(t, "algorandNetInverse") - //.algorand.net?backup=.algorand.network" + - // "&dedup=.algorand-.(network|net) - return &MergeTestDNSInputs{ - dedupExpStr: "(algorand-.(network|net))", - primaryDomainSuffix: "algorand-.net", - secondaryDomainSuffix: "algorand-.network", - } - }) - - return rapid.OneOf(algorandNetBase, algorandNetInverse) +func alphaNumStr(n int) string { + var chars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0987654321") + str := make([]rune, n) + for i := range str { + str[i] = chars[rand.Intn(len(chars))] + } + return string(str) } func TestMergePrimarySecondaryRelayAddressListsPartialOverlap(t *testing.T) { partitiontest.PartitionTest(t) - var netA *WebsocketNetwork - - rapid.Check(t, func(t1 *rapid.T) { - netA = makeTestWebsocketNode(t) - network := supportedNetworkGen().Draw(t1, "network") - mergeTestInputs := mergePrimarySecondaryRelayAddressListsPartialOverlapTestInputsGen().Draw(t1, "mergeTestInputs") + networks := []protocol.NetworkID{config.Testnet, config.Mainnet, config.Devnet, config.Betanet, + config.Alphanet, config.Devtestnet} + var netA *WebsocketNetwork + for _, network := range networks { dedupExp := regexp.MustCompile(strings.Replace( - mergeTestInputs.dedupExpStr, "", network, -1)) - primaryDomainSuffix := strings.Replace( - mergeTestInputs.primaryDomainSuffix, "", network, -1) - - // Generate hosts for a primary network domain - primaryNetworkDomainGen := rapidgen.DomainWithSuffixAndPort(primaryDomainSuffix, nil) - primaryDomainsGen := rapid.SliceOfN(primaryNetworkDomainGen, 0, 200) - - primaryRelayAddresses := primaryDomainsGen.Draw(t1, "primaryRelayAddresses") - - secondaryDomainSuffix := strings.Replace( - mergeTestInputs.secondaryDomainSuffix, "", network, -1) - // Generate these addresses from primary ones, find/replace domain suffix appropriately - secondaryRelayAddresses := replaceAllIn(primaryRelayAddresses, primaryDomainSuffix, secondaryDomainSuffix) - // Add some generated addresses to secondary list - to simplify verification further down - // (substituting suffixes, etc), we dont want the generated addresses to duplicate any of - // the replaced secondary ones - secondaryNetworkDomainGen := rapidgen.DomainWithSuffixAndPort(secondaryDomainSuffix, secondaryRelayAddresses) - secondaryDomainsGen := rapid.SliceOfN(secondaryNetworkDomainGen, 0, 200) - generatedSecondaryRelayAddresses := secondaryDomainsGen.Draw(t1, "secondaryRelayAddresses") - secondaryRelayAddresses = append(secondaryRelayAddresses, generatedSecondaryRelayAddresses...) + "(algorand-.(network|net))", "", string(network), -1)) + primaryRelayAddresses := make([]string, 0) + secondaryRelayAddresses := make([]string, 0) + extraSecondaryRelayAddresses := make([]string, 0) + for i := 0; i < 100; i++ { + relayID := alphaNumStr(2) + primaryRelayAddresses = append(primaryRelayAddresses, fmt.Sprintf("r-%s.algorand-%s.network", + relayID, network)) + secondaryRelayAddresses = append(secondaryRelayAddresses, fmt.Sprintf("r-%s.algorand-%s.net", + relayID, network)) + } + for i := 0; i < 20; i++ { + relayID := alphaNumStr(2) + "-" + alphaNumStr(1) + primaryRelayAddresses = append(primaryRelayAddresses, fmt.Sprintf("relay-%s.algorand-%s.network", + relayID, network)) + secondaryRelayAddresses = append(secondaryRelayAddresses, fmt.Sprintf("relay-%s.algorand-%s.net", + relayID, network)) + } + // Add additional secondary ones that intentionally do not duplicate primary ones + for i := 0; i < 10; i++ { + relayID := alphaNumStr(2) + "-" + alphaNumStr(1) + extraSecondaryRelayAddresses = append(extraSecondaryRelayAddresses, fmt.Sprintf("noduprelay-%s.algorand-%s.net", + relayID, network)) + } + secondaryRelayAddresses = append(secondaryRelayAddresses, extraSecondaryRelayAddresses...) - mergedRelayAddresses := netA.mergePrimarySecondaryRelayAddressSlices(protocol.NetworkID(network), + mergedRelayAddresses := netA.mergePrimarySecondaryRelayAddressSlices(network, primaryRelayAddresses, secondaryRelayAddresses, dedupExp) - // We expect the primary addresses to take precedence over a "matching" secondary address, randomly generated + // We expect the primary addresses to take precedence over a "matching" secondary address, extra non-duplicate // secondary addresses should be present in the merged slice - expectedRelayAddresses := removeDuplicateStr(append(primaryRelayAddresses, generatedSecondaryRelayAddresses...), true) + expectedRelayAddresses := removeDuplicateStr(append(primaryRelayAddresses, extraSecondaryRelayAddresses...), true) assert.ElementsMatch(t, expectedRelayAddresses, mergedRelayAddresses) - }) + } + } // Case where a "backup" network is specified, but no dedup expression is provided. Technically possible, diff --git a/tools/network/dnssec/config_windows.go b/tools/network/dnssec/config_windows.go index f41d6b6be7..318f8f7a49 100644 --- a/tools/network/dnssec/config_windows.go +++ b/tools/network/dnssec/config_windows.go @@ -95,7 +95,7 @@ type fixedInfoWithOverlay struct { func SystemConfig() (servers []ResolverAddress, timeout time.Duration, err error) { ulSize := uint32(unsafe.Sizeof(fixedInfoWithOverlay{})) - buf, err := windows.LocalAlloc(windows.LMEM_FIXED | windows.LMEM_ZEROINIT, ulSize) + buf, err := windows.LocalAlloc(windows.LMEM_FIXED|windows.LMEM_ZEROINIT, ulSize) if err != nil { err = fmt.Errorf("GetNetworkParams failed to allocate %d bytes of memory for fixedInfoWithOverlay", ulSize) return