Skip to content

Commit

Permalink
Migrate to assertion package (#477)
Browse files Browse the repository at this point in the history
* moves existing tests to use assert package; moves helper functions to test package

Signed-off-by: Jordan Rash <jordan@synadia.com>
  • Loading branch information
jordan-rash authored Jan 3, 2025
1 parent f21b68e commit 82fac7b
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 986 deletions.
188 changes: 48 additions & 140 deletions api/nodecontrol/client_test.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions cmd/nex/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ github.com/buraksezer/consistent v0.10.0 h1:hqBgz1PvNLC5rkWcEBVAL9dFMBWz6I0VgUCW
github.com/buraksezer/consistent v0.10.0/go.mod h1:6BrVajWq7wbKZlTOUPs/XVfR8c0maujuPowduSpZqmw=
github.com/buraksezer/olric v0.5.6-0.20240925183822-6ca0e20256e0 h1:0oLGcEeK3ew44mabFJ3nrAkg8G83RGM0FaXAIDrKSEQ=
github.com/buraksezer/olric v0.5.6-0.20240925183822-6ca0e20256e0/go.mod h1:g9fss7jy1l9W7pPezICBxRAPWDwCiImcPi0ABF1o1R0=
github.com/carlmjohnson/be v0.23.2 h1:1QjPnPJhwGUjsD9+7h98EQlKsxnG5TV+nnEvk0wnkls=
github.com/carlmjohnson/be v0.23.2/go.mod h1:KAgPUh0HpzWYZZI+IABdo80wTgY43YhbdsiLYAaSI/Q=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand Down
88 changes: 21 additions & 67 deletions test/auction_workload_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,35 @@ import (
"testing"
"time"

"github.com/carlmjohnson/be"
"github.com/synadia-io/nex/api/nodecontrol/gen"
"github.com/synadia-io/nex/models"
)

func TestAuctionDeploy(t *testing.T) {
workingDir := t.TempDir()

binPath, err := buildTestBinary(t, "./testdata/direct_start/main.go", workingDir)
if err != nil {
t.Fatal(err)
}
binPath := BuildTestBinary(t, "./testdata/direct_start/main.go", workingDir)

nexCli, err := buildNexCli(t, workingDir)
if err != nil {
t.Fatal(err)
}
nexCli := buildNexCli(t, workingDir)

s, err := startNatsServer(t, workingDir)
if err != nil {
t.Fatal(err)
}
s := StartNatsServer(t, workingDir)
defer s.Shutdown()

stdout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
nex1, err := startNexNodeCmd(t, workingDir, "", "", s.ClientURL(), "node1", "nexus")
if err != nil {
t.Fatal(err)
}
nex1 := startNexNodeCmd(t, workingDir, "", "", s.ClientURL(), "node1", "nexus")
nex1.Stdout = stdout
nex1.Stderr = stderr
// nex1.Stdout = os.Stdout
// nex1.Stderr = os.Stderr
nex1.SysProcAttr = sysProcAttr()

nex2, err := startNexNodeCmd(t, workingDir, "", "", s.ClientURL(), "node2", "nexus")
if err != nil {
t.Fatal(err)
}
nex2 := startNexNodeCmd(t, workingDir, "", "", s.ClientURL(), "node2", "nexus")
nex2.SysProcAttr = sysProcAttr()
// nex2.Stdout = os.Stdout
// nex2.Stderr = os.Stderr

err = nex1.Start()
if err != nil {
t.Fatal(err)
}
err := nex1.Start()
be.NilErr(t, err)
err = nex2.Start()
if err != nil {
t.Fatal(err)
}
be.NilErr(t, err)

go func() {
time.Sleep(500 * time.Millisecond)
Expand All @@ -69,75 +47,51 @@ func TestAuctionDeploy(t *testing.T) {

// find unused port
listener, err := net.Listen("tcp", ":0")
if err != nil {
t.Error(err)
return
}
be.NilErr(t, err)

port := listener.Addr().(*net.TCPAddr).Port
listener.Close()

auctionDeploy := exec.Command(nexCli, "workload", "run", "-s", s.ClientURL(), "--name", "tester", fmt.Sprintf("--node-tags=%s=%s", models.TagNodeName, "node1"), "file://"+binPath, fmt.Sprintf("--argv=-port=%d", port), "--env=ENV_TEST=nexenvset")
auctionDeploy.Stdout = stdout
auctionDeploy.Stderr = stderr
err = auctionDeploy.Run()
if err != nil {
t.Error(err)
}
be.NilErr(t, err)

stdout = new(bytes.Buffer)
stderr = new(bytes.Buffer)
nodels := exec.Command(nexCli, "node", "ls", "-s", s.ClientURL(), "--json")
nodels.Stdout = stdout
nodels.Stderr = stderr
err = nodels.Run()
if err != nil {
t.Error(err)
}
be.NilErr(t, err)

lsout := []*gen.NodePingResponseJson{}
err = json.Unmarshal(stdout.Bytes(), &lsout)
if err != nil {
t.Log(stdout.String())
t.Log(stderr.String())
t.Error(err)
}
be.NilErr(t, err)

for _, n := range lsout {
switch n.Tags.Tags[models.TagNodeName] {
case "node1":
if n.RunningAgents.Status["direct-start"] != 1 {
t.Error("node1 does not have expected workload running")
}
be.Equal(t, 1, n.RunningAgents.Status["direct-start"])
case "node2":
if n.RunningAgents.Status["direct-start"] != 0 {
t.Error("node2 has unexpected workloads running")
}
be.Equal(t, 0, n.RunningAgents.Status["direct-start"])
default:
t.Log(stdout.String())
t.Error("this should never happen")
}
}

err = stopProcess(nex1.Process)
if err != nil {
t.Error(err)
}
be.NilErr(t, err)
err = stopProcess(nex2.Process)
if err != nil {
t.Error(err)
}
be.NilErr(t, err)
}()

err = nex1.Wait()
if err != nil {
t.Fatal(err)
}
be.NilErr(t, err)
err = nex2.Wait()
if err != nil {
t.Fatal(err)
}
be.NilErr(t, err)

if !bytes.Contains(stdout.Bytes(), []byte("ENV: nexenvset")) {
t.Error("Expected ENV Data missing | stdout:", stdout.String())
}
be.In(t, "ENV: nexenvset", stdout.Bytes())
}
Loading

0 comments on commit 82fac7b

Please sign in to comment.