Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 3bfd659

Browse files
authored
Merge pull request #892 from iotaledger/fix/tests-eventually-cases
Fix testing.Eventually cases to not fail the test if an assertion fails
2 parents 672bea9 + 4a27031 commit 3bfd659

File tree

8 files changed

+32
-17
lines changed

8 files changed

+32
-17
lines changed

pkg/protocol/engine/mempool/spenddag/spenddagv1/spender_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func TestSpendParallel(t *testing.T) {
249249
parallelPendingTasks.WaitIsZero()
250250

251251
lo.ForEach(lo.Keys(parallelSpenders), func(SpendAlias string) {
252-
assert.EqualValuesf(t, sequentialSpenders[SpendAlias].PreferredInstead().ID, parallelSpenders[SpendAlias].PreferredInstead().ID, "parallel Spend %s prefers %s, but sequential Spend prefers %s", SpendAlias, parallelSpenders[SpendAlias].PreferredInstead().ID, sequentialSpenders[SpendAlias].PreferredInstead().ID)
252+
require.EqualValuesf(t, sequentialSpenders[SpendAlias].PreferredInstead().ID, parallelSpenders[SpendAlias].PreferredInstead().ID, "parallel Spend %s prefers %s, but sequential Spend prefers %s", SpendAlias, parallelSpenders[SpendAlias].PreferredInstead().ID, sequentialSpenders[SpendAlias].PreferredInstead().ID)
253253
})
254254

255255
assertCorrectOrder(t, lo.Values(sequentialSpenders)...)

pkg/testsuite/attestations.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ func (t *TestSuite) AssertAttestationsForSlot(slot iotago.SlotIndex, blocks []*b
3232
//nolint:revive
3333
err = attestationTree.Stream(func(key iotago.AccountID, att *iotago.Attestation) error {
3434
blockID, err := att.BlockID()
35-
require.NoError(t.Testing, err)
35+
if err != nil {
36+
return ierrors.Wrapf(err, "failed to stream attestationTree: %s, slot: %d", node.Name, slot)
37+
}
3638
storedAttestations = append(storedAttestations, blockID)
3739

3840
return nil

pkg/testsuite/storage_settings.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package testsuite
33
import (
44
"context"
55

6-
"github.com/stretchr/testify/require"
7-
86
"github.com/iotaledger/hive.go/ierrors"
97
"github.com/iotaledger/iota-core/pkg/testsuite/mock"
108
iotago "github.com/iotaledger/iota.go/v4"
@@ -56,14 +54,17 @@ func (t *TestSuite) AssertCommitmentSlotIndexExists(slot iotago.SlotIndex, clien
5654
for _, client := range clients {
5755
t.Eventually(func() error {
5856
latestCommitment, err := client.CommitmentByID(context.Background(), iotago.EmptyCommitmentID)
59-
require.NoError(t.Testing, err)
57+
if err != nil {
58+
return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: error loading latest commitment: %w", client.Name(), err)
59+
}
60+
6061
if latestCommitment.Slot < slot {
6162
return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: commitment with at least %v not found in settings.LatestCommitment()", client.Name(), slot)
6263
}
6364

6465
cm, err := client.CommitmentBySlot(context.Background(), slot)
6566
if err != nil {
66-
return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: expected %v, got error %v", client.Name(), slot, err)
67+
return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: expected %v, got error %w", client.Name(), slot, err)
6768
}
6869

6970
if cm == nil {

pkg/testsuite/sybilprotection.go

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

33
import (
44
"github.com/stretchr/testify/assert"
5-
"github.com/stretchr/testify/require"
65

76
"github.com/iotaledger/hive.go/ierrors"
87
"github.com/iotaledger/hive.go/lo"
@@ -89,7 +88,9 @@ func (t *TestSuite) AssertSybilProtectionRegisteredValidators(epoch iotago.Epoch
8988
candidateIDs := lo.Map(candidates, func(candidate *api.ValidatorResponse) string {
9089
return candidate.AddressBech32
9190
})
92-
require.NoError(t.Testing, err)
91+
if err != nil {
92+
return ierrors.Wrapf(err, "AssertSybilProtectionRegisteredValidators: %s: failed to get registered validators in epoch %d", node.Name, epoch)
93+
}
9394

9495
if !assert.ElementsMatch(t.fakeTesting, expectedAccounts, candidateIDs) {
9596
return ierrors.Errorf("AssertSybilProtectionRegisteredValidators: %s: expected %s, got %s", node.Name, expectedAccounts, candidateIDs)
@@ -113,7 +114,9 @@ func (t *TestSuite) AssertSybilProtectionCandidates(epoch iotago.EpochIndex, exp
113114
candidateIDs := lo.Map(candidates, func(candidate *accounts.AccountData) iotago.AccountID {
114115
return candidate.ID
115116
})
116-
require.NoError(t.Testing, err)
117+
if err != nil {
118+
return ierrors.Wrapf(err, "AssertSybilProtectionCandidates: %s: failed to get eligible validators in epoch %d", node.Name, epoch)
119+
}
117120

118121
if !assert.ElementsMatch(t.fakeTesting, expectedAccounts, candidateIDs) {
119122
return ierrors.Errorf("AssertSybilProtectionCandidates: %s: expected %s, got %s", node.Name, expectedAccounts, candidateIDs)

pkg/testsuite/testsuite.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ func WithWalletBlockIssuanceCredits(blockIssuanceCredits iotago.BlockIssuanceCre
5454
}
5555

5656
type TestSuite struct {
57-
Testing *testing.T
57+
Testing *testing.T
58+
// we use the fake testing so that actual tests don't fail if an assertion fails
5859
fakeTesting *testing.T
5960
network *mock.Network
6061

pkg/testsuite/transactions.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ func (t *TestSuite) AssertTransaction(transaction *iotago.Transaction, node *moc
3838
return ierrors.Errorf("AssertTransaction: %s: expected Transaction type %T, got %T", node.Name, transaction, loadedTransactionMetadata.Transaction())
3939
}
4040

41-
// TODO: fix this in another PR
42-
// if !assert.Equal(t.fakeTesting, transaction.Outputs, typedTransaction.Outputs) {
4341
api := t.DefaultWallet().Client.APIForSlot(transactionID.Slot())
4442
expected, _ := api.Encode(transaction.Outputs)
4543
actual, _ := api.Encode(typedTransaction.Outputs)

tools/docker-network/tests/dockerframework.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ func (n *Node) AccountAddress(t *testing.T) *iotago.AccountAddress {
6868

6969
type DockerTestFramework struct {
7070
Testing *testing.T
71+
// we use the fake testing so that actual tests don't fail if an assertion fails
72+
fakeTesting *testing.T
7173

7274
nodes map[string]*Node
7375
nodesLock syncutils.RWMutex
@@ -88,6 +90,7 @@ type DockerTestFramework struct {
8890
func NewDockerTestFramework(t *testing.T, opts ...options.Option[DockerTestFramework]) *DockerTestFramework {
8991
return options.Apply(&DockerTestFramework{
9092
Testing: t,
93+
fakeTesting: &testing.T{},
9194
nodes: make(map[string]*Node),
9295
wallet: NewDockerWallet(t),
9396
optsWaitForSync: 5 * time.Minute,
@@ -223,13 +226,19 @@ func (d *DockerTestFramework) WaitUntilFaucetHealthy() {
223226

224227
d.Eventually(func() error {
225228
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, d.optsFaucetURL+"/health", nil)
226-
require.NoError(d.Testing, err)
229+
if err != nil {
230+
return err
231+
}
227232

228233
res, err := http.DefaultClient.Do(req)
229-
require.NoError(d.Testing, err)
234+
if err != nil {
235+
return err
236+
}
230237
defer res.Body.Close()
231238

232-
require.Equal(d.Testing, http.StatusOK, res.StatusCode)
239+
if res.StatusCode != http.StatusOK {
240+
return ierrors.Errorf("faucet is not healthy, status code: %d", res.StatusCode)
241+
}
233242

234243
return nil
235244
}, true)

tools/docker-network/tests/utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"strconv"
1616
"time"
1717

18+
"github.com/stretchr/testify/assert"
1819
"github.com/stretchr/testify/require"
1920

2021
"github.com/iotaledger/hive.go/ierrors"
@@ -70,8 +71,8 @@ func (d *DockerTestFramework) AssertIndexerAccount(account *mock.AccountData) {
7071
return err
7172
}
7273

73-
require.EqualValues(d.Testing, account.OutputID, *outputID)
74-
require.EqualValues(d.Testing, account.Output, output)
74+
assert.EqualValues(d.fakeTesting, account.OutputID, *outputID)
75+
assert.EqualValues(d.fakeTesting, account.Output, output)
7576

7677
return nil
7778
})

0 commit comments

Comments
 (0)