Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
815231b1
Commit
815231b1
authored
Oct 20, 2015
by
Paulo L F Casaretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test app.SetCPU function
parent
0feb0d92
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
app/app_test.go
app/app_test.go
+42
-0
No files found.
app/app_test.go
0 → 100644
View file @
815231b1
package
app_test
import
(
"runtime"
"testing"
"github.com/mholt/caddy/app"
)
func
TestSetCPU
(
t
*
testing
.
T
)
{
currentCPU
:=
runtime
.
GOMAXPROCS
(
-
1
)
maxCPU
:=
runtime
.
NumCPU
()
for
i
,
test
:=
range
[]
struct
{
input
string
output
int
shouldErr
bool
}{
{
"1"
,
1
,
false
},
{
"-1"
,
currentCPU
,
true
},
{
"0"
,
currentCPU
,
true
},
{
"100%"
,
maxCPU
,
false
},
{
"50%"
,
int
(
0.5
*
float32
(
maxCPU
)),
false
},
{
"110%"
,
currentCPU
,
true
},
{
"-10%"
,
currentCPU
,
true
},
{
"invalid input"
,
currentCPU
,
true
},
{
"invalid input%"
,
currentCPU
,
true
},
{
"9999"
,
maxCPU
,
false
},
// over available CPU
}
{
err
:=
app
.
SetCPU
(
test
.
input
)
if
test
.
shouldErr
&&
err
==
nil
{
t
.
Errorf
(
"Test %d: Expected error, but there wasn't any"
,
i
)
}
if
!
test
.
shouldErr
&&
err
!=
nil
{
t
.
Errorf
(
"Test %d: Expected no error, but there was one: %v"
,
i
,
err
)
}
if
actual
,
expected
:=
runtime
.
GOMAXPROCS
(
-
1
),
test
.
output
;
actual
!=
expected
{
t
.
Errorf
(
"Test %d: GOMAXPROCS was %d but expected %d"
,
i
,
actual
,
expected
)
}
// teardown
runtime
.
GOMAXPROCS
(
currentCPU
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment