github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/utilities/common/fdlimit/fdlimit_test.go (about)

     1  package fdlimit
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func TestFileDescriptorLimits(t *testing.T) {
     9  	target := 4096
    10  	hardlimit, err := Maximum()
    11  	if err != nil {
    12  		t.Fatal(err)
    13  	}
    14  	if hardlimit < target {
    15  		t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target))
    16  	}
    17  
    18  	if limit, err := Current(); err != nil || limit <= 0 {
    19  		t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err)
    20  	}
    21  	if err := Raise(uint64(target)); err != nil {
    22  		t.Fatalf("failed to raise file allowance")
    23  	}
    24  	if limit, err := Current(); err != nil || limit < target {
    25  		t.Fatalf("failed to retrieve raised descriptor limit (have %v, want %v): %v", limit, target, err)
    26  	}
    27  }