Skip to content

Commit 23a04c2

Browse files
authored
tests: flaky tests fixes (algorand#6098)
1 parent 595ec23 commit 23a04c2

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

ledger/ledger_test.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,6 +2915,12 @@ func testVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T, cfg confi
29152915
require.NoError(t, err)
29162916
defer l.Close()
29172917

2918+
// quit the commitSyncer goroutine: this test flushes manually with triggerTrackerFlush
2919+
l.trackers.ctxCancel()
2920+
l.trackers.ctxCancel = nil
2921+
<-l.trackers.commitSyncerClosed
2922+
l.trackers.commitSyncerClosed = nil
2923+
29182924
blk := genesisInitState.Block
29192925

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

29342943
// we simulate that the stateproof for round 512 is confirmed on chain, and we can move to the next one.
@@ -2941,31 +2950,12 @@ func testVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T, cfg confi
29412950
blk.BlockHeader.Round++
29422951
err = l.AddBlock(blk, agreement.Certificate{})
29432952
require.NoError(t, err)
2944-
}
2945-
2946-
// wait all pending commits to finish
2947-
l.trackers.accountsWriting.Wait()
2948-
2949-
// quit the commitSyncer goroutine: this test flushes manually with triggerTrackerFlush
2950-
l.trackers.ctxCancel()
2951-
l.trackers.ctxCancel = nil
2952-
<-l.trackers.commitSyncerClosed
2953-
l.trackers.commitSyncerClosed = nil
2954-
2955-
// it is possible a commmit was scheduled while commitSyncer was closing so that there is one pending task
2956-
// that required to be done before before the ledger can be closed, so drain the queue
2957-
outer:
2958-
for {
2959-
select {
2960-
case <-l.trackers.deferredCommits:
2961-
log.Info("drained deferred commit")
2962-
l.trackers.accountsWriting.Done()
2963-
default:
2964-
break outer
2953+
if i%100 == 0 {
2954+
triggerTrackerFlush(t, l)
29652955
}
29662956
}
29672957

2968-
// flush one final time
2958+
// flush remaining blocks
29692959
triggerTrackerFlush(t, l)
29702960

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

2975+
t.Log("reloading ledger")
2976+
// drain any deferred commits since AddBlock above triggered scheduleCommit
2977+
outer:
2978+
for {
2979+
select {
2980+
case <-l.trackers.deferredCommits:
2981+
l.trackers.accountsWriting.Done()
2982+
default:
2983+
break outer
2984+
}
2985+
}
2986+
29852987
err = l.reloadLedger()
29862988
require.NoError(t, err)
29872989

network/p2p/p2p_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,13 @@ func TestP2PMakeHostAddressFilter(t *testing.T) {
290290
mala, err := multiaddr.NewMultiaddr(la)
291291
require.NoError(t, err)
292292
host.Network().Listen(mala)
293-
require.Empty(t, host.Addrs())
293+
addrs := host.Addrs()
294+
if len(addrs) > 0 {
295+
// CI servers might have a single public IP interface, validate if this is a case
296+
for _, a := range addrs {
297+
require.True(t, manet.IsPublicAddr(a))
298+
}
299+
}
294300
host.Close()
295301
}
296302

test/scripts/e2e_subs/goal-partkey-commands.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ fail_test () {
6363

6464
create_and_fund_account () {
6565
set +x # disable command echoing to hide the account funding output
66-
local TEMP_ACCT=$(${gcmd} account new|awk '{ print $6 }')
66+
local TEMP_ACCT
67+
TEMP_ACCT=$(${gcmd} account new|awk '{ print $6 }')
6768
SEND_OUTOUT=$(${gcmd} clerk send -f "$INITIAL_ACCOUNT" -t "$TEMP_ACCT" -a 1000000 2>&1)
6869
if [[ $SEND_OUTOUT == *"Couldn't broadcast tx"* ]]; then
6970
fail_test "Failed to fund account: $SEND_OUTOUT"
@@ -77,17 +78,21 @@ create_and_fund_account () {
7778
# $2 - a participation id
7879
# $3 - error message
7980
verify_registered_state () {
81+
SEARCH_STATE=$(echo "$1" | xargs)
82+
SEARCH_KEY=$(echo "$2" | xargs)
83+
SEARCH_INVOKE_CONTEXT=$(echo "$3" | xargs)
84+
8085
# look for participation ID anywhere in the partkeyinfo output
8186
PARTKEY_OUTPUT=$(${gcmd} account partkeyinfo)
82-
if ! echo "$PARTKEY_OUTPUT" | grep -q "$2"; then
83-
fail_test "Key $2 was not installed properly for cmd '$3':\n$PARTKEY_OUTPUT"
87+
if ! echo "$PARTKEY_OUTPUT" | grep -q -F "$SEARCH_KEY"; then
88+
fail_test "Key $SEARCH_KEY was not installed properly for cmd '$SEARCH_INVOKE_CONTEXT':\n$PARTKEY_OUTPUT"
8489
fi
8590

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

0 commit comments

Comments
 (0)