fix: serialize concurrent property updates

Concurrent commands for the same app could each read a setting, change it, and write it back, so all of them exited successfully while silently dropping changes made by the others. Updates to app settings are now serialized so every change is kept, and readers never see a partially written value.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-10-21 21:21:57 -04:00
1 parent ba1d49576b
commit 9df45f6a6e
42 files changed
+1698 -642

No files matched your search

@@ -0,0 +1,72 @@
package dockeroptions
import (
"errors"
"fmt"
"sync"
"testing"
)
func TestAddDockerOptionToPhasesConcurrent(t *testing.T) {
const appName = "race-test"
setupReportEnv(t, appName)
const count = 20
var wg sync.WaitGroup
errs := make([]error, count)
for i := 0; i < count; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
errs[i] = AddDockerOptionToPhases(appName, []string{"deploy", "run"}, fmt.Sprintf("--label=race%d", i))
}(i)
}
wg.Wait()
if err := errors.Join(errs...); err != nil {
t.Fatalf("AddDockerOptionToPhases: %v", err)
}
for _, phase := range []string{"deploy", "run"} {
options, err := GetDockerOptionsForPhase(appName, phase)
if err != nil {
t.Fatalf("GetDockerOptionsForPhase(%s): %v", phase, err)
}
if len(options) != count {
t.Fatalf("%s phase has %d options, want %d: %v", phase, len(options), count, options)
}
}
}
func TestRemoveDockerOptionFromPhasesConcurrent(t *testing.T) {
const appName = "race-test"
setupReportEnv(t, appName)
const count = 20
for i := 0; i < count; i++ {
if err := AddDockerOptionToPhases(appName, []string{"deploy"}, fmt.Sprintf("--label=race%d", i)); err != nil {
t.Fatalf("AddDockerOptionToPhases: %v", err)
}
}
var wg sync.WaitGroup
errs := make([]error, count)
for i := 0; i < count; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
errs[i] = RemoveDockerOptionFromPhases(appName, []string{"deploy"}, fmt.Sprintf("--label=race%d", i))
}(i)
}
wg.Wait()
if err := errors.Join(errs...); err != nil {
t.Fatalf("RemoveDockerOptionFromPhases: %v", err)
}
options, err := GetDockerOptionsForPhase(appName, "deploy")
if err != nil {
t.Fatalf("GetDockerOptionsForPhase: %v", err)
}
if len(options) != 0 {
t.Fatalf("deploy phase still has options: %v", options)
}
}