Skip to content

Commit

Permalink
tests: flaky tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Jun 22, 2023
1 parent b06de44 commit 827570a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ ALWAYS:
# build our fork of libsodium, placing artifacts into crypto/lib/ and crypto/include/
crypto/libs/$(OS_TYPE)/$(ARCH)/lib/libsodium.a:
mkdir -p crypto/copies/$(OS_TYPE)/$(ARCH)
cp -R crypto/libsodium-fork crypto/copies/$(OS_TYPE)/$(ARCH)/libsodium-fork
cp -R crypto/libsodium-fork/. crypto/copies/$(OS_TYPE)/$(ARCH)/libsodium-fork
cd crypto/copies/$(OS_TYPE)/$(ARCH)/libsodium-fork && \
./autogen.sh --prefix $(SRCPATH)/crypto/libs/$(OS_TYPE)/$(ARCH) && \
./configure --disable-shared --prefix="$(SRCPATH)/crypto/libs/$(OS_TYPE)/$(ARCH)" && \
Expand Down
29 changes: 29 additions & 0 deletions data/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package data
import (
"context"
"fmt"
"regexp"
"strconv"
"strings"
"sync"
"testing"

Expand Down Expand Up @@ -629,6 +632,32 @@ func TestLedgerErrorValidate(t *testing.T) {
case <-expectedMessages:
// only debug messages should be reported
case um := <-unexpectedMessages:
if strings.Contains(um, "before dbRound") {
// EnsureBlock might log the following:
// data.EnsureBlock: could not write block 774 to the ledger: round 773 before dbRound 774
// it happens because of simultaneous EnsureValidatedBlock and EnsureBlock calls
// that pass round check and then EnsureBlock yields after StartEvaluator.
// Meanwhile EnsureValidatedBlock finishes and adds the block to the ledger.
// After that trackersDB commit happen and account data get flushed.
// The EnsureBlock goroutine then tries to evaluate a first transaction and fails because
// the trackerDB advanced further.
// This is okay to ignore if
// - attempted round is less or equal than dbRound
// - ledger latest round is greater than dbRound + cfg.MaxAcctLookback
re := regexp.MustCompile(`could not write block (\d+) to the ledger: round (\d+) before dbRound (\d+)`)
result := re.FindStringSubmatch(um)
require.NotNil(t, result)
require.Len(t, result, 4)
attemptedRound, err := strconv.Atoi(result[1])
require.NoError(t, err)
evalRound, err := strconv.Atoi(result[2])
require.NoError(t, err)
dbRound, err := strconv.Atoi(result[3])
require.NoError(t, err)
require.Equal(t, attemptedRound, evalRound+1)
require.LessOrEqual(t, attemptedRound, dbRound)
require.GreaterOrEqual(t, int(l.Latest()), dbRound+int(cfg.MaxAcctLookback))
}
require.Empty(t, um, um)
default:
more = false
Expand Down
12 changes: 12 additions & 0 deletions tools/network/dnssec/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@ func TestSrvSort(t *testing.T) {
arr = append(arr, &net.SRV{Priority: 1, Weight: 1})
arr = append(arr, &net.SRV{Priority: 1, Weight: 1})

retryCounter := 0
retry:
srvRecArray(arr).sortAndRand()
if (*arr[0] != net.SRV{Priority: 1, Weight: 200}) {
// there is a small change that random number from 0 to 204 would 0 or 1
// so the first element would be with weight of 1 and not 200
// if this happens, we will try again
if retryCounter > 3 {
a.Fail("randomization failed")
}
retryCounter++
goto retry
}
a.Equal(net.SRV{Priority: 1, Weight: 200}, *arr[0])
a.Equal(net.SRV{Priority: 1, Weight: 1}, *arr[1])
a.Equal(net.SRV{Priority: 1, Weight: 1}, *arr[2])
Expand Down

0 comments on commit 827570a

Please sign in to comment.