summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-11-26 01:59:47 +0300
committerValery Piashchynski <[email protected]>2020-11-26 01:59:47 +0300
commitd68d0473cc804110627aa8adf680ea260adf5d40 (patch)
treed72e404e6b534c49bfa79e7b988b45f0f24e5a5f
parent5a689337cc557d6d57e20277cac1e31b6878e142 (diff)
Apply fixes for golangci warnings
-rwxr-xr-xworker.go96
-rwxr-xr-xworker_test.go114
2 files changed, 1 insertions, 209 deletions
diff --git a/worker.go b/worker.go
index 8cfc05a8..4b9ef962 100755
--- a/worker.go
+++ b/worker.go
@@ -2,7 +2,6 @@ package roadrunner
import (
"bytes"
- //"bytes"
"context"
"fmt"
"os"
@@ -120,10 +119,8 @@ type WorkerProcess struct {
// can be nil while process is not started.
pid int
- // errBuffer aggregates stderr output from underlying process. Value can be
+ // stderr aggregates stderr output from underlying process. Value can be
// receive only once command is completed and all pipes are closed.
- // errBuffer *errBuffer
-
stderr *bytes.Buffer
// channel is being closed once command is complete.
@@ -155,10 +152,6 @@ func InitBaseWorker(cmd *exec.Cmd) (WorkerBase, error) {
// small buffer optimization
// at this point we know, that stderr will contain huge messages
w.stderr.Grow(1024)
- //w.errBuffer = newErrBuffer(w.logCallback)
-
- // piping all stderr to command errBuffer
- //w.cmd.Stderr = w.errBuffer
w.cmd.Stderr = w
return w, nil
@@ -177,10 +170,6 @@ func (w *WorkerProcess) Created() time.Time {
// AddListener registers new worker event listener.
func (w *WorkerProcess) AddListener(listener util.EventListener) {
w.events.AddListener(listener)
-
- //w.errBuffer.mu.Lock()
- //w.errBuffer.enable = true
- //w.errBuffer.mu.Unlock()
}
// State return receive-only WorkerProcess state object, state can be used to safely access
@@ -222,9 +211,7 @@ func (w *WorkerProcess) Start() error {
if err != nil {
return err
}
-
w.pid = w.cmd.Process.Pid
-
return nil
}
@@ -248,11 +235,6 @@ func (w *WorkerProcess) Wait(ctx context.Context) error {
w.stderr.Truncate(0)
}
- // if no errors in the events, error might be in the errBuffer
- //if w.errBuffer.Len() > 0 {
- // err = multierr.Append(err, errors.New(w.errBuffer.String()))
- //}
-
return multierr.Append(err, w.closeRelay())
}
@@ -287,7 +269,6 @@ func (w *WorkerProcess) Stop(ctx context.Context) error {
go func() {
var err error
- //w.errBuffer.Close()
w.state.Set(StateStopping)
err = multierr.Append(err, sendControl(w.relay, &stopCommand{Stop: true}))
if err != nil {
@@ -321,22 +302,6 @@ func (w *WorkerProcess) Kill() error {
return nil
}
-//func (w *WorkerProcess) logCallback(log []byte) {
-// w.events.Push(WorkerEvent{Event: EventWorkerLog, Worker: w, Payload: log})
-//}
-
-// Len returns the number of buf of the unread portion of the errBuffer;
-// buf.Len() == len(buf.Bytes()).
-//func (w *WorkerProcess) Len() int {
-// //eb.mu.RLock()
-// //defer eb.mu.RUnlock()
-//
-// // currently active message
-// return len(w.stderr)
-//}
-// Writer is the interface that wraps the basic Write method.
-//
-
// Write appends the contents of pool to the errBuffer, growing the errBuffer as
// needed. The return value n is the length of pool; errBuffer is always nil.
func (w *WorkerProcess) Write(p []byte) (int, error) {
@@ -344,65 +309,6 @@ func (w *WorkerProcess) Write(p []byte) (int, error) {
defer w.mu.Unlock()
w.events.Push(WorkerEvent{Event: EventWorkerLog, Worker: w, Payload: p})
w.stderr.Write(p)
- //eb.mu.Unlock()
- //eb.update <- nil
return len(p), nil
}
-
-// Close aggregation timer.
-//func (w *WorkerProcess) Close() {
-// //close(eb.stop)
-//}
-
-// thread safe errBuffer
-//type errBuffer struct {
-// enable bool
-// mu sync.RWMutex
-// buf []byte
-// last int
-// wait *time.Timer
-// // todo: remove update
-// update chan interface{}
-// stop chan interface{}
-// logCallback func(log []byte)
-//}
-//
-//func newErrBuffer(logCallback func(log []byte)) *errBuffer {
-// eb := &errBuffer{
-// buf: make([]byte, 0),
-// update: make(chan interface{}),
-// wait: time.NewTimer(WaitDuration),
-// stop: make(chan interface{}),
-// logCallback: logCallback,
-// }
-//
-// go func(eb *errBuffer) {
-// for {
-// select {
-// case <-eb.update:
-// eb.wait.Reset(WaitDuration)
-// case <-eb.wait.C:
-// eb.mu.Lock()
-// if eb.enable && len(eb.buf) > eb.last {
-// eb.logCallback(eb.buf[eb.last:])
-// eb.buf = eb.buf[0:0]
-// eb.last = len(eb.buf)
-// }
-// eb.mu.Unlock()
-// case <-eb.stop:
-// eb.wait.Stop()
-//
-// eb.mu.Lock()
-// if eb.enable && len(eb.buf) > eb.last {
-// eb.logCallback(eb.buf[eb.last:])
-// eb.last = len(eb.buf)
-// }
-// eb.mu.Unlock()
-// return
-// }
-// }
-// }(eb)
-//
-// return eb
-//}
diff --git a/worker_test.go b/worker_test.go
index 43bb8b65..b8bd4c8b 100755
--- a/worker_test.go
+++ b/worker_test.go
@@ -64,117 +64,3 @@ func Test_OnStarted(t *testing.T) {
assert.Equal(t, "can't attach to running process", err.Error())
}
-
-//func TestErrBuffer_Write_Len(t *testing.T) {
-// buf := newErrBuffer(nil)
-// defer func() {
-// buf.Close()
-// }()
-//
-// _, err := buf.Write([]byte("hello"))
-// if err != nil {
-// t.Errorf("fail to write: error %v", err)
-// }
-// assert.Equal(t, 5, buf.Len())
-// assert.Equal(t, "hello", buf.String())
-//}
-//
-//func TestErrBuffer_Write_Event(t *testing.T) {
-// buf := newErrBuffer(nil)
-// defer func() {
-// buf.Close()
-// }()
-//
-// wg := &sync.WaitGroup{}
-// wg.Add(1)
-// buf.logCallback = func(log []byte) {
-// assert.Equal(t, []byte("hello\n"), log)
-// wg.Done()
-// }
-// buf.enable = true
-//
-// _, err := buf.Write([]byte("hello\n"))
-// if err != nil {
-// t.Errorf("fail to write: error %v", err)
-// }
-//
-// wg.Wait()
-//
-// // messages are read
-// assert.Equal(t, 0, buf.Len())
-//}
-//
-//func TestErrBuffer_Write_Event_Separated(t *testing.T) {
-// buf := newErrBuffer(nil)
-// defer func() {
-// buf.Close()
-// }()
-//
-// wg := &sync.WaitGroup{}
-// wg.Add(1)
-//
-// buf.logCallback = func(log []byte) {
-// assert.Equal(t, []byte("hello\nending"), log)
-// wg.Done()
-// }
-// buf.enable = true
-//
-// _, err := buf.Write([]byte("hel"))
-// if err != nil {
-// t.Errorf("fail to write: error %v", err)
-// }
-//
-// _, err = buf.Write([]byte("lo\n"))
-// if err != nil {
-// t.Errorf("fail to write: error %v", err)
-// }
-//
-// _, err = buf.Write([]byte("ending"))
-// if err != nil {
-// t.Errorf("fail to write: error %v", err)
-// }
-//
-// wg.Wait()
-// assert.Equal(t, 0, buf.Len())
-// assert.Equal(t, "", buf.String())
-//}
-//
-//func TestErrBuffer_Write_Event_Separated_NoListener(t *testing.T) {
-// buf := newErrBuffer(nil)
-// defer func() {
-// buf.Close()
-// }()
-//
-// _, err := buf.Write([]byte("hel"))
-// if err != nil {
-// t.Errorf("fail to write: error %v", err)
-// }
-//
-// _, err = buf.Write([]byte("lo\n"))
-// if err != nil {
-// t.Errorf("fail to write: error %v", err)
-// }
-//
-// _, err = buf.Write([]byte("ending"))
-// if err != nil {
-// t.Errorf("fail to write: error %v", err)
-// }
-//
-// assert.Equal(t, 12, buf.Len())
-// assert.Equal(t, "hello\nending", buf.String())
-//}
-//
-//func TestErrBuffer_Write_Remaining(t *testing.T) {
-// buf := newErrBuffer(nil)
-// defer func() {
-// buf.Close()
-// }()
-//
-// _, err := buf.Write([]byte("hel"))
-// if err != nil {
-// t.Errorf("fail to write: error %v", err)
-// }
-//
-// assert.Equal(t, 3, buf.Len())
-// assert.Equal(t, "hel", buf.String())
-//}