...

Source file src/github.com/containerd/cgroups/v2/pidsv2_test.go

Documentation: github.com/containerd/cgroups/v2

     1  /*
     2     Copyright The containerd Authors.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package v2
    18  
    19  import (
    20  	"fmt"
    21  	"os"
    22  	"strconv"
    23  	"testing"
    24  )
    25  
    26  func TestCgroupv2PidsStats(t *testing.T) {
    27  	checkCgroupMode(t)
    28  	group := "/pids-test-cg"
    29  	groupPath := fmt.Sprintf("%s-%d", group, os.Getpid())
    30  	var max int64 = 1000
    31  	res := Resources{
    32  		Pids: &Pids{
    33  			Max: max,
    34  		},
    35  	}
    36  	c, err := NewManager(defaultCgroup2Path, groupPath, &res)
    37  	if err != nil {
    38  		t.Fatal("failed to init new cgroup manager: ", err)
    39  	}
    40  	defer os.Remove(c.path)
    41  
    42  	checkFileContent(t, c.path, "pids.max", strconv.Itoa(int(max)))
    43  }
    44  
    45  func TestSystemdCgroupPidsController(t *testing.T) {
    46  	checkCgroupMode(t)
    47  	group := fmt.Sprintf("testing-pids-%d.scope", os.Getpid())
    48  	pid := os.Getpid()
    49  	res := Resources{}
    50  	c, err := NewSystemd("", group, pid, &res)
    51  	if err != nil {
    52  		t.Fatal("failed to init new cgroup systemd manager: ", err)
    53  	}
    54  	checkFileContent(t, c.path, "cgroup.procs", strconv.Itoa(pid))
    55  }
    56  

View as plain text