Skip to content

Commit c012a8a

Browse files
authored
tests: don't panic when a staker query fails during a wait (#146)
waitForCompletedPeriods logged periodDetails.CompletedPeriods before checking the query error, so a failed GetValidationPeriodDetails call dereferenced a nil result and panicked. The panic skipped RunFlakyTest's retries and hid the query error. It failed thor-private CI twice in Test_Stargate_DelegatorFlow_Stake_And_Claim_Auto_Renew_On_And_Off while the chain was producing blocks normally. Check the error first. A failed query now counts as not done yet, is logged, and polling continues within the existing one-minute bound. If the wait still fails, return the underlying error instead of a generic StakerStatusUnknownError, so the cause shows and the test is retried. assertValidatorStatus and assertValidatorStatusUnknown in the validations tests had the same nil dereference after assert.NoError: stop with require.NoError, or return the error for a retry.
1 parent d65070a commit c012a8a

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎tests/stargate/stargate_test.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package stargate
22

33
import (
4+
"fmt"
45
"log/slog"
56
"math/big"
67
"strconv"
@@ -37,14 +38,17 @@ func Test_Stargate_SingleDelegator(t *testing.T) {
3738
func waitForCompletedPeriods(ticker *utils.Ticker, staker *builtin.Staker, validationID thor.Address, expectedPeriods uint32) error {
3839
err := ticker.WaitForCondition(time.Minute*1, func() (bool, error) {
3940
periodDetails, err := staker.GetValidationPeriodDetails(validationID)
40-
slog.Info("⚠️ - completed periods, waiting for greater or equal than expected", "completed", int(periodDetails.CompletedPeriods), "expected", expectedPeriods)
4141
if err != nil {
42-
return false, err
42+
// keep polling: a failed query is not a result, and WaitForCondition
43+
// still bounds the wait
44+
slog.Warn("⚠️ - failed to get validation period details", "validationID", validationID, "err", err)
45+
return false, nil
4346
}
47+
slog.Info("⚠️ - completed periods, waiting for greater or equal than expected", "completed", int(periodDetails.CompletedPeriods), "expected", expectedPeriods)
4448
return periodDetails.CompletedPeriods >= expectedPeriods, nil
4549
})
4650
if err != nil {
47-
return testutil.StakerStatusUnknownError{ValidationID: validationID.String()}
51+
return fmt.Errorf("waiting for %d completed periods of %s: %w", expectedPeriods, validationID, err)
4852
}
4953
return nil
5054
}

‎tests/validations/validations_test.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package validations
22

33
import (
4+
"fmt"
45
"log/slog"
56
"math/big"
67
"testing"
@@ -772,14 +773,16 @@ func assertMatchingValidators(t *testing.T, staker *builtin.Staker, id1 thor.Add
772773
func assertValidatorStatus(t *testing.T, staker *builtin.Staker, validatorID thor.Address, expectedStatus builtin.StakerStatus, waitForBlock uint32) {
773774
assert.NoError(t, utils.NewTicker(staker.Raw().Client()).WaitForBlock(waitForBlock))
774775
validator, err := staker.GetValidation(validatorID)
775-
assert.NoError(t, err)
776+
require.NoError(t, err)
776777
assert.Equal(t, expectedStatus, validator.Status)
777778
}
778779

779780
func assertValidatorStatusUnknown(t *testing.T, staker *builtin.Staker, validatorID thor.Address, expectedStatus builtin.StakerStatus, waitForBlock uint32) error {
780781
assert.NoError(t, utils.NewTicker(staker.Raw().Client()).WaitForBlock(waitForBlock))
781782
validator, err := staker.GetValidation(validatorID)
782-
assert.NoError(t, err)
783+
if err != nil {
784+
return fmt.Errorf("getting validation %s: %w", validatorID, err)
785+
}
783786
if validator.Status == builtin.StakerStatusUnknown {
784787
return testutil.StakerStatusUnknownError{ValidationID: validatorID.String()}
785788
}

0 commit comments

Comments
 (0)