ffiwrapper: Test FD leaks
This commit is contained in:
parent
edb4a1ee9e
commit
57adda40f9
@ -8,7 +8,9 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -229,10 +231,14 @@ func getGrothParamFileAndVerifyingKeys(s abi.SectorSize) {
|
|||||||
// go test -run=^TestDownloadParams
|
// go test -run=^TestDownloadParams
|
||||||
//
|
//
|
||||||
func TestDownloadParams(t *testing.T) {
|
func TestDownloadParams(t *testing.T) {
|
||||||
|
defer requireFDsClosed(t, openFDs(t))
|
||||||
|
|
||||||
getGrothParamFileAndVerifyingKeys(sectorSize)
|
getGrothParamFileAndVerifyingKeys(sectorSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSealAndVerify(t *testing.T) {
|
func TestSealAndVerify(t *testing.T) {
|
||||||
|
defer requireFDsClosed(t, openFDs(t))
|
||||||
|
|
||||||
if runtime.NumCPU() < 10 && os.Getenv("CI") == "" { // don't bother on slow hardware
|
if runtime.NumCPU() < 10 && os.Getenv("CI") == "" { // don't bother on slow hardware
|
||||||
t.Skip("this is slow")
|
t.Skip("this is slow")
|
||||||
}
|
}
|
||||||
@ -301,6 +307,8 @@ func TestSealAndVerify(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSealPoStNoCommit(t *testing.T) {
|
func TestSealPoStNoCommit(t *testing.T) {
|
||||||
|
defer requireFDsClosed(t, openFDs(t))
|
||||||
|
|
||||||
if runtime.NumCPU() < 10 && os.Getenv("CI") == "" { // don't bother on slow hardware
|
if runtime.NumCPU() < 10 && os.Getenv("CI") == "" { // don't bother on slow hardware
|
||||||
t.Skip("this is slow")
|
t.Skip("this is slow")
|
||||||
}
|
}
|
||||||
@ -361,6 +369,8 @@ func TestSealPoStNoCommit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSealAndVerify2(t *testing.T) {
|
func TestSealAndVerify2(t *testing.T) {
|
||||||
|
defer requireFDsClosed(t, openFDs(t))
|
||||||
|
|
||||||
if runtime.NumCPU() < 10 && os.Getenv("CI") == "" { // don't bother on slow hardware
|
if runtime.NumCPU() < 10 && os.Getenv("CI") == "" { // don't bother on slow hardware
|
||||||
t.Skip("this is slow")
|
t.Skip("this is slow")
|
||||||
}
|
}
|
||||||
@ -430,3 +440,44 @@ func BenchmarkWriteWithAlignment(b *testing.B) {
|
|||||||
w()
|
w()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func openFDs(t *testing.T) int {
|
||||||
|
dent, err := ioutil.ReadDir("/proc/self/fd")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var skip int
|
||||||
|
for _, info := range dent {
|
||||||
|
l, err := os.Readlink(filepath.Join("/proc/self/fd", info.Name()))
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(l, "/dev/nvidia") {
|
||||||
|
skip++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(dent) - skip
|
||||||
|
}
|
||||||
|
|
||||||
|
func requireFDsClosed(t *testing.T, start int) {
|
||||||
|
openNow := openFDs(t)
|
||||||
|
|
||||||
|
if start != openNow {
|
||||||
|
dent, err := ioutil.ReadDir("/proc/self/fd")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
for _, info := range dent {
|
||||||
|
l, err := os.Readlink(filepath.Join("/proc/self/fd", info.Name()))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("FD err %s\n", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("FD %s -> %s\n", info.Name(), l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infow("open FDs", "start", start, "now", openNow)
|
||||||
|
require.Equal(t, start, openNow, "FDs shouldn't leak")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user