| // Copyright 2020 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| "golang.org/x/tools/internal/stack/stacktest" |
| func TestIdleTimeout(t *testing.T) { |
| ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| ln, err := net.Listen("tcp", "localhost:0") |
| connect := func() net.Conn { |
| conn, err := net.DialTimeout("tcp", ln.Addr().String(), 5*time.Second) |
| server := HandlerServer(MethodNotFound) |
| // connTimer := &fakeTimer{c: make(chan time.Time, 1)} |
| runErr = Serve(ctx, ln, server, 100*time.Millisecond) |
| // Exercise some connection/disconnection patterns, and then assert that when |
| // our timer fires, the server exits. |
| if runErr != ErrIdleTimeout { |
| t.Errorf("run() returned error %v, want %v", runErr, ErrIdleTimeout) |