Skip to content

Commit

Permalink
tests: flaky tests fixes (algorand#6098)
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy authored Aug 8, 2024
1 parent 595ec23 commit 23a04c2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
46 changes: 24 additions & 22 deletions ledger/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2915,6 +2915,12 @@ func testVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T, cfg confi
require.NoError(t, err)
defer l.Close()

// quit the commitSyncer goroutine: this test flushes manually with triggerTrackerFlush
l.trackers.ctxCancel()
l.trackers.ctxCancel = nil
<-l.trackers.commitSyncerClosed
l.trackers.commitSyncerClosed = nil

blk := genesisInitState.Block

sp := bookkeeping.StateProofTrackingData{
Expand All @@ -2929,6 +2935,9 @@ func testVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T, cfg confi
blk.BlockHeader.Round++
err = l.AddBlock(blk, agreement.Certificate{})
require.NoError(t, err)
if i > 0 && i%100 == 0 {
triggerTrackerFlush(t, l)
}
}

// we simulate that the stateproof for round 512 is confirmed on chain, and we can move to the next one.
Expand All @@ -2941,31 +2950,12 @@ func testVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T, cfg confi
blk.BlockHeader.Round++
err = l.AddBlock(blk, agreement.Certificate{})
require.NoError(t, err)
}

// wait all pending commits to finish
l.trackers.accountsWriting.Wait()

// quit the commitSyncer goroutine: this test flushes manually with triggerTrackerFlush
l.trackers.ctxCancel()
l.trackers.ctxCancel = nil
<-l.trackers.commitSyncerClosed
l.trackers.commitSyncerClosed = nil

// it is possible a commmit was scheduled while commitSyncer was closing so that there is one pending task
// that required to be done before before the ledger can be closed, so drain the queue
outer:
for {
select {
case <-l.trackers.deferredCommits:
log.Info("drained deferred commit")
l.trackers.accountsWriting.Done()
default:
break outer
if i%100 == 0 {
triggerTrackerFlush(t, l)
}
}

// flush one final time
// flush remaining blocks
triggerTrackerFlush(t, l)

var vtSnapshot map[basics.Round]*ledgercore.VotersForRound
Expand All @@ -2982,6 +2972,18 @@ outer:
require.NotContains(t, vtSnapshot, basics.Round(240))
}()

t.Log("reloading ledger")
// drain any deferred commits since AddBlock above triggered scheduleCommit
outer:
for {
select {
case <-l.trackers.deferredCommits:
l.trackers.accountsWriting.Done()
default:
break outer
}
}

err = l.reloadLedger()
require.NoError(t, err)

Expand Down
8 changes: 7 additions & 1 deletion network/p2p/p2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,13 @@ func TestP2PMakeHostAddressFilter(t *testing.T) {
mala, err := multiaddr.NewMultiaddr(la)
require.NoError(t, err)
host.Network().Listen(mala)
require.Empty(t, host.Addrs())
addrs := host.Addrs()
if len(addrs) > 0 {
// CI servers might have a single public IP interface, validate if this is a case
for _, a := range addrs {
require.True(t, manet.IsPublicAddr(a))
}
}
host.Close()
}

Expand Down
15 changes: 10 additions & 5 deletions test/scripts/e2e_subs/goal-partkey-commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ fail_test () {

create_and_fund_account () {
set +x # disable command echoing to hide the account funding output
local TEMP_ACCT=$(${gcmd} account new|awk '{ print $6 }')
local TEMP_ACCT
TEMP_ACCT=$(${gcmd} account new|awk '{ print $6 }')
SEND_OUTOUT=$(${gcmd} clerk send -f "$INITIAL_ACCOUNT" -t "$TEMP_ACCT" -a 1000000 2>&1)
if [[ $SEND_OUTOUT == *"Couldn't broadcast tx"* ]]; then
fail_test "Failed to fund account: $SEND_OUTOUT"
Expand All @@ -77,17 +78,21 @@ create_and_fund_account () {
# $2 - a participation id
# $3 - error message
verify_registered_state () {
SEARCH_STATE=$(echo "$1" | xargs)
SEARCH_KEY=$(echo "$2" | xargs)
SEARCH_INVOKE_CONTEXT=$(echo "$3" | xargs)

# look for participation ID anywhere in the partkeyinfo output
PARTKEY_OUTPUT=$(${gcmd} account partkeyinfo)
if ! echo "$PARTKEY_OUTPUT" | grep -q "$2"; then
fail_test "Key $2 was not installed properly for cmd '$3':\n$PARTKEY_OUTPUT"
if ! echo "$PARTKEY_OUTPUT" | grep -q -F "$SEARCH_KEY"; then
fail_test "Key $SEARCH_KEY was not installed properly for cmd '$SEARCH_INVOKE_CONTEXT':\n$PARTKEY_OUTPUT"
fi

# looking for yes/no, and the 8 character head of participation id in this line:
# yes LFMT...RHJQ 4UPT6AQC... 4 0 3000
LISTKEY_OUTPUT=$(${gcmd} account listpartkeys)
if ! echo "$LISTKEY_OUTPUT" | grep -q "$1.*$(echo "$2" | cut -c1-8)"; then
fail_test "Unexpected key $2 state ($1) for cmd '$3':\n$LISTKEY_OUTPUT"
if ! echo "$LISTKEY_OUTPUT" | grep -q "$SEARCH_STATE.*$(echo "$SEARCH_KEY" | cut -c1-8)"; then
fail_test "Unexpected key $SEARCH_KEY state (looked for $SEARCH_STATE ) for cmd '$SEARCH_INVOKE_CONTEXT':\n$LISTKEY_OUTPUT"
fi
}

Expand Down

0 comments on commit 23a04c2

Please sign in to comment.