Skip to content

Commit

Permalink
Fix waiting time in test_BlockMetadataMatchedCoreAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed May 16, 2024
1 parent 336424f commit 6b34744
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/lo"
"github.com/iotaledger/hive.go/runtime/options"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
"github.com/iotaledger/iota-core/pkg/testsuite/mock"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
Expand Down Expand Up @@ -61,7 +62,7 @@ func (e *EventAPIDockerTestFramework) ConnectEventAPIClient(ctx context.Context)
}

// SubmitDataBlockStream submits a stream of data blocks to the network for the given duration.
func (e *EventAPIDockerTestFramework) SubmitDataBlockStream(wallet *mock.Wallet, duration time.Duration, tick time.Duration, countPerTick int, blockSubmittedCallback func()) {
func (e *EventAPIDockerTestFramework) SubmitDataBlockStream(wallet *mock.Wallet, duration time.Duration, tick time.Duration, countPerTick int, blockSubmittedCallback func(*blocks.Block)) {
timer := time.NewTimer(duration)
defer timer.Stop()

Expand All @@ -72,10 +73,10 @@ func (e *EventAPIDockerTestFramework) SubmitDataBlockStream(wallet *mock.Wallet,
select {
case <-ticker.C:
for range countPerTick {
_, err := wallet.CreateAndSubmitBasicBlock(context.TODO(), "tagged_data_block", mock.WithPayload(tpkg.RandTaggedData([]byte("tag"))))
block, err := wallet.CreateAndSubmitBasicBlock(context.TODO(), "tagged_data_block", mock.WithPayload(tpkg.RandTaggedData([]byte("tag"))))
require.NoError(e.Testing, err)

blockSubmittedCallback()
blockSubmittedCallback(block)
}
case <-timer.C:
return
Expand Down
13 changes: 10 additions & 3 deletions tools/docker-network/tests/eventapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
"github.com/iotaledger/iota-core/pkg/testsuite/mock"
"github.com/iotaledger/iota-core/tools/docker-network/tests/dockertestframework"
iotago "github.com/iotaledger/iota.go/v4"
Expand Down Expand Up @@ -501,13 +502,19 @@ func test_BlockMetadataMatchedCoreAPI(t *testing.T, e *dockertestframework.Event

// issue blocks
fmt.Println("Submitting blocks for 30s...")
e.SubmitDataBlockStream(account.Wallet(), 30*time.Second, 1*time.Second, 10, func() {
var maxSlot iotago.SlotIndex
e.SubmitDataBlockStream(account.Wallet(), 30*time.Second, 1*time.Second, 10, func(block *blocks.Block) {
sentCounter.Add(1)
if block.ID().Slot() > maxSlot {
maxSlot = block.ID().Slot()
}
})

// wait until all blocks are committed
e.DockerTestFramework().AwaitCommittedSlot(maxSlot, true)

// wait until all topics receives all expected objects
fmt.Println("Waiting for receiving additional blocks for 5s...")
time.Sleep(5 * time.Second)
time.Sleep(1 * time.Second)

// cancel listening
cancel()
Expand Down

0 comments on commit 6b34744

Please sign in to comment.