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

+62
View File
@@ -0,0 +1,62 @@
package config
import (
"errors"
"fmt"
"sync"
"testing"
. "github.com/onsi/gomega"
)
func TestConfigSetManyConcurrent(t *testing.T) {
RegisterTestingT(t)
setupTestApp(t)
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] = SetMany(testAppName, map[string]string{fmt.Sprintf("KEY%d", i): "value"}, false, false)
}(i)
}
wg.Wait()
Expect(errors.Join(errs...)).NotTo(HaveOccurred())
for i := 0; i < count; i++ {
expectValue(testAppName, fmt.Sprintf("KEY%d", i), "value")
}
expectValue(testAppName, "testKey", "TESTING")
}
func TestConfigUnsetManyConcurrent(t *testing.T) {
RegisterTestingT(t)
setupTestApp(t)
const count = 20
entries := map[string]string{}
for i := 0; i < count; i++ {
entries[fmt.Sprintf("KEY%d", i)] = "value"
}
Expect(SetMany(testAppName, entries, false, false)).To(Succeed())
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] = UnsetMany(testAppName, []string{fmt.Sprintf("KEY%d", i)}, false)
}(i)
}
wg.Wait()
Expect(errors.Join(errs...)).NotTo(HaveOccurred())
for i := 0; i < count; i++ {
expectNoValue(testAppName, fmt.Sprintf("KEY%d", i))
}
expectValue(testAppName, "testKey", "TESTING")
}