github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/common/fdlimit/fdlimit_test.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 package fdlimit 13 14 import ( 15 "fmt" 16 "testing" 17 ) 18 19 // TestFileDescriptorLimits simply tests whether the file descriptor allowance 20 // per this process can be retrieved. 21 func TestFileDescriptorLimits(t *testing.T) { 22 target := 4096 23 hardlimit, err := Maximum() 24 if err != nil { 25 t.Fatal(err) 26 } 27 if hardlimit < target { 28 t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target)) 29 } 30 31 if limit, err := Current(); err != nil || limit <= 0 { 32 t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err) 33 } 34 if err := Raise(uint64(target)); err != nil { 35 t.Fatalf("failed to raise file allowance") 36 } 37 if limit, err := Current(); err != nil || limit < target { 38 t.Fatalf("failed to retrieve raised descriptor limit (have %v, want %v): %v", limit, target, err) 39 } 40 }