engine: Rewrite the core algorithm
The engine core had some unfortunate bugs that were the result of some early design errors when I wasn't as familiar with channels. I've finally rewritten most of the bad parts, and I think it's much more logical and stable now. This also simplifies the resource API, since more of the work is done completely in the engine, and hidden from view. Lastly, this adds a few new metaparameters and associated code. There are still some open problems left to solve, but hopefully this brings us one step closer.
This commit is contained in:
@@ -28,7 +28,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/purpleidea/mgmt/engine"
|
||||
"github.com/purpleidea/mgmt/engine/event"
|
||||
"github.com/purpleidea/mgmt/util"
|
||||
)
|
||||
|
||||
@@ -220,36 +219,33 @@ func TestResources1(t *testing.T) {
|
||||
|
||||
readyChan := make(chan struct{})
|
||||
eventChan := make(chan struct{})
|
||||
eventsChan := make(chan *event.Msg)
|
||||
doneChan := make(chan struct{})
|
||||
debug := testing.Verbose() // set via the -test.v flag to `go test`
|
||||
logf := func(format string, v ...interface{}) {
|
||||
t.Logf(fmt.Sprintf("test #%d: Res: ", index)+format, v...)
|
||||
}
|
||||
init := &engine.Init{
|
||||
Running: func() error {
|
||||
Running: func() {
|
||||
close(readyChan)
|
||||
select { // this always sends one!
|
||||
case eventChan <- struct{}{}:
|
||||
|
||||
}
|
||||
return nil
|
||||
},
|
||||
// Watch runs this to send a changed event.
|
||||
Event: func() error {
|
||||
Event: func() {
|
||||
select {
|
||||
case eventChan <- struct{}{}:
|
||||
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
// Watch listens on this for close/pause events.
|
||||
Events: eventsChan,
|
||||
Debug: debug,
|
||||
Logf: logf,
|
||||
Done: doneChan,
|
||||
Debug: debug,
|
||||
Logf: logf,
|
||||
|
||||
// unused
|
||||
Dirty: func() {},
|
||||
Recv: func() map[string]*engine.Send {
|
||||
return map[string]*engine.Send{}
|
||||
},
|
||||
@@ -341,7 +337,7 @@ func TestResources1(t *testing.T) {
|
||||
}
|
||||
}
|
||||
t.Logf("test #%d: shutting down Watch", index)
|
||||
close(eventsChan) // send Watch shutdown command
|
||||
close(doneChan) // send Watch shutdown command
|
||||
}()
|
||||
Loop:
|
||||
for {
|
||||
|
||||
Reference in New Issue
Block a user