Source file src/syscall/rlimit_test.go

     1  // Copyright 2022 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build unix
     6  
     7  package syscall_test
     8  
     9  import (
    10  	"os"
    11  	"runtime"
    12  	"testing"
    13  )
    14  
    15  func TestOpenFileLimit(t *testing.T) {
    16  	// For open file count,
    17  	// macOS sets the default soft limit to 256 and no hard limit.
    18  	// CentOS and Fedora set the default soft limit to 1024,
    19  	// with hard limits of 4096 and 524288, respectively.
    20  	// Check that we can open 1200 files, which proves
    21  	// that the rlimit is being raised appropriately on those systems.
    22  	fileCount := 1200
    23  
    24  	// OpenBSD has a default soft limit of 512 and hard limit of 1024.
    25  	if runtime.GOOS == "openbsd" {
    26  		fileCount = 768
    27  	}
    28  
    29  	var files []*os.File
    30  	for i := 0; i < fileCount; i++ {
    31  		f, err := os.Open("rlimit.go")
    32  		if err != nil {
    33  			t.Error(err)
    34  			break
    35  		}
    36  		files = append(files, f)
    37  	}
    38  
    39  	for _, f := range files {
    40  		f.Close()
    41  	}
    42  }
    43  

View as plain text