Skip to content

Commit

Permalink
Convert BadgerRetryableUploadWrapper to Component
Browse files Browse the repository at this point in the history
BadgerRetryableUploadWrapper wraps an AsyncUploader. Now that the
AsyncUploader is a Component, it needs to be `Start()`ed.
The retryable wrapper did not itself do anything special on ready/done,
so the Component functionality is directly delegated to the wrapped AsyncUploader.
  • Loading branch information
tim-barry committed Dec 12, 2024
1 parent e73b3f3 commit 9c57c77
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/onflow/flow-go/engine/execution"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
"github.com/onflow/flow-go/module/component"
"github.com/onflow/flow-go/module/executiondatasync/execution_data"
"github.com/onflow/flow-go/module/mempool/entity"
"github.com/onflow/flow-go/storage"
Expand All @@ -34,6 +35,7 @@ type BadgerRetryableUploaderWrapper struct {
results storage.ExecutionResults
transactionResults storage.TransactionResults
uploadStatusStore storage.ComputationResultUploadStatus
component.Component
}

func NewBadgerRetryableUploaderWrapper(
Expand Down Expand Up @@ -99,17 +101,10 @@ func NewBadgerRetryableUploaderWrapper(
results: results,
transactionResults: transactionResults,
uploadStatusStore: uploadStatusStore,
Component: uploader, // delegate to the AsyncUploader
}
}

func (b *BadgerRetryableUploaderWrapper) Ready() <-chan struct{} {
return b.uploader.Ready()
}

func (b *BadgerRetryableUploaderWrapper) Done() <-chan struct{} {
return b.uploader.Done()
}

func (b *BadgerRetryableUploaderWrapper) Upload(computationResult *execution.ComputationResult) error {
if computationResult == nil || computationResult.ExecutableBlock == nil ||
computationResult.ExecutableBlock.Block == nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uploader

import (
"context"
"sync"
"testing"
"time"
Expand All @@ -11,6 +12,7 @@ import (
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/executiondatasync/execution_data"
executionDataMock "github.com/onflow/flow-go/module/executiondatasync/execution_data/mock"
"github.com/onflow/flow-go/module/irrecoverable"
"github.com/onflow/flow-go/module/mempool/entity"
"github.com/onflow/flow-go/module/metrics"

Expand All @@ -26,6 +28,8 @@ import (
)

func Test_Upload_invoke(t *testing.T) {
ctx, cancel := irrecoverable.NewMockSignalerContextWithCancel(t, context.Background())
defer cancel()
wg := sync.WaitGroup{}
uploaderCalled := false

Expand All @@ -40,7 +44,7 @@ func Test_Upload_invoke(t *testing.T) {
1*time.Nanosecond, 1, zerolog.Nop(), &metrics.NoopCollector{})

testRetryableUploaderWrapper := createTestBadgerRetryableUploaderWrapper(asyncUploader)
defer testRetryableUploaderWrapper.Done()
testRetryableUploaderWrapper.Start(ctx)

// nil input - no call to Upload()
err := testRetryableUploaderWrapper.Upload(nil)
Expand All @@ -58,6 +62,8 @@ func Test_Upload_invoke(t *testing.T) {
}

func Test_RetryUpload(t *testing.T) {
ctx, cancel := irrecoverable.NewMockSignalerContextWithCancel(t, context.Background())
defer cancel()
wg := sync.WaitGroup{}
wg.Add(1)
uploaderCalled := false
Expand All @@ -72,7 +78,7 @@ func Test_RetryUpload(t *testing.T) {
1*time.Nanosecond, 1, zerolog.Nop(), &metrics.NoopCollector{})

testRetryableUploaderWrapper := createTestBadgerRetryableUploaderWrapper(asyncUploader)
defer testRetryableUploaderWrapper.Done()
testRetryableUploaderWrapper.Start(ctx)

err := testRetryableUploaderWrapper.RetryUpload()
wg.Wait()
Expand All @@ -82,6 +88,8 @@ func Test_RetryUpload(t *testing.T) {
}

func Test_AsyncUploaderCallback(t *testing.T) {
ctx, cancel := irrecoverable.NewMockSignalerContextWithCancel(t, context.Background())
defer cancel()
wgUploadCalleded := sync.WaitGroup{}
wgUploadCalleded.Add(1)

Expand All @@ -95,7 +103,7 @@ func Test_AsyncUploaderCallback(t *testing.T) {
1*time.Nanosecond, 1, zerolog.Nop(), &metrics.NoopCollector{})

testRetryableUploaderWrapper := createTestBadgerRetryableUploaderWrapper(asyncUploader)
defer testRetryableUploaderWrapper.Done()
testRetryableUploaderWrapper.Start(ctx)

testComputationResult := createTestComputationResult()
err := testRetryableUploaderWrapper.Upload(testComputationResult)
Expand Down

0 comments on commit 9c57c77

Please sign in to comment.