1 Star 0 Fork 0

CNCF/devstatscode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
threads_test.go 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
package devstatscode
import (
"testing"
lib "github.com/cncf/devstatscode"
)
func TestGetThreadsNum(t *testing.T) {
// Environment context parse
var ctx lib.Ctx
ctx.Init()
ctx.TestMode = true
// Get actual number of threads available
nThreads := lib.GetThreadsNum(&ctx)
// Set context's ST/NCPUs manually (don't need to repeat tests from context_test.go)
var testCases = []struct {
ST bool
NCPUs int
expected int
}{
{ST: false, NCPUs: 0, expected: nThreads},
{ST: false, NCPUs: 1, expected: 1},
{ST: false, NCPUs: -1, expected: nThreads},
{ST: false, NCPUs: 2, expected: 2},
{ST: true, NCPUs: 0, expected: 1},
{ST: true, NCPUs: 1, expected: 1},
{ST: true, NCPUs: -1, expected: 1},
{ST: true, NCPUs: 2, expected: 2},
{ST: true, NCPUs: nThreads + 1, expected: nThreads},
}
// Execute test cases
for index, test := range testCases {
ctx.ST = test.ST
ctx.NCPUs = test.NCPUs
expected := test.expected
got := lib.GetThreadsNum(&ctx)
if got != expected {
t.Errorf(
"test number %d, expected to return %d threads, got %d (default is %d on this machine)",
index+1, expected, got, nThreads,
)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cncf/devstatscode.git
git@gitee.com:cncf/devstatscode.git
cncf
devstatscode
devstatscode
master

搜索帮助