mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
Set clean config for mock driver
The default job here contains some exec task config (for setting command and args) that aren't used for mock driver. Now, the alloc runner seems stricter about validating fields and errors on unexpected fields. Updating configs in tests so we can have an explicit task config whenever driver is set explicitly.
This commit is contained in:
@@ -157,8 +157,10 @@ func TestAllocRunner_DeploymentHealth_Unhealthy_Deadline(t *testing.T) {
|
||||
// Make the task block
|
||||
task := ar.alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["start_block_for"] = "4s"
|
||||
task.Config["run_for"] = "10s"
|
||||
task.Config = map[string]interface{}{
|
||||
"start_block_for": "4s",
|
||||
"run_for": "10s",
|
||||
}
|
||||
|
||||
// Make the alloc be part of a deployment
|
||||
ar.alloc.DeploymentID = uuid.Generate()
|
||||
@@ -216,7 +218,9 @@ func TestAllocRunner_DeploymentHealth_Healthy_NoChecks(t *testing.T) {
|
||||
// Make the task run healthy
|
||||
task := ar.alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "10s"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "10s",
|
||||
}
|
||||
|
||||
// Create a task that takes longer to become healthy
|
||||
ar.alloc.Job.TaskGroups[0].Tasks = append(ar.alloc.Job.TaskGroups[0].Tasks, task.Copy())
|
||||
@@ -264,7 +268,9 @@ func TestAllocRunner_DeploymentHealth_Healthy_Checks(t *testing.T) {
|
||||
// Make the task fail
|
||||
task := ar.alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "10s"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "10s",
|
||||
}
|
||||
|
||||
// Create a task that has no checks
|
||||
ar.alloc.Job.TaskGroups[0].Tasks = append(ar.alloc.Job.TaskGroups[0].Tasks, task.Copy())
|
||||
@@ -357,7 +363,9 @@ func TestAllocRunner_DeploymentHealth_Unhealthy_Checks(t *testing.T) {
|
||||
// Make the task fail
|
||||
task := ar.alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "10s"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "10s",
|
||||
}
|
||||
|
||||
// Make the alloc be part of a deployment
|
||||
ar.alloc.DeploymentID = uuid.Generate()
|
||||
@@ -426,7 +434,9 @@ func TestAllocRunner_DeploymentHealth_Healthy_UpdatedDeployment(t *testing.T) {
|
||||
// Make the task run healthy
|
||||
task := ar.alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "30s"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "30s",
|
||||
}
|
||||
|
||||
// Make the alloc be part of a deployment
|
||||
ar.alloc.DeploymentID = uuid.Generate()
|
||||
@@ -484,7 +494,9 @@ func TestAllocRunner_DeploymentHealth_Healthy_Migration(t *testing.T) {
|
||||
tg := ar.alloc.Job.TaskGroups[0]
|
||||
task := tg.Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "30s"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "30s",
|
||||
}
|
||||
|
||||
// Shorten the default migration healthy time
|
||||
tg.Migrate = structs.DefaultMigrateStrategy()
|
||||
@@ -530,7 +542,9 @@ func TestAllocRunner_DeploymentHealth_BatchDisabled(t *testing.T) {
|
||||
|
||||
task := tg.Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "5s"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "5s",
|
||||
}
|
||||
upd, ar := TestAllocRunnerFromAlloc(t, alloc, false)
|
||||
|
||||
go ar.Run()
|
||||
@@ -621,7 +635,9 @@ func TestAllocRunner_TerminalUpdate_Destroy(t *testing.T) {
|
||||
// Ensure task takes some time
|
||||
task := ar.alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "10s"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "10s",
|
||||
}
|
||||
go ar.Run()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
@@ -720,7 +736,9 @@ func TestAllocRunner_Destroy(t *testing.T) {
|
||||
// Ensure task takes some time
|
||||
task := ar.alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "10s"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "10s",
|
||||
}
|
||||
go ar.Run()
|
||||
start := time.Now()
|
||||
|
||||
@@ -779,7 +797,9 @@ func TestAllocRunner_Update(t *testing.T) {
|
||||
// Ensure task takes some time
|
||||
task := ar.alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "10s"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "10s",
|
||||
}
|
||||
go ar.Run()
|
||||
defer ar.Destroy()
|
||||
|
||||
@@ -880,7 +900,9 @@ func TestAllocRunner_SaveRestoreState_TerminalAlloc(t *testing.T) {
|
||||
// Ensure task takes some time
|
||||
ar.alloc.Job.TaskGroups[0].Tasks[0].Driver = "mock_driver"
|
||||
task := ar.alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Config["run_for"] = "10s"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "10s",
|
||||
}
|
||||
go ar.Run()
|
||||
defer ar.Destroy()
|
||||
|
||||
|
||||
@@ -86,7 +86,9 @@ func testTaskRunner(t *testing.T, restarts bool) *taskRunnerTestCtx {
|
||||
alloc := mock.Alloc()
|
||||
task := alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "500ms"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "500ms",
|
||||
}
|
||||
return testTaskRunnerFromAlloc(t, restarts, alloc)
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,8 @@ func TestAllocRunner(t *testing.T, restarts bool) (*MockAllocStateUpdater, *Allo
|
||||
alloc := mock.Alloc()
|
||||
task := alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "500ms"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "500ms",
|
||||
}
|
||||
return TestAllocRunnerFromAlloc(t, alloc, restarts)
|
||||
}
|
||||
|
||||
@@ -123,7 +123,9 @@ func TestPrevAlloc_LocalPrevAlloc(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
conf.Alloc.Job.TaskGroups[0].Tasks[0].Driver = "mock_driver"
|
||||
conf.Alloc.Job.TaskGroups[0].Tasks[0].Config["run_for"] = "500ms"
|
||||
conf.Alloc.Job.TaskGroups[0].Tasks[0].Config = map[string]interface{}{
|
||||
"run_for": "500ms",
|
||||
}
|
||||
|
||||
waiter := NewAllocWatcher(conf)
|
||||
|
||||
|
||||
@@ -570,8 +570,9 @@ func TestClient_SaveRestoreState(t *testing.T) {
|
||||
alloc1.Job = job
|
||||
alloc1.JobID = job.ID
|
||||
alloc1.Job.TaskGroups[0].Tasks[0].Driver = "mock_driver"
|
||||
task := alloc1.Job.TaskGroups[0].Tasks[0]
|
||||
task.Config["run_for"] = "10s"
|
||||
alloc1.Job.TaskGroups[0].Tasks[0].Config = map[string]interface{}{
|
||||
"run_for": "10s",
|
||||
}
|
||||
|
||||
state := s1.State()
|
||||
if err := state.UpsertJob(100, job); err != nil {
|
||||
|
||||
@@ -86,7 +86,9 @@ func TestFS_Stat(t *testing.T) {
|
||||
a := mock.Alloc()
|
||||
task := a.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "500ms"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "500ms",
|
||||
}
|
||||
c.addAlloc(a, "")
|
||||
|
||||
// Wait for the client to start it
|
||||
@@ -225,7 +227,9 @@ func TestFS_List(t *testing.T) {
|
||||
a := mock.Alloc()
|
||||
task := a.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
task.Config["run_for"] = "500ms"
|
||||
task.Config = map[string]interface{}{
|
||||
"run_for": "500ms",
|
||||
}
|
||||
c.addAlloc(a, "")
|
||||
|
||||
// Wait for the client to start it
|
||||
|
||||
@@ -372,7 +372,9 @@ func TestAllocGarbageCollector_MaxAllocs(t *testing.T) {
|
||||
state := server.State()
|
||||
job := mock.Job()
|
||||
job.TaskGroups[0].Tasks[0].Driver = "mock_driver"
|
||||
job.TaskGroups[0].Tasks[0].Config["run_for"] = "30s"
|
||||
job.TaskGroups[0].Tasks[0].Config = map[string]interface{}{
|
||||
"run_for": "30s",
|
||||
}
|
||||
nodeID := client.Node().ID
|
||||
if err := state.UpsertJob(98, job); err != nil {
|
||||
t.Fatalf("error upserting job: %v", err)
|
||||
|
||||
@@ -444,7 +444,9 @@ func TestHTTP_AllocSnapshot_Atomic(t *testing.T) {
|
||||
state := s.server.State()
|
||||
alloc := mock.Alloc()
|
||||
alloc.Job.TaskGroups[0].Tasks[0].Driver = "mock_driver"
|
||||
alloc.Job.TaskGroups[0].Tasks[0].Config["run_for"] = "30s"
|
||||
alloc.Job.TaskGroups[0].Tasks[0].Config = map[string]interface{}{
|
||||
"run_for": "30s",
|
||||
}
|
||||
alloc.NodeID = s.client.NodeID()
|
||||
state.UpsertJobSummary(998, mock.JobSummary(alloc.JobID))
|
||||
if err := state.UpsertAllocs(1000, []*structs.Allocation{alloc.Copy()}); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user