Fix data race in bulk import tests (#24897)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1a12faaaae
Коммит
4408ece955
@@ -268,7 +268,7 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader
|
||||
linesChan = make(chan imports.LineImportWorkerData, workers)
|
||||
for i := 0; i < workers; i++ {
|
||||
wg.Add(1)
|
||||
go a.bulkImportWorker(c, dryRun, &wg, linesChan, errorsChan)
|
||||
go a.bulkImportWorker(c.Clone(), dryRun, &wg, linesChan, errorsChan)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -16,3 +17,48 @@ func TestContextMaster(t *testing.T) {
|
||||
m := WithMaster(ctx)
|
||||
assert.True(t, HasMaster(m))
|
||||
}
|
||||
|
||||
func TestRequestContextWithMaster(t *testing.T) {
|
||||
t.Run("set and get", func(t *testing.T) {
|
||||
var rctx request.CTX = request.TestContext(t)
|
||||
|
||||
rctx = RequestContextWithMaster(rctx)
|
||||
assert.True(t, HasMaster(rctx.Context()))
|
||||
})
|
||||
|
||||
t.Run("directly assigning does cause the child to alter the parent", func(t *testing.T) {
|
||||
var rctx request.CTX = request.TestContext(t)
|
||||
rctxClone := rctx
|
||||
rctxClone = RequestContextWithMaster(rctxClone)
|
||||
|
||||
assert.True(t, HasMaster(rctx.Context()))
|
||||
assert.True(t, HasMaster(rctxClone.Context()))
|
||||
})
|
||||
|
||||
t.Run("values get copied from parent", func(t *testing.T) {
|
||||
var rctx request.CTX = request.TestContext(t)
|
||||
rctx = RequestContextWithMaster(rctx)
|
||||
rctxClone := rctx.Clone()
|
||||
|
||||
assert.True(t, HasMaster(rctx.Context()))
|
||||
assert.True(t, HasMaster(rctxClone.Context()))
|
||||
})
|
||||
|
||||
t.Run("changing the child does not alter the parent", func(t *testing.T) {
|
||||
var rctx request.CTX = request.TestContext(t)
|
||||
rctxClone := rctx.Clone()
|
||||
rctxClone = RequestContextWithMaster(rctxClone)
|
||||
|
||||
assert.False(t, HasMaster(rctx.Context()))
|
||||
assert.True(t, HasMaster(rctxClone.Context()))
|
||||
})
|
||||
|
||||
t.Run("changing the parent does not alter the child", func(t *testing.T) {
|
||||
var rctx request.CTX = request.TestContext(t)
|
||||
rctxClone := rctx.Clone()
|
||||
rctx = RequestContextWithMaster(rctx)
|
||||
|
||||
assert.True(t, HasMaster(rctx.Context()))
|
||||
assert.False(t, HasMaster(rctxClone.Context()))
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user