Example #1
0
func TestReadAfterClose(t *testing.T) {
	laddr, raddr := chooseInterfaces(t)
	c1, c2 := connPair(laddr, raddr)
	mr, err := AllocateMemory(8192)
	if err != nil {
		panic(err)
	}
	if err := c2.Close(); err != nil {
		panic(err)
	}
	c1.SetTimeout(10e9)
	for i := 0; i < 100; i++ {
		fmt.Printf("reading\n")
		err = c1.Read(mr)
		fmt.Printf("read returned\n")
		if err == nil {
			panic("expected a read error")
		}
		if t, ok := err.(timeout); ok && t.Timeout() {
			err = nil
			continue
		} else {
			break
		}
	}
	if err == nil {
		panic("expected a non-timeout read error")
	}
	fmt.Printf("read error: %+v\n", err)
	if err := c1.Close(); err != nil {
		panic(err)
	}
	if err := mr.Close(); err != nil {
		panic(err)
	}
}