mirror of
https://github.com/postmannen/ctrl.git
synced 2025-01-18 21:59:30 +00:00
added testCh to errrorKernel
This commit is contained in:
parent
fbbeb1a4ab
commit
f92e8a8e0a
5 changed files with 55 additions and 1 deletions
|
@ -24,6 +24,8 @@ type errorKernel struct {
|
||||||
|
|
||||||
// errorCh is used to report errors from a process
|
// errorCh is used to report errors from a process
|
||||||
errorCh chan errorEvent
|
errorCh chan errorEvent
|
||||||
|
// testCh is used within REQTest for receving data for tests.
|
||||||
|
testCh chan []byte
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
|
@ -36,6 +38,7 @@ func newErrorKernel(ctx context.Context, m *metrics) *errorKernel {
|
||||||
|
|
||||||
return &errorKernel{
|
return &errorKernel{
|
||||||
errorCh: make(chan errorEvent, 2),
|
errorCh: make(chan errorEvent, 2),
|
||||||
|
testCh: make(chan []byte),
|
||||||
ctx: ctxC,
|
ctx: ctxC,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
metrics: m,
|
metrics: m,
|
||||||
|
@ -229,7 +232,7 @@ type errorAction int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// errActionContinue is ment to be used when the a process
|
// errActionContinue is ment to be used when the a process
|
||||||
// can just continue without takig any special care.
|
// can just continue without taking any special care.
|
||||||
errActionContinue errorAction = iota
|
errActionContinue errorAction = iota
|
||||||
// TODO:
|
// TODO:
|
||||||
// errActionKill should log the error,
|
// errActionKill should log the error,
|
||||||
|
|
|
@ -114,6 +114,13 @@ func (p *processes) Start(proc process) {
|
||||||
go proc.spawnWorker()
|
go proc.spawnWorker()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
log.Printf("Starting REQTest subscriber: %#v\n", proc.node)
|
||||||
|
sub := newSubject(REQTest, string(proc.node))
|
||||||
|
proc := newProcess(proc.ctx, p.server, sub, processKindSubscriber, nil)
|
||||||
|
go proc.spawnWorker()
|
||||||
|
}
|
||||||
|
|
||||||
if proc.configuration.StartSubREQToFileAppend {
|
if proc.configuration.StartSubREQToFileAppend {
|
||||||
proc.startup.subREQToFileAppend(proc)
|
proc.startup.subREQToFileAppend(proc)
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,10 @@ const (
|
||||||
REQRelayInitial Method = "REQRelayInitial"
|
REQRelayInitial Method = "REQRelayInitial"
|
||||||
// REQNone is used when there should be no reply.
|
// REQNone is used when there should be no reply.
|
||||||
REQNone Method = "REQNone"
|
REQNone Method = "REQNone"
|
||||||
|
// REQTest is used only for testing to be able to grab the output
|
||||||
|
// of messages.
|
||||||
|
REQTest Method = "REQTest"
|
||||||
|
|
||||||
// REQPublicKey will get the public ed25519 key from a node.
|
// REQPublicKey will get the public ed25519 key from a node.
|
||||||
REQPublicKey Method = "REQPublicKey"
|
REQPublicKey Method = "REQPublicKey"
|
||||||
// REQPublicKeysGet will get all the public keys from central.
|
// REQPublicKeysGet will get all the public keys from central.
|
||||||
|
@ -126,6 +130,7 @@ const (
|
||||||
REQPublicKeysToNode Method = "REQPublicKeysToNode"
|
REQPublicKeysToNode Method = "REQPublicKeysToNode"
|
||||||
// REQAuthPublicKeysAllow
|
// REQAuthPublicKeysAllow
|
||||||
REQPublicKeysAllow Method = "REQPublicKeysAllow"
|
REQPublicKeysAllow Method = "REQPublicKeysAllow"
|
||||||
|
|
||||||
// REQAclAddCommand
|
// REQAclAddCommand
|
||||||
REQAclAddCommand = "REQAclAddCommand"
|
REQAclAddCommand = "REQAclAddCommand"
|
||||||
// REQAclDeleteCommand
|
// REQAclDeleteCommand
|
||||||
|
@ -276,6 +281,9 @@ func (m Method) GetMethodsAvailable() MethodsAvailable {
|
||||||
REQAclImport: methodREQAclImport{
|
REQAclImport: methodREQAclImport{
|
||||||
event: EventACK,
|
event: EventACK,
|
||||||
},
|
},
|
||||||
|
REQTest: methodREQTest{
|
||||||
|
event: EventACK,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -432,3 +432,32 @@ func (m methodREQTuiToConsole) handler(proc process, message Message, node strin
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
|
type methodREQTest struct {
|
||||||
|
event Event
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m methodREQTest) getKind() Event {
|
||||||
|
return m.event
|
||||||
|
}
|
||||||
|
|
||||||
|
// handler to be used as a reply method when testing requests.
|
||||||
|
// We can then within the test listen on the testCh for received
|
||||||
|
// data and validate it.
|
||||||
|
// If not test is listening the data will be dropped.
|
||||||
|
func (m methodREQTest) handler(proc process, message Message, node string) ([]byte, error) {
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
// Try to send the received message data on the test channel. If we
|
||||||
|
// have a test started the data will be read from the testCh.
|
||||||
|
// If no test is reading from the testCh the data will be dropped.
|
||||||
|
select {
|
||||||
|
case proc.errorKernel.testCh <- message.Data:
|
||||||
|
default:
|
||||||
|
// drop.
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
ackMsg := []byte("confirmed from: " + node + ": " + fmt.Sprint(message.ID))
|
||||||
|
return ackMsg, nil
|
||||||
|
}
|
||||||
|
|
7
requests_test.go
Normal file
7
requests_test.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package steward
|
||||||
|
|
||||||
|
func requestTest() {
|
||||||
|
type test struct {
|
||||||
|
want []byte
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue