From 486d33631e8ab0d1e60c9d57f729a6205937f478 Mon Sep 17 00:00:00 2001 From: fahedouch Date: Sun, 24 Nov 2019 00:40:04 +0100 Subject: [PATCH] test runtime v2 CPU settings Signed-off-by: fahedouch --- runtime/v2/shim/shim_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/runtime/v2/shim/shim_test.go b/runtime/v2/shim/shim_test.go index 282059c76..23a962a82 100644 --- a/runtime/v2/shim/shim_test.go +++ b/runtime/v2/shim/shim_test.go @@ -18,9 +18,30 @@ package shim import ( "context" + "os" + "runtime" "testing" ) +func TestRuntimeWithEmptyMaxEnvProcs(t *testing.T) { + + os.Setenv("GOMAXPROCS", "") + setRuntime() + var oldGoMaxProcs = runtime.GOMAXPROCS(0) + if oldGoMaxProcs != 2 { + t.Fatal("the max number of procs should be 2") + } +} + +func TestRuntimeWithNonEmptyMaxEnvProcs(t *testing.T) { + os.Setenv("GOMAXPROCS", "not_empty") + setRuntime() + var oldGoMaxProcs2 = runtime.GOMAXPROCS(0) + if oldGoMaxProcs2 != runtime.NumCPU() { + t.Fatal("the max number CPU should be equal to available CPUs") + } +} + func TestShimOptWithValue(t *testing.T) { ctx := context.TODO() ctx = context.WithValue(ctx, OptsKey{}, Opts{Debug: true})