Skip to content

Commit

Permalink
better cancel test for hpc compute backends
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstruck authored and buchanae committed Feb 12, 2018
1 parent 0de7f8b commit e55c5af
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 19 deletions.
9 changes: 4 additions & 5 deletions tests/funnel_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (f *Funnel) ReadFile(name string) string {
}

// StartServerInDocker starts a funnel server in a docker image
func (f *Funnel) StartServerInDocker(imageName string, extraArgs []string) {
func (f *Funnel) StartServerInDocker(containerName, imageName string, extraArgs []string) {
var funnelBinary string
var err error
gopath := os.Getenv("GOPATH")
Expand Down Expand Up @@ -360,7 +360,7 @@ func (f *Funnel) StartServerInDocker(imageName string, extraArgs []string) {
args := []string{
"run", "-i", "--rm",
"--group-add", fmt.Sprintf("%d", gid),
"--name", "funnel-test-server-" + RandomString(6),
"--name", containerName,
"-p", fmt.Sprintf("%d:%d", httpPort, httpPort),
"-p", fmt.Sprintf("%d:%d", rpcPort, rpcPort),
"-v", "/var/run/docker.sock:/var/run/docker.sock",
Expand Down Expand Up @@ -431,10 +431,9 @@ func (f *Funnel) killTestServerContainers(ids []string) {
}

// CleanupTestServerContainer stops the docker container running the test funnel server
func (f *Funnel) CleanupTestServerContainer() {
func (f *Funnel) CleanupTestServerContainer(containerName string) {
f.Cleanup()
s := f.findTestServerContainers()
f.killTestServerContainers(s)
f.killTestServerContainers([]string{containerName})
return
}

Expand Down
19 changes: 15 additions & 4 deletions tests/gridengine/gridengine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e
import (
"context"
"os"
"os/exec"
"testing"

"github.com/ohsu-comp-bio/funnel/logger"
Expand All @@ -11,6 +12,7 @@ import (
)

var fun *tests.Funnel
var serverName string

func TestMain(m *testing.M) {
conf := tests.DefaultConfig()
Expand All @@ -21,8 +23,9 @@ func TestMain(m *testing.M) {
}

fun = tests.NewFunnel(conf)
fun.StartServerInDocker("ohsucompbio/gridengine:latest", []string{})
defer fun.CleanupTestServerContainer()
serverName = "funnel-test-server-" + tests.RandomString(6)
fun.StartServerInDocker(serverName, "ohsucompbio/gridengine:latest", []string{})
defer fun.CleanupTestServerContainer(serverName)

m.Run()
return
Expand Down Expand Up @@ -69,8 +72,16 @@ func TestCancel(t *testing.T) {
}

task := fun.Wait(id)

if task.State != tes.State_CANCELED {
t.Fatal("expected task to get canceled")
t.Error("expected task to get canceled")
}

bid := task.Logs[0].Metadata["gridengine_id"]
cmd := exec.Command("docker", "exec", "-e", "SGE_ROOT=/usr/share/gridengine", serverName, "qstat", "-j", bid)
out, err := cmd.Output()
t.Log("cmd output:", string(out))
t.Log("error:", err)
if err == nil {
t.Error("expected error from qstat command")
}
}
20 changes: 16 additions & 4 deletions tests/htcondor/htcondor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package htcondor
import (
"context"
"os"
"os/exec"
"strings"
"testing"

"github.com/ohsu-comp-bio/funnel/logger"
Expand All @@ -11,6 +13,7 @@ import (
)

var fun *tests.Funnel
var serverName string

func TestMain(m *testing.M) {
conf := tests.DefaultConfig()
Expand All @@ -21,8 +24,9 @@ func TestMain(m *testing.M) {
}

fun = tests.NewFunnel(conf)
fun.StartServerInDocker("ohsucompbio/htcondor:latest", []string{})
defer fun.CleanupTestServerContainer()
serverName = "funnel-test-server-" + tests.RandomString(6)
fun.StartServerInDocker(serverName, "ohsucompbio/htcondor:latest", []string{})
defer fun.CleanupTestServerContainer(serverName)

m.Run()
return
Expand Down Expand Up @@ -69,8 +73,16 @@ func TestCancel(t *testing.T) {
}

task := fun.Wait(id)

if task.State != tes.State_CANCELED {
t.Fatal("expected task to get canceled")
t.Error("expected task to get canceled")
}

bid := task.Logs[0].Metadata["htcondor_id"]
cmd := exec.Command("docker", "exec", serverName, "condor_q", bid)
out, err := cmd.Output()
t.Log("cmd output:", string(out))
t.Log("error:", err)
if !strings.Contains(string(out), "0 jobs;") {
t.Error("unexpected condor_q output")
}
}
6 changes: 4 additions & 2 deletions tests/pbs/pbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

var fun *tests.Funnel
var serverName string

func TestMain(m *testing.M) {
conf := tests.DefaultConfig()
Expand All @@ -20,8 +21,9 @@ func TestMain(m *testing.M) {
}

fun = tests.NewFunnel(conf)
fun.StartServerInDocker("ohsucompbio/pbs-torque:latest", []string{"--hostname", "docker", "--privileged"})
defer fun.CleanupTestServerContainer()
serverName = "funnel-test-server-" + tests.RandomString(6)
fun.StartServerInDocker(serverName, "ohsucompbio/pbs-torque:latest", []string{"--hostname", "docker", "--privileged"})
defer fun.CleanupTestServerContainer(serverName)

m.Run()
return
Expand Down
20 changes: 16 additions & 4 deletions tests/slurm/slurm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package slurm
import (
"context"
"os"
"os/exec"
"strings"
"testing"

"github.com/ohsu-comp-bio/funnel/logger"
Expand All @@ -11,6 +13,7 @@ import (
)

var fun *tests.Funnel
var serverName string

func TestMain(m *testing.M) {
conf := tests.DefaultConfig()
Expand All @@ -21,8 +24,9 @@ func TestMain(m *testing.M) {
}

fun = tests.NewFunnel(conf)
fun.StartServerInDocker("ohsucompbio/slurm:latest", []string{"--hostname", "ernie"})
defer fun.CleanupTestServerContainer()
serverName = "funnel-test-server-" + tests.RandomString(6)
fun.StartServerInDocker(serverName, "ohsucompbio/slurm:latest", []string{"--hostname", "ernie"})
defer fun.CleanupTestServerContainer(serverName)

m.Run()
return
Expand Down Expand Up @@ -80,8 +84,16 @@ func TestCancel(t *testing.T) {
}

task := fun.Wait(id)

if task.State != tes.State_CANCELED {
t.Fatal("expected task to get canceled")
t.Error("expected task to get canceled")
}

bid := task.Logs[0].Metadata["slurm_id"]
cmd := exec.Command("docker", "exec", serverName, "squeue", "--job", bid)
out, err := cmd.Output()
t.Log("cmd output:", string(out))
t.Log("error:", err)
if strings.Contains(string(out), bid) {
t.Error("unexpected squeue output")
}
}

0 comments on commit e55c5af

Please sign in to comment.