github.com/awesome-flow/flow@v0.0.3-0.20190918184116-508d75d68a2c/pkg/corev1alpha1/actor/receiver_unix_test.go (about) 1 package actor 2 3 import ( 4 "reflect" 5 "testing" 6 7 core "github.com/awesome-flow/flow/pkg/corev1alpha1" 8 coretest "github.com/awesome-flow/flow/pkg/corev1alpha1/test" 9 testutil "github.com/awesome-flow/flow/pkg/util/test" 10 flowtest "github.com/awesome-flow/flow/pkg/util/test/corev1alpha1" 11 ) 12 13 func TestUnixHandleConn(t *testing.T) { 14 nthreads := 4 15 ctx, err := coretest.NewContextWithConfig(map[string]interface{}{}) 16 if err != nil { 17 t.Fatalf("failed to create context: %s", err) 18 } 19 rcv, err := NewReceiverUnix("receiver", ctx, core.Params{ 20 "bind": "/never/where", 21 }) 22 if err != nil { 23 t.Fatalf("failed to create Unix receiver: %s", err) 24 } 25 26 peer, err := flowtest.NewTestActor("test-actor", ctx, core.Params{}) 27 if err != nil { 28 t.Fatalf("failed to create test actor: %s", err) 29 } 30 mailbox := make(chan *core.Message) 31 peer.(*flowtest.TestActor).OnReceive(func(msg *core.Message) { 32 msg.Complete(core.MsgStatusDone) 33 mailbox <- msg 34 peer.(*flowtest.TestActor).Flush() 35 }) 36 if err := rcv.Connect(nthreads, peer); err != nil { 37 t.Fatalf("failed to connect test actor: %s", err) 38 } 39 40 conn := newTestConn( 41 newTestAddr("unix", "/never/where"), 42 newTestAddr("unix", "/never/where"), 43 ) 44 45 body := testutil.RandBytes(1024) 46 if _, err := conn.Write(body); err != nil { 47 t.Fatalf("failed to write body data to test conn: %s", err) 48 } 49 50 rcv.(*ReceiverUnix).handleConn(conn) 51 msg := <-mailbox 52 53 if !reflect.DeepEqual(msg.Body(), body) { 54 t.Fatalf("unexpected mesage body: got: %s, want: %s", msg.Body(), body) 55 } 56 }