Beispiel #1
0
func starTestNewClient(t *testing.T, addr string, id int) *starTester {
	var err error
	bt := &starTester{id: id, rdoneq: make(chan bool), sdoneq: make(chan bool)}

	if bt.sock, err = star.NewSocket(); err != nil {
		t.Errorf("Failed getting client %d socket: %v", id, err)
		return nil
	}
	bt.sock.AddTransport(tcp.NewTransport())
	if err = bt.sock.Dial(addr); err != nil {
		t.Errorf("Failed client %d dialing: %v", id, err)
		bt.sock.Close()
		return nil
	}
	return bt
}
func testStarNonBlock(t *testing.T, addr string, tran mangos.Transport) {
	maxqlen := 2
	timeout := time.Second / 2

	rp, err := star.NewSocket()
	if err != nil {
		t.Errorf("Failed to make PUB: %v", err)
		return
	}
	defer rp.Close()
	rp.AddTransport(tran)

	// Now try setting the option
	err = rp.SetOption(mangos.OptionWriteQLen, maxqlen)
	if err != nil {
		t.Errorf("Failed set WriteQLen: %v", err)
		return
	}
	// At this point, we can issue requests on rq, and read them from rp.
	if err = rp.SetOption(mangos.OptionSendDeadline, timeout); err != nil {
		t.Errorf("Failed set recv deadline")
		return
	}
	if err = rp.Listen(addr); err != nil {
		t.Errorf("Failed listen: %v", err)
		return
	}

	msg := []byte{'A', 'B', 'C'}

	for i := 0; i < maxqlen*2; i++ {
		t.Logf("Sending #%d", i)
		if err := rp.Send(msg); err != nil {
			t.Errorf("Failed to send: %v", err)
		}
	}
}