lib: Apply config changes sequentially (ref #5298) (#7188)

This commit is contained in:
Simon Frei
2021-01-15 15:43:34 +01:00
committed by GitHub
parent b2d82da20d
commit f63cdbfcfa
20 changed files with 1032 additions and 790 deletions
+17 -12
View File
@@ -41,10 +41,20 @@ func (validationError) String() string {
return "validationError"
}
func TestReplaceCommit(t *testing.T) {
t.Skip("broken, fails randomly, #3834")
func replace(t testing.TB, w Wrapper, to Configuration) {
t.Helper()
waiter, err := w.Modify(func(cfg *Configuration) {
*cfg = to
})
if err != nil {
t.Fatal(err)
}
waiter.Wait()
}
func TestReplaceCommit(t *testing.T) {
w := wrap("/dev/null", Configuration{Version: 0}, device1)
defer w.stop()
if w.RawCopy().Version != 0 {
t.Fatal("Config incorrect")
}
@@ -52,10 +62,7 @@ func TestReplaceCommit(t *testing.T) {
// Replace config. We should get back a clean response and the config
// should change.
_, err := w.Replace(Configuration{Version: 1})
if err != nil {
t.Fatal("Should not have a validation error:", err)
}
replace(t, w, Configuration{Version: 1})
if w.RequiresRestart() {
t.Fatal("Should not require restart")
}
@@ -69,11 +76,7 @@ func TestReplaceCommit(t *testing.T) {
sub0 := requiresRestart{committed: make(chan struct{}, 1)}
w.Subscribe(sub0)
_, err = w.Replace(Configuration{Version: 2})
if err != nil {
t.Fatal("Should not have a validation error:", err)
}
replace(t, w, Configuration{Version: 1})
<-sub0.committed
if !w.RequiresRestart() {
t.Fatal("Should require restart")
@@ -87,7 +90,9 @@ func TestReplaceCommit(t *testing.T) {
w.Subscribe(validationError{})
_, err = w.Replace(Configuration{Version: 3})
_, err := w.Modify(func(cfg *Configuration) {
*cfg = Configuration{Version: 3}
})
if err == nil {
t.Fatal("Should have a validation error")
}