Skip to content

Commit

Permalink
tests: ensure exec tests pass valid task resources (#4992)
Browse files Browse the repository at this point in the history
Prior to 97f33bb, executor cgroup validation errors were
silently ignored.  Enforcing them reveals test cases that missed them.

This doesn't change customer facing contract, as resource struct is
is either configured or we default to 100 (much higher than 2).
  • Loading branch information
notnoop authored Dec 13, 2018
1 parent 5bcb24b commit 5ef81ed
Showing 1 changed file with 39 additions and 19 deletions.
58 changes: 39 additions & 19 deletions drivers/exec/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
"testing"
"time"

dtestutil "github.com/hashicorp/nomad/plugins/drivers/testutils"

"github.com/hashicorp/hcl2/hcl"
ctestutils "github.com/hashicorp/nomad/client/testutil"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/helper/testtask"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/drivers"
dtestutil "github.com/hashicorp/nomad/plugins/drivers/testutils"
"github.com/hashicorp/nomad/plugins/shared"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
"github.com/hashicorp/nomad/testutil"
Expand All @@ -34,6 +34,17 @@ func TestMain(m *testing.M) {
}
}

var testResources = &drivers.Resources{
NomadResources: &structs.Resources{
MemoryMB: 128,
CPU: 100,
},
LinuxResources: &drivers.LinuxResources{
MemoryLimitBytes: 134217728,
CPUShares: 100,
},
}

func TestExecDriver_Fingerprint_NonLinux(t *testing.T) {
if !testutil.IsTravis() {
t.Parallel()
Expand Down Expand Up @@ -84,8 +95,9 @@ func TestExecDriver_StartWait(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "test",
ID: uuid.Generate(),
Name: "test",
Resources: testResources,
}

taskConfig := map[string]interface{}{
Expand Down Expand Up @@ -116,8 +128,9 @@ func TestExecDriver_StartWaitStop(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "test",
ID: uuid.Generate(),
Name: "test",
Resources: testResources,
}

taskConfig := map[string]interface{}{
Expand Down Expand Up @@ -175,8 +188,9 @@ func TestExecDriver_StartWaitStopKill(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "test",
ID: uuid.Generate(),
Name: "test",
Resources: testResources,
}

taskConfig := map[string]interface{}{
Expand Down Expand Up @@ -235,8 +249,9 @@ func TestExecDriver_StartWaitRecover(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "test",
ID: uuid.Generate(),
Name: "test",
Resources: testResources,
}

taskConfig := map[string]interface{}{
Expand Down Expand Up @@ -304,8 +319,9 @@ func TestExecDriver_Stats(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "test",
ID: uuid.Generate(),
Name: "test",
Resources: testResources,
}

taskConfig := map[string]interface{}{
Expand Down Expand Up @@ -337,8 +353,9 @@ func TestExecDriver_Start_Wait_AllocDir(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "sleep",
ID: uuid.Generate(),
Name: "sleep",
Resources: testResources,
}
cleanup := harness.MkAllocDir(task, false)
defer cleanup()
Expand Down Expand Up @@ -385,9 +402,10 @@ func TestExecDriver_User(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "sleep",
User: "alice",
ID: uuid.Generate(),
Name: "sleep",
User: "alice",
Resources: testResources,
}
cleanup := harness.MkAllocDir(task, false)
defer cleanup()
Expand Down Expand Up @@ -418,8 +436,9 @@ func TestExecDriver_HandlerExec(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "sleep",
ID: uuid.Generate(),
Name: "sleep",
Resources: testResources,
}
cleanup := harness.MkAllocDir(task, false)
defer cleanup()
Expand Down Expand Up @@ -507,6 +526,7 @@ func TestExecDriver_DevicesAndMounts(t *testing.T) {
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "test",
Resources: testResources,
StdoutPath: filepath.Join(tmpDir, "task-stdout"),
StderrPath: filepath.Join(tmpDir, "task-stderr"),
Devices: []*drivers.DeviceConfig{
Expand Down

0 comments on commit 5ef81ed

Please sign in to comment.