summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-07-08 20:38:01 -0700
committerWolfy-J <[email protected]>2018-07-08 20:38:01 -0700
commitdafe0c3f4877c25157b5df4ca69eb23df248ab7a (patch)
treec3796aea78bb489cb06fa5da846196a178fe5df9
parent9f59155c781f0178e52c53abd2b437d40c51a52d (diff)
better error buffer
-rw-r--r--cmd/rr/debug/debugger.go2
-rw-r--r--error_buffer.go3
-rw-r--r--error_buffer_test.go15
-rw-r--r--service/injector.go2
4 files changed, 18 insertions, 4 deletions
diff --git a/cmd/rr/debug/debugger.go b/cmd/rr/debug/debugger.go
index 0dca43de..533a5947 100644
--- a/cmd/rr/debug/debugger.go
+++ b/cmd/rr/debug/debugger.go
@@ -58,7 +58,7 @@ func (s *debugger) listener(event int, ctx interface{}) {
// outputs
switch event {
case roadrunner.EventStderrOutput:
- s.logger.Warning(strings.Trim(string(ctx.([]byte)), "\r\n"))
+ s.logger.Warning(utils.Sprintf("<yellow+h>%s</reset>", strings.Trim(string(ctx.([]byte)), "\r\n")))
}
// rr server events
diff --git a/error_buffer.go b/error_buffer.go
index 8be9c5a8..211fe25f 100644
--- a/error_buffer.go
+++ b/error_buffer.go
@@ -43,7 +43,9 @@ func newErrBuffer() *errBuffer {
if len(eb.buf) > eb.last {
if eb.lsn != nil {
eb.lsn(EventStderrOutput, eb.buf[eb.last:])
+ eb.buf = eb.buf[0:0]
}
+
eb.last = len(eb.buf)
}
eb.mu.Unlock()
@@ -55,6 +57,7 @@ func newErrBuffer() *errBuffer {
if eb.lsn != nil {
eb.lsn(EventStderrOutput, eb.buf[eb.last:])
}
+
eb.last = len(eb.buf)
}
eb.mu.Unlock()
diff --git a/error_buffer_test.go b/error_buffer_test.go
index 09ea4f03..81107935 100644
--- a/error_buffer_test.go
+++ b/error_buffer_test.go
@@ -30,8 +30,7 @@ func TestErrBuffer_Write_Event(t *testing.T) {
<-tr
// messages are read
- assert.Equal(t, 6, buf.Len())
- assert.Equal(t, "hello\n", buf.String())
+ assert.Equal(t, 0, buf.Len())
}
func TestErrBuffer_Write_Event_Separated(t *testing.T) {
@@ -50,6 +49,18 @@ func TestErrBuffer_Write_Event_Separated(t *testing.T) {
buf.Write([]byte("ending"))
<-tr
+ assert.Equal(t, 0, buf.Len())
+ assert.Equal(t, "", buf.String())
+}
+
+func TestErrBuffer_Write_Event_Separated_NoListener(t *testing.T) {
+ buf := newErrBuffer()
+ defer buf.Close()
+
+ buf.Write([]byte("hel"))
+ buf.Write([]byte("lo\n"))
+ buf.Write([]byte("ending"))
+
assert.Equal(t, 12, buf.Len())
assert.Equal(t, "hello\nending", buf.String())
}
diff --git a/service/injector.go b/service/injector.go
index e7dfaa0b..2d18b651 100644
--- a/service/injector.go
+++ b/service/injector.go
@@ -77,7 +77,7 @@ func injectValues(m reflect.Method, s interface{}, cfg Config, c *container) (va
// looking for the service candidate
for _, e := range c.services {
- if v.ConvertibleTo(reflect.ValueOf(e.svc).Type()) {
+ if v.ConvertibleTo(reflect.ValueOf(e.svc).Type()) && e.hasStatus(StatusOK) {
found = true
values = append(values, reflect.ValueOf(e.svc))
break