status-go/profiling/profiling_test.go

59 lines
1.2 KiB
Go
Raw Permalink Normal View History

2017-09-01 14:09:11 +00:00
package profiling
import (
"os"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestProfilingCPU(t *testing.T) {
dir := t.TempDir()
2017-09-01 14:09:11 +00:00
err := StartCPUProfile(dir)
2017-09-01 14:09:11 +00:00
require.NoError(t, err)
// Block for a bit to collect some metrics.
time.Sleep(time.Second)
err = StopCPUProfile()
require.NoError(t, err)
// Verify that the file has some content.
file, err := os.Open(filepath.Join(dir, CPUFilename))
require.NoError(t, err)
defer func() {
err := file.Close()
require.NoError(t, err)
}()
2017-09-01 14:09:11 +00:00
t.Logf("CPU profile saved in %s for %s", filepath.Join(dir, CPUFilename), os.Args[0])
info, err := file.Stat()
require.NoError(t, err)
require.True(t, info.Size() > 0, "a file with CPU profile is empty")
}
func TestProfilingMem(t *testing.T) {
dir := t.TempDir()
2017-09-01 14:09:11 +00:00
err := WriteHeapFile(dir)
2017-09-01 14:09:11 +00:00
require.NoError(t, err)
// Verify that the file has some content.
file, err := os.Open(filepath.Join(dir, MemFilename))
require.NoError(t, err)
defer func() {
err := file.Close()
require.NoError(t, err)
}()
2017-09-01 14:09:11 +00:00
t.Logf("Memory profile saved in %s for %s", filepath.Join(dir, MemFilename), os.Args[0])
info, err := file.Stat()
require.NoError(t, err)
require.True(t, info.Size() > 0, "a file with memory profile is empty")
}