Get tests to pass
This commit is contained in:
parent
9f878a16bf
commit
ab44bc78a2
|
@ -1,6 +1,7 @@
|
|||
package driver
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
|
@ -38,6 +39,31 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
}
|
||||
|
||||
// copyFile moves an existing file to the destination
|
||||
func copyFile(src, dst string, t *testing.T) {
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
defer in.Close()
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
defer func() {
|
||||
if err := out.Close(); err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
}()
|
||||
if _, err = io.Copy(out, in); err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
if err := out.Sync(); err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func testLogger() *log.Logger {
|
||||
return log.New(os.Stderr, "", log.LstdFlags)
|
||||
}
|
||||
|
|
|
@ -188,54 +188,6 @@ func TestExecDriver_Start_Wait(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestExecDriver_Start_Artifact_basic(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctestutils.ExecCompatible(t)
|
||||
file := "hi_linux_amd64"
|
||||
checksum := "sha256:6f99b4c5184726e601ecb062500aeb9537862434dfe1898dbe5c68d9f50c179c"
|
||||
|
||||
task := &structs.Task{
|
||||
Name: "sleep",
|
||||
Config: map[string]interface{}{
|
||||
"artifact_source": fmt.Sprintf("https://dl.dropboxusercontent.com/u/47675/jar_thing/%s?checksum=%s", file, checksum),
|
||||
"command": file,
|
||||
},
|
||||
LogConfig: &structs.LogConfig{
|
||||
MaxFiles: 10,
|
||||
MaxFileSizeMB: 10,
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
|
||||
driverCtx, execCtx := testDriverContexts(task)
|
||||
defer execCtx.AllocDir.Destroy()
|
||||
d := NewExecDriver(driverCtx)
|
||||
|
||||
handle, err := d.Start(execCtx, task)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if handle == nil {
|
||||
t.Fatalf("missing handle")
|
||||
}
|
||||
|
||||
// Update should be a no-op
|
||||
err = handle.Update(task)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Task should terminate quickly
|
||||
select {
|
||||
case res := <-handle.WaitCh():
|
||||
if !res.Successful() {
|
||||
t.Fatalf("err: %v", res)
|
||||
}
|
||||
case <-time.After(time.Duration(testutil.TestMultiplier()*5) * time.Second):
|
||||
t.Fatalf("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecDriver_Start_Wait_AllocDir(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctestutils.ExecCompatible(t)
|
||||
|
|
|
@ -58,9 +58,8 @@ func TestJavaDriver_StartOpen_Wait(t *testing.T) {
|
|||
task := &structs.Task{
|
||||
Name: "demo-app",
|
||||
Config: map[string]interface{}{
|
||||
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/demoapp.jar",
|
||||
"jvm_options": []string{"-Xmx64m", "-Xms32m"},
|
||||
"checksum": "sha256:58d6e8130308d32e197c5108edd4f56ddf1417408f743097c2e662df0f0b17c8",
|
||||
"jar_path": "demoapp.jar",
|
||||
"jvm_options": []string{"-Xmx64m", "-Xms32m"},
|
||||
},
|
||||
LogConfig: &structs.LogConfig{
|
||||
MaxFiles: 10,
|
||||
|
@ -73,6 +72,10 @@ func TestJavaDriver_StartOpen_Wait(t *testing.T) {
|
|||
defer execCtx.AllocDir.Destroy()
|
||||
d := NewJavaDriver(driverCtx)
|
||||
|
||||
// Copy the test jar into the task's directory
|
||||
dst, _ := execCtx.AllocDir.TaskDirs[task.Name]
|
||||
copyFile("./test-resources/java/demoapp.jar", filepath.Join(dst, "demoapp.jar"), t)
|
||||
|
||||
handle, err := d.Start(execCtx, task)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
@ -108,8 +111,7 @@ func TestJavaDriver_Start_Wait(t *testing.T) {
|
|||
task := &structs.Task{
|
||||
Name: "demo-app",
|
||||
Config: map[string]interface{}{
|
||||
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/demoapp.jar",
|
||||
"checksum": "sha256:58d6e8130308d32e197c5108edd4f56ddf1417408f743097c2e662df0f0b17c8",
|
||||
"jar_path": "demoapp.jar",
|
||||
},
|
||||
LogConfig: &structs.LogConfig{
|
||||
MaxFiles: 10,
|
||||
|
@ -119,9 +121,12 @@ func TestJavaDriver_Start_Wait(t *testing.T) {
|
|||
}
|
||||
|
||||
driverCtx, execCtx := testDriverContexts(task)
|
||||
defer execCtx.AllocDir.Destroy()
|
||||
d := NewJavaDriver(driverCtx)
|
||||
|
||||
// Copy the test jar into the task's directory
|
||||
dst, _ := execCtx.AllocDir.TaskDirs[task.Name]
|
||||
copyFile("./test-resources/java/demoapp.jar", filepath.Join(dst, "demoapp.jar"), t)
|
||||
|
||||
handle, err := d.Start(execCtx, task)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
@ -168,7 +173,7 @@ func TestJavaDriver_Start_Kill_Wait(t *testing.T) {
|
|||
task := &structs.Task{
|
||||
Name: "demo-app",
|
||||
Config: map[string]interface{}{
|
||||
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/demoapp.jar",
|
||||
"jar_path": "demoapp.jar",
|
||||
},
|
||||
LogConfig: &structs.LogConfig{
|
||||
MaxFiles: 10,
|
||||
|
@ -181,6 +186,10 @@ func TestJavaDriver_Start_Kill_Wait(t *testing.T) {
|
|||
defer execCtx.AllocDir.Destroy()
|
||||
d := NewJavaDriver(driverCtx)
|
||||
|
||||
// Copy the test jar into the task's directory
|
||||
dst, _ := execCtx.AllocDir.TaskDirs[task.Name]
|
||||
copyFile("./test-resources/java/demoapp.jar", filepath.Join(dst, "demoapp.jar"), t)
|
||||
|
||||
handle, err := d.Start(execCtx, task)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
|
|
@ -2,6 +2,7 @@ package driver
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/client/config"
|
||||
|
@ -37,13 +38,11 @@ func TestQemuDriver_Fingerprint(t *testing.T) {
|
|||
func TestQemuDriver_StartOpen_Wait(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctestutils.QemuCompatible(t)
|
||||
// TODO: use test server to load from a fixture
|
||||
task := &structs.Task{
|
||||
Name: "linux",
|
||||
Config: map[string]interface{}{
|
||||
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img",
|
||||
"checksum": "sha256:a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544",
|
||||
"accelerator": "tcg",
|
||||
"image_path": "linux-0.2.img",
|
||||
"accelerator": "tcg",
|
||||
"port_map": []map[string]int{{
|
||||
"main": 22,
|
||||
"web": 8080,
|
||||
|
@ -68,6 +67,10 @@ func TestQemuDriver_StartOpen_Wait(t *testing.T) {
|
|||
defer execCtx.AllocDir.Destroy()
|
||||
d := NewQemuDriver(driverCtx)
|
||||
|
||||
// Copy the test image into the task's directory
|
||||
dst, _ := execCtx.AllocDir.TaskDirs[task.Name]
|
||||
copyFile("./test-resources/qemu/linux-0.2.img", filepath.Join(dst, "linux-0.2.img"), t)
|
||||
|
||||
handle, err := d.Start(execCtx, task)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
@ -90,33 +93,3 @@ func TestQemuDriver_StartOpen_Wait(t *testing.T) {
|
|||
fmt.Printf("\nError killing Qemu test: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQemuDriver_RequiresMemory(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctestutils.QemuCompatible(t)
|
||||
// TODO: use test server to load from a fixture
|
||||
task := &structs.Task{
|
||||
Name: "linux",
|
||||
Config: map[string]interface{}{
|
||||
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img",
|
||||
"accelerator": "tcg",
|
||||
"host_port": "8080",
|
||||
"guest_port": "8081",
|
||||
"checksum": "sha256:a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544",
|
||||
// ssh u/p would be here
|
||||
},
|
||||
LogConfig: &structs.LogConfig{
|
||||
MaxFiles: 10,
|
||||
MaxFileSizeMB: 10,
|
||||
},
|
||||
}
|
||||
|
||||
driverCtx, execCtx := testDriverContexts(task)
|
||||
defer execCtx.AllocDir.Destroy()
|
||||
d := NewQemuDriver(driverCtx)
|
||||
|
||||
_, err := d.Start(execCtx, task)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error when not specifying memory")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ package driver
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
@ -99,57 +97,6 @@ func TestRawExecDriver_StartOpen_Wait(t *testing.T) {
|
|||
handle2.Kill()
|
||||
}
|
||||
|
||||
func TestRawExecDriver_Start_Artifact_basic(t *testing.T) {
|
||||
t.Parallel()
|
||||
path := testtask.Path()
|
||||
ts := httptest.NewServer(http.FileServer(http.Dir(filepath.Dir(path))))
|
||||
defer ts.Close()
|
||||
|
||||
file := filepath.Base(path)
|
||||
task := &structs.Task{
|
||||
Name: "sleep",
|
||||
Config: map[string]interface{}{
|
||||
"artifact_source": fmt.Sprintf("%s/%s", ts.URL, file),
|
||||
"command": file,
|
||||
"args": []string{"sleep", "1s"},
|
||||
},
|
||||
LogConfig: &structs.LogConfig{
|
||||
MaxFiles: 10,
|
||||
MaxFileSizeMB: 10,
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
testtask.SetTaskEnv(task)
|
||||
|
||||
driverCtx, execCtx := testDriverContexts(task)
|
||||
defer execCtx.AllocDir.Destroy()
|
||||
d := NewRawExecDriver(driverCtx)
|
||||
|
||||
handle, err := d.Start(execCtx, task)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if handle == nil {
|
||||
t.Fatalf("missing handle")
|
||||
}
|
||||
|
||||
// Attempt to open
|
||||
handle2, err := d.Open(execCtx, handle.ID())
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if handle2 == nil {
|
||||
t.Fatalf("missing handle")
|
||||
}
|
||||
|
||||
// Task should terminate quickly
|
||||
select {
|
||||
case <-handle2.WaitCh():
|
||||
case <-time.After(time.Duration(testutil.TestMultiplier()*5) * time.Second):
|
||||
t.Fatalf("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRawExecDriver_Start_Wait(t *testing.T) {
|
||||
t.Parallel()
|
||||
task := &structs.Task{
|
||||
|
|
|
@ -228,7 +228,7 @@ func (r *TaskRunner) run() {
|
|||
|
||||
for {
|
||||
// Download the task's artifacts
|
||||
if !r.artifactsDownloaded {
|
||||
if !r.artifactsDownloaded && len(r.task.Artifacts) > 0 {
|
||||
r.setState(structs.TaskStatePending, structs.NewTaskEvent(structs.TaskDownloadingArtifacts))
|
||||
taskDir, ok := r.ctx.AllocDir.TaskDirs[r.task.Name]
|
||||
if !ok {
|
||||
|
|
Loading…
Reference in a new issue