MCPcopy Create free account
hub / github.com/google/pprof / TestNewTempFile

Function TestNewTempFile

internal/driver/tempfile_test.go:9–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestNewTempFile(t *testing.T) {
10 const n = 100
11 // Line up ready to execute goroutines with a read-write lock.
12 var mu sync.RWMutex
13 mu.Lock()
14 var wg sync.WaitGroup
15 errc := make(chan error, n)
16 for i := 0; i < n; i++ {
17 wg.Add(1)
18 go func() {
19 mu.RLock()
20 defer mu.RUnlock()
21 defer wg.Done()
22 f, err := newTempFile(os.TempDir(), "profile", ".tmp")
23 errc <- err
24 deferDeleteTempFile(f.Name())
25 f.Close()
26 }()
27 }
28 // Start the file creation race.
29 mu.Unlock()
30 // Wait for the goroutines to finish.
31 wg.Wait()
32
33 for i := 0; i < n; i++ {
34 if err := <-errc; err != nil {
35 t.Fatalf("newTempFile(): got %v, want no error", err)
36 }
37 }
38 if len(tempFiles) != n {
39 t.Errorf("len(tempFiles): got %d, want %d", len(tempFiles), n)
40 }
41 names := map[string]bool{}
42 for _, name := range tempFiles {
43 if names[name] {
44 t.Errorf("got temp file %s created multiple times", name)
45 break
46 }
47 names[name] = true
48 }
49 if err := cleanupTempFiles(); err != nil {
50 t.Errorf("cleanupTempFiles(): got error %v, want no error", err)
51 }
52 if len(tempFiles) != 0 {
53 t.Errorf("len(tempFiles) after the cleanup: got %d, want 0", len(tempFiles))
54 }
55}

Callers

nothing calls this directly

Calls 5

newTempFileFunction · 0.85
deferDeleteTempFileFunction · 0.85
cleanupTempFilesFunction · 0.85
NameMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…