Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky data_iterator_test.go by adding locking #377

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions test/go/data_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ package test

import (
"fmt"
"github.com/stretchr/testify/suite"
"sync"
"testing"

"github.com/Shopify/ghostferry"
"github.com/Shopify/ghostferry/testhelpers"
"github.com/stretchr/testify/suite"
)

type DataIteratorTestSuite struct {
*testhelpers.GhostferryUnitTestSuite

di *ghostferry.DataIterator
wg *sync.WaitGroup
tables []*ghostferry.TableSchema
receivedRows map[string][]ghostferry.RowData
di *ghostferry.DataIterator
wg *sync.WaitGroup
tables []*ghostferry.TableSchema
receivedRows map[string][]ghostferry.RowData
receivedRowsMutex sync.Mutex
}

func (this *DataIteratorTestSuite) SetupTest() {
Expand Down Expand Up @@ -61,6 +62,9 @@ func (this *DataIteratorTestSuite) SetupTest() {
this.receivedRows = make(map[string][]ghostferry.RowData, 0)

this.di.AddBatchListener(func(ev *ghostferry.RowBatch) error {
this.receivedRowsMutex.Lock()
defer this.receivedRowsMutex.Unlock()

this.receivedRows[ev.TableSchema().Name] = append(this.receivedRows[ev.TableSchema().Name], ev.Values()...)
return nil
})
Expand Down
Loading