mirror of
https://github.com/docker/docs.git
synced 2026-11-05 00:14:17 +03:00
inmem: a message is simply 1 opcode + an array of binary strings.
Remove redundant `Data` field. Every argument can be arbitrary data. Signed-off-by: Solomon Hykes <solomon@docker.com>
This commit is contained in:
@@ -18,7 +18,6 @@ type Receiver interface {
|
||||
type Message struct {
|
||||
Name string
|
||||
Args []string
|
||||
Data []byte
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -27,18 +27,15 @@ func TestSimpleSend(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(msg.Data) != "hello world" {
|
||||
t.Fatalf("%#v", *msg)
|
||||
}
|
||||
if msg.Name != "print" {
|
||||
t.Fatalf("%#v", *msg)
|
||||
}
|
||||
if len(msg.Args) != 0 {
|
||||
if msg.Args[0] != "hello world" {
|
||||
t.Fatalf("%#v", *msg)
|
||||
}
|
||||
assertMode(t, in, out, 0)
|
||||
}()
|
||||
in, out, err := w.Send(&Message{Name: "print", Data: []byte("hello world")}, 0)
|
||||
in, out, err := w.Send(&Message{Name: "print", Args: []string{"hello world"}}, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -94,7 +91,7 @@ func TestSendReply(t *testing.T) {
|
||||
// Send
|
||||
go func() {
|
||||
// Send a message with mode=R
|
||||
in, out, err := w.Send(&Message{Data: []byte("this is the request")}, R)
|
||||
in, out, err := w.Send(&Message{Args: []string{"this is the request"}}, R)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -104,7 +101,7 @@ func TestSendReply(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(resp.Data) != "this is the reply" {
|
||||
if resp.Args[0] != "this is the reply" {
|
||||
t.Fatalf("%#v", resp)
|
||||
}
|
||||
}()
|
||||
@@ -113,12 +110,12 @@ func TestSendReply(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(msg.Data) != "this is the request" {
|
||||
if msg.Args[0] != "this is the request" {
|
||||
t.Fatalf("%#v", msg)
|
||||
}
|
||||
assertMode(t, in, out, W)
|
||||
// Send a reply
|
||||
_, _, err = out.Send(&Message{Data: []byte("this is the reply")}, 0)
|
||||
_, _, err = out.Send(&Message{Args: []string{"this is the reply"}}, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -133,13 +130,13 @@ func TestSendNested(t *testing.T) {
|
||||
// Send
|
||||
go func() {
|
||||
// Send a message with mode=W
|
||||
in, out, err := w.Send(&Message{Data: []byte("this is the request")}, W)
|
||||
in, out, err := w.Send(&Message{Args: []string{"this is the request"}}, W)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertMode(t, in, out, W)
|
||||
// Send a nested message
|
||||
_, _, err = out.Send(&Message{Data: []byte("this is the nested message")}, 0)
|
||||
_, _, err = out.Send(&Message{Args: []string{"this is the nested message"}}, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -149,7 +146,7 @@ func TestSendNested(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(msg.Data) != "this is the request" {
|
||||
if msg.Args[0] != "this is the request" {
|
||||
t.Fatalf("%#v", msg)
|
||||
}
|
||||
assertMode(t, in, out, R)
|
||||
@@ -158,7 +155,7 @@ func TestSendNested(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(nested.Data) != "this is the nested message" {
|
||||
if nested.Args[0] != "this is the nested message" {
|
||||
t.Fatalf("%#v", nested)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
// StackSender forwards beam messages to a dynamic list of backend receivers.
|
||||
// New backends are stacked on top. When a message is sent, each backend is
|
||||
// tried until one succeeds. Any failing backends encountered along the way
|
||||
// tried until one succeeds. Any failing backends encountered along the way
|
||||
// are removed from the queue.
|
||||
type StackSender struct {
|
||||
stack *list.List
|
||||
@@ -92,7 +92,7 @@ func (s *StackSender) Len() int {
|
||||
return s.stack.Len()
|
||||
}
|
||||
var len int
|
||||
for e := s.front; e != nil ; e = e.Next() {
|
||||
for e := s.front; e != nil; e = e.Next() {
|
||||
len++
|
||||
}
|
||||
return len
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestSendStack(t *testing.T) {
|
||||
t.Fatalf("%#v", msg)
|
||||
}
|
||||
}()
|
||||
_, _, err := s.Send(&Message{"hello", []string{"wonderful", "world"}, nil}, 0)
|
||||
_, _, err := s.Send(&Message{"hello", []string{"wonderful", "world"}}, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user