timeout_probe.go
TEXT FILE533 B · Public source code for developers, search crawlers and AI agents
1//go:build ignore
2
3package main
4
5import (
6 "context"
7 "fmt"
8 "net/http"
9 "net/http/httptest"
10 "time"
11)
12
13func main() {
14 s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
15 time.Sleep(200 * time.Millisecond)
16 fmt.Fprintln(w, "ok")
17 }))
18 defer s.Close()
19 ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
20 defer cancel()
21 req, _ := http.NewRequestWithContext(ctx, "GET", s.URL, nil)
22 _, err := http.DefaultClient.Do(req)
23 fmt.Println("expected timeout:", err != nil)
24}Read-only source · Select a line number to link directly · Raw download above
