From e7b1d96d1310dbdf413061bed49521ef9bf35374 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sun, 28 Jan 2018 18:31:12 +0300 Subject: Context --- payload.go | 4 ++-- pipe_factory_test.go | 2 +- pool.go | 2 +- pool_test.go | 16 ++++++++-------- socket_factory_test.go | 4 ++-- worker.go | 6 +++--- worker_test.go | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/payload.go b/payload.go index 8b029e1d..cc714eb3 100644 --- a/payload.go +++ b/payload.go @@ -3,8 +3,8 @@ package roadrunner // Payload carries binary header and body to workers and // back to the server. type Payload struct { - // Head represent payload context, might be omitted - Head []byte + // Context represent payload context, might be omitted + Context []byte // Body contains binary payload to be processed by worker Body []byte diff --git a/pipe_factory_test.go b/pipe_factory_test.go index 6d3d9eeb..9d50e47f 100644 --- a/pipe_factory_test.go +++ b/pipe_factory_test.go @@ -78,7 +78,7 @@ func Test_Pipe_Echo(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, res) assert.NotNil(t, res.Body) - assert.Nil(t, res.Head) + assert.Nil(t, res.Context) assert.Equal(t, "hello", res.String()) } diff --git a/pool.go b/pool.go index 8dac6cf7..c2226420 100644 --- a/pool.go +++ b/pool.go @@ -109,7 +109,7 @@ func (p *Pool) Exec(rqs *Payload) (rsp *Payload, err error) { } // worker want's to be terminated - if rsp.Body == nil && rsp.Head != nil && string(rsp.Head) == StopRequest { + if rsp.Body == nil && rsp.Context != nil && string(rsp.Context) == StopRequest { go p.replaceWorker(w, err) return p.Exec(rqs) } diff --git a/pool_test.go b/pool_test.go index 9d9bcca8..8b936059 100644 --- a/pool_test.go +++ b/pool_test.go @@ -72,7 +72,7 @@ func Test_Pool_Echo(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, res) assert.NotNil(t, res.Body) - assert.Nil(t, res.Head) + assert.Nil(t, res.Context) assert.Equal(t, "hello", res.String()) } @@ -88,12 +88,12 @@ func Test_Pool_Echo_NilHead(t *testing.T) { assert.NotNil(t, p) assert.NoError(t, err) - res, err := p.Exec(&Payload{Body: []byte("hello"), Head: nil}) + res, err := p.Exec(&Payload{Body: []byte("hello"), Context: nil}) assert.NoError(t, err) assert.NotNil(t, res) assert.NotNil(t, res.Body) - assert.Nil(t, res.Head) + assert.Nil(t, res.Context) assert.Equal(t, "hello", res.String()) } @@ -109,14 +109,14 @@ func Test_Pool_Echo_Head(t *testing.T) { assert.NotNil(t, p) assert.NoError(t, err) - res, err := p.Exec(&Payload{Body: []byte("hello"), Head: []byte("world")}) + res, err := p.Exec(&Payload{Body: []byte("hello"), Context: []byte("world")}) assert.NoError(t, err) assert.NotNil(t, res) assert.Nil(t, res.Body) - assert.NotNil(t, res.Head) + assert.NotNil(t, res.Context) - assert.Equal(t, "world", string(res.Head)) + assert.Equal(t, "world", string(res.Context)) } func Test_Pool_JobError(t *testing.T) { @@ -218,7 +218,7 @@ func Test_Pool_Replace_Worker(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, res) assert.NotNil(t, res.Body) - assert.Nil(t, res.Head) + assert.Nil(t, res.Context) assert.NotEqual(t, lastPID, string(res.Body)) lastPID = string(res.Body) @@ -253,7 +253,7 @@ func Test_Pool_Stop_Worker(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, res) assert.NotNil(t, res.Body) - assert.Nil(t, res.Head) + assert.Nil(t, res.Context) assert.NotEqual(t, lastPID, string(res.Body)) lastPID = string(res.Body) diff --git a/socket_factory_test.go b/socket_factory_test.go index bb22e217..d0d643af 100644 --- a/socket_factory_test.go +++ b/socket_factory_test.go @@ -153,7 +153,7 @@ func Test_Tcp_Echo(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, res) assert.NotNil(t, res.Body) - assert.Nil(t, res.Head) + assert.Nil(t, res.Context) assert.Equal(t, "hello", res.String()) } @@ -296,7 +296,7 @@ func Test_Unix_Echo(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, res) assert.NotNil(t, res.Body) - assert.Nil(t, res.Head) + assert.Nil(t, res.Context) assert.Equal(t, "hello", res.String()) } diff --git a/worker.go b/worker.go index 7fa675af..df97871e 100644 --- a/worker.go +++ b/worker.go @@ -209,7 +209,7 @@ func (w *Worker) start() error { } func (w *Worker) execPayload(rqs *Payload) (rsp *Payload, err error) { - if err := sendHead(w.rl, rqs.Head); err != nil { + if err := sendHead(w.rl, rqs.Context); err != nil { return nil, errors.Wrap(err, "header error") } @@ -218,7 +218,7 @@ func (w *Worker) execPayload(rqs *Payload) (rsp *Payload, err error) { var pr goridge.Prefix rsp = new(Payload) - if rsp.Head, pr, err = w.rl.Receive(); err != nil { + if rsp.Context, pr, err = w.rl.Receive(); err != nil { return nil, errors.Wrap(err, "worker error") } @@ -227,7 +227,7 @@ func (w *Worker) execPayload(rqs *Payload) (rsp *Payload, err error) { } if pr.HasFlag(goridge.PayloadError) { - return nil, JobError(rsp.Head) + return nil, JobError(rsp.Context) } if rsp.Body, pr, err = w.rl.Receive(); err != nil { diff --git a/worker_test.go b/worker_test.go index af9ce663..de11226a 100644 --- a/worker_test.go +++ b/worker_test.go @@ -37,7 +37,7 @@ func Test_Echo(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, res) assert.NotNil(t, res.Body) - assert.Nil(t, res.Head) + assert.Nil(t, res.Context) assert.Equal(t, "hello", res.String()) } @@ -79,7 +79,7 @@ func Test_Echo_Slow(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, res) assert.NotNil(t, res.Body) - assert.Nil(t, res.Head) + assert.Nil(t, res.Context) assert.Equal(t, "hello", res.String()) } -- cgit v1.2.3