Ejemplo n.º 1
0
func TestAbstractIpc(t *testing.T) {

	var sb, sc *zmq.Socket
	defer func() {
		for _, s := range []*zmq.Socket{sb, sc} {
			if s != nil {
				s.SetLinger(0)
				s.Close()
			}
		}
	}()

	addr := "ipc://@/tmp/tester"

	// This is Linux only
	if runtime.GOOS != "linux" {
		t.Skip("Only on Linux")
	}

	sb, err := zmq.NewSocket(zmq.PAIR)
	if err != nil {
		t.Fatal("NewSocket:", err)
	}

	err = sb.Bind(addr)
	if err != nil {
		t.Fatal("sb.Bind:", err)
	}

	endpoint, err := sb.GetLastEndpoint()
	expected := "ipc://@/tmp/tester"
	if endpoint != expected || err != nil {
		t.Fatalf("sb.GetLastEndpoint: expected 'nil' %q, got '%v' %q", expected, err, endpoint)
		return
	}

	sc, err = zmq.NewSocket(zmq.PAIR)
	if err != nil {
		t.Fatal("NewSocket:", err)
	}
	err = sc.Connect(addr)
	if err != nil {
		t.Fatal("sc.Bind:", err)
	}

	resp, err := bounce(sb, sc)
	if err != nil {
		t.Error(resp, err)
	}

	err = sc.Close()
	sc = nil
	if err != nil {
		t.Fatal("sc.Close:", err)
	}

	err = sb.Close()
	sb = nil
	if err != nil {
		t.Fatal("sb.Close:", err)
	}
}