Skip to content

Commit e91216b

Browse files
committed
fix: data race in tests
1 parent ca7f5c9 commit e91216b

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

internal/replication/manager.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,11 @@ func (m *Manager) Run(ctx context.Context) {
257257

258258
close(m.started)
259259

260+
// copy to prevent data race when setting the stopChannel to nil
261+
stopChannel := m.stopChannel
260262
for {
261263
select {
262-
case signalChannel := <-m.stopChannel:
264+
case signalChannel := <-stopChannel:
263265
m.logger.Debugf("got stop signal")
264266
m.stopPipelines(ctx)
265267
m.pipelinesWaitGroup.Wait()
@@ -291,14 +293,9 @@ func (m *Manager) Stop(ctx context.Context) error {
291293
m.logger.Info("stopping manager")
292294
signalChannel := make(chan error, 1)
293295

294-
if m.stopChannel == nil {
295-
return nil
296-
}
297-
298296
select {
299297
case m.stopChannel <- signalChannel:
300298
close(m.stopChannel)
301-
m.stopChannel = nil
302299
m.logger.Debug("stopping manager signal sent")
303300
select {
304301
case <-signalChannel:

internal/replication/manager_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ func startManager(
3333
WithSyncPeriod(time.Second),
3434
)
3535
go manager.Run(ctx)
36-
t.Cleanup(func() {
37-
ctx, cancel := context.WithTimeout(ctx, time.Second)
38-
defer cancel()
39-
40-
require.NoError(t, manager.Stop(ctx))
41-
})
4236

4337
return manager
4438
}
@@ -122,6 +116,9 @@ func TestManagerExportersNominal(t *testing.T) {
122116
driverFactory,
123117
exporterConfigValidator,
124118
)
119+
t.Cleanup(func() {
120+
require.NoError(t, manager.Stop(ctx))
121+
})
125122
<-manager.Started()
126123

127124
err := manager.StartPipeline(ctx, pipeline.ID)
@@ -208,6 +205,9 @@ func TestManagerExportersUpdate(t *testing.T) {
208205
driverFactory,
209206
exporterConfigValidator,
210207
)
208+
t.Cleanup(func() {
209+
require.NoError(t, manager.Stop(ctx))
210+
})
211211
<-manager.Started()
212212

213213
err := manager.StartPipeline(ctx, pipeline.ID)

0 commit comments

Comments
 (0)