Skip to content

Commit

Permalink
fixed: test datarace
Browse files Browse the repository at this point in the history
  • Loading branch information
primalmotion committed Oct 7, 2019
1 parent 78542e8 commit e4891ba
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions maniptest/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,49 @@ func NewTestSubscriber() TestSubscriber {

func (m *testSubscriber) MockStart(t *testing.T, impl func(context.Context, *elemental.PushFilter)) {

m.lock.Lock()
defer m.lock.Unlock()

m.currentMocks(t).startMock = impl
}

func (m *testSubscriber) MockUpdateFilter(t *testing.T, impl func(*elemental.PushFilter)) {

m.lock.Lock()
defer m.lock.Unlock()

m.currentMocks(t).updateFilerMock = impl
}

func (m *testSubscriber) MockEvents(t *testing.T, impl func() chan *elemental.Event) {

m.lock.Lock()
defer m.lock.Unlock()

m.currentMocks(t).eventsMock = impl
}

func (m *testSubscriber) MockErrors(t *testing.T, impl func() chan error) {

m.lock.Lock()
defer m.lock.Unlock()

m.currentMocks(t).errorsMock = impl
}

func (m *testSubscriber) MockStatus(t *testing.T, impl func() chan manipulate.SubscriberStatus) {

m.lock.Lock()
defer m.lock.Unlock()

m.currentMocks(t).statusMock = impl
}

func (m *testSubscriber) Start(ctx context.Context, filter *elemental.PushFilter) {

m.lock.Lock()
defer m.lock.Unlock()

if mock := m.currentMocks(m.currentTest); mock != nil && mock.startMock != nil {
mock.startMock(ctx, filter)
}
Expand All @@ -88,6 +106,9 @@ func (m *testSubscriber) Start(ctx context.Context, filter *elemental.PushFilter

func (m *testSubscriber) UpdateFilter(filter *elemental.PushFilter) {

m.lock.Lock()
defer m.lock.Unlock()

if mock := m.currentMocks(m.currentTest); mock != nil && mock.updateFilerMock != nil {
mock.updateFilerMock(filter)
}
Expand All @@ -96,6 +117,9 @@ func (m *testSubscriber) UpdateFilter(filter *elemental.PushFilter) {

func (m *testSubscriber) Events() chan *elemental.Event {

m.lock.Lock()
defer m.lock.Unlock()

if mock := m.currentMocks(m.currentTest); mock != nil && mock.eventsMock != nil {
return mock.eventsMock()
}
Expand All @@ -105,6 +129,9 @@ func (m *testSubscriber) Events() chan *elemental.Event {

func (m *testSubscriber) Errors() chan error {

m.lock.Lock()
defer m.lock.Unlock()

if mock := m.currentMocks(m.currentTest); mock != nil && mock.errorsMock != nil {
return mock.errorsMock()
}
Expand All @@ -114,6 +141,9 @@ func (m *testSubscriber) Errors() chan error {

func (m *testSubscriber) Status() chan manipulate.SubscriberStatus {

m.lock.Lock()
defer m.lock.Unlock()

if mock := m.currentMocks(m.currentTest); mock != nil && mock.statusMock != nil {
return mock.statusMock()
}
Expand All @@ -123,9 +153,6 @@ func (m *testSubscriber) Status() chan manipulate.SubscriberStatus {

func (m *testSubscriber) currentMocks(t *testing.T) *mockedSubscriberMethods {

m.lock.Lock()
defer m.lock.Unlock()

mocks := m.mocks[t]

if mocks == nil {
Expand Down

0 comments on commit e4891ba

Please sign in to comment.