Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(900)

Side by Side Diff: src/pkg/net/net_test.go

Issue 5136052: code review 5136052: net: add shutdown: TCPConn.CloseWrite and CloseRead (Closed)
Patch Set: diff -r 6c5c19791fae https://go.googlecode.com/hg/ Created 13 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/net/fd_windows.go ('k') | src/pkg/net/tcpsock_posix.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package net 5 package net
6 6
7 import ( 7 import (
8 "flag" 8 "flag"
9 "os"
9 "regexp" 10 "regexp"
10 "testing" 11 "testing"
11 ) 12 )
12 13
13 var runErrorTest = flag.Bool("run_error_test", false, "let TestDialError check f or dns errors") 14 var runErrorTest = flag.Bool("run_error_test", false, "let TestDialError check f or dns errors")
14 15
15 type DialErrorTest struct { 16 type DialErrorTest struct {
16 Net string 17 Net string
17 Raddr string 18 Raddr string
18 Pattern string 19 Pattern string
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 t.Errorf("#%d: expected <nil>, got %q (error)", i, e) 113 t.Errorf("#%d: expected <nil>, got %q (error)", i, e)
113 } 114 }
114 if e != nil && e.(*DNSError).Error != tt.ErrPrefix { 115 if e != nil && e.(*DNSError).Error != tt.ErrPrefix {
115 t.Errorf("#%d: expected %q, got %q (mismatched error)", i, tt.ErrPrefix, e.(*DNSError).Error) 116 t.Errorf("#%d: expected %q, got %q (mismatched error)", i, tt.ErrPrefix, e.(*DNSError).Error)
116 } 117 }
117 if a != tt.Reverse { 118 if a != tt.Reverse {
118 t.Errorf("#%d: expected %q, got %q (reverse address)", i , tt.Reverse, a) 119 t.Errorf("#%d: expected %q, got %q (reverse address)", i , tt.Reverse, a)
119 } 120 }
120 } 121 }
121 } 122 }
123
124 func TestShutdown(t *testing.T) {
125 l, err := Listen("tcp", "127.0.0.1:0")
126 if err != nil {
127 if l, err = Listen("tcp6", "[::1]:0"); err != nil {
128 t.Fatalf("ListenTCP on :0: %v", err)
129 }
130 }
131
132 go func() {
133 c, err := l.Accept()
134 if err != nil {
135 t.Fatalf("Accept: %v", err)
136 }
137 var buf [10]byte
138 n, err := c.Read(buf[:])
139 if n != 0 || err != os.EOF {
140 t.Fatalf("server Read = %d, %v; want 0, os.EOF", n, err)
141 }
142 c.Write([]byte("response"))
143 c.Close()
144 }()
145
146 c, err := Dial("tcp", l.Addr().String())
147 if err != nil {
148 t.Fatalf("Dial: %v", err)
149 }
150 defer c.Close()
151
152 err = c.(*TCPConn).CloseWrite()
153 if err != nil {
154 t.Fatalf("CloseWrite: %v", err)
155 }
156 var buf [10]byte
157 n, err := c.Read(buf[:])
158 if err != nil {
159 t.Fatalf("client Read: %d, %v", n, err)
160 }
161 got := string(buf[:n])
162 if got != "response" {
163 t.Errorf("read = %q, want \"response\"", got)
164 }
165 }
OLDNEW
« no previous file with comments | « src/pkg/net/fd_windows.go ('k') | src/pkg/net/tcpsock_posix.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b