status-go/profiling/profiling_test.go
Alex Kohler 365bc662a2 Enable gometalinter on tests and fix static analysis issues #631 (#644)
* Enable gometalinter on tests and fix static analysis issues

* Remove unneeded change

* Fix additional lint errors

* Add nolint directives and error checks

* Add error assertions instead of nolint directives

* Go back to using lint directive for loop.Run goroutine

* Add error check to loop.Run
2018-02-12 13:16:06 +02:00

61 lines
1.4 KiB
Go

package profiling
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestProfilingCPU(t *testing.T) {
dir, err := ioutil.TempDir("", "profiling")
require.NoError(t, err)
err = StartCPUProfile(dir)
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)
}()
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, err := ioutil.TempDir("", "profiling")
require.NoError(t, err)
err = WriteHeapFile(dir)
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)
}()
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")
}