Skip to content

Commit

Permalink
Merge pull request #377 from Shopify/grodowski/fix-flaky-go-test
Browse files Browse the repository at this point in the history
Fix flaky data_iterator_test.go by adding locking
  • Loading branch information
grodowski authored Dec 10, 2024
2 parents 25f3578 + 1e4299a commit 24001d1
Showing 1 changed file with 9 additions and 5 deletions.
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

0 comments on commit 24001d1

Please sign in to comment.