代码拉取完成,页面将自动刷新
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,
)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。