mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: handle potential DB conflict due to concurrent upload requests in postFile (#19005)
This issue manifests when users have multiple templates which rely on the same files, for example see: https://github.com/coder/coder/issues/17442 --------- Signed-off-by: Callum Styan <callumstyan@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/http"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -69,6 +70,30 @@ func TestPostFiles(t *testing.T) {
|
||||
_, err = client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader(data))
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("InsertConcurrent", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := coderdtest.New(t, nil)
|
||||
_ = coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
|
||||
defer cancel()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
var end sync.WaitGroup
|
||||
wg.Add(1)
|
||||
end.Add(3)
|
||||
for range 3 {
|
||||
go func() {
|
||||
wg.Wait()
|
||||
data := make([]byte, 1024)
|
||||
_, err := client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader(data))
|
||||
end.Done()
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
}
|
||||
wg.Done()
|
||||
end.Wait()
|
||||
})
|
||||
}
|
||||
|
||||
func TestDownload(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user