MCPcopy Index your code
hub / github.com/tailscale/tailscale / TestTimeout

Function TestTimeout

cmd/testwrapper/testwrapper_test.go:359–391  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

357}
358
359func TestTimeout(t *testing.T) {
360 t.Parallel()
361
362 // Construct our broken package.
363 testfile := filepath.Join(t.TempDir(), "timeout_test.go")
364 code := []byte(`package noretry_test
365
366import (
367 "testing"
368 "time"
369)
370
371func TestTimeout(t *testing.T) {
372 time.Sleep(500 * time.Millisecond)
373}
374`)
375 err := os.WriteFile(testfile, code, 0o644)
376 if err != nil {
377 t.Fatalf("writing package: %s", err)
378 }
379
380 out, err := cmdTestwrapper(t, testfile, "-timeout=20ms").CombinedOutput()
381 if code, ok := errExitCode(err); !ok || code != 1 {
382 t.Fatalf("testwrapper %s: expected error with exit code 1 but got: %v; output was:\n%s", testfile, err, out)
383 }
384 if want := "panic: test timed out after 20ms"; !bytes.Contains(out, []byte(want)) {
385 t.Fatalf("testwrapper %s: expected timeout panic containing %q but got:\n%s", testfile, want, out)
386 }
387
388 if testing.Verbose() {
389 t.Logf("success - output:\n%s", out)
390 }
391}
392
393func TestCached(t *testing.T) {
394 t.Parallel()

Callers

nothing calls this directly

Calls 8

cmdTestwrapperFunction · 0.85
errExitCodeFunction · 0.85
CombinedOutputMethod · 0.80
TempDirMethod · 0.65
WriteFileMethod · 0.65
FatalfMethod · 0.65
LogfMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…