-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add start of tests for fluence package
Problem: we will want to have scoped tests for fluence. Solution: to start, add a simple test file for JGF (the content of this current PR) and have an easy way to run it with "make test" from that directory. Currently this does not validate most of the structure - I would like to review the output, discuss a testing strategy, and then update the commit here to reflect that decision. Signed-off-by: vsoch <[email protected]>
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: fluence testing | ||
|
||
on: | ||
- pull_request: [] | ||
|
||
jobs: | ||
test-fluence: | ||
runs-on: ubuntu-latest | ||
name: build fluence | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: ^1.21 | ||
|
||
- name: Run Tests | ||
run: | | ||
cd src/fluence | ||
make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
.PHONY: all | ||
all: test | ||
|
||
.PHONY: test | ||
test: | ||
go test -v ./jgf/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package jgf | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewFluxJGF(t *testing.T) { | ||
|
||
// Create a new FluxGraph, assert that it is empty | ||
fluxgraph := NewFluxJGF() | ||
assert.Equal(t, len(fluxgraph.Graph.Nodes), 0) | ||
assert.Equal(t, fluxgraph.Resources.Elements, int64(0)) | ||
assert.Equal(t, len(fluxgraph.NodeMap), 0) | ||
|
||
out, err := fluxgraph.ToJson() | ||
assert.Nil(t, err) | ||
fmt.Println() | ||
fmt.Println("== Empty graph:") | ||
fmt.Println(out) | ||
|
||
// Init the cluster (make the root node) | ||
clusterNode, err := fluxgraph.InitCluster("keebler") | ||
assert.Nil(t, err) | ||
|
||
out, err = fluxgraph.ToJson() | ||
assert.Nil(t, err) | ||
fmt.Println() | ||
fmt.Println("== Graph with Cluster Root:") | ||
fmt.Println(out) | ||
|
||
// Add subnets to it | ||
subnetNodeA := fluxgraph.MakeSubnet("east") | ||
subnetNodeB := fluxgraph.MakeSubnet("west") | ||
fluxgraph.MakeBidirectionalEdge(clusterNode.Id, subnetNodeA.Id) | ||
fluxgraph.MakeBidirectionalEdge(clusterNode.Id, subnetNodeB.Id) | ||
|
||
out, err = fluxgraph.ToJson() | ||
assert.Nil(t, err) | ||
fmt.Println() | ||
fmt.Println("== Graph with Two Subnets:") | ||
fmt.Println(out) | ||
|
||
// Add some nodes! | ||
computeNodeA := fluxgraph.MakeNode("node", subnetNodeA.Metadata.Name) | ||
computeNodeB := fluxgraph.MakeNode("node", subnetNodeB.Metadata.Name) | ||
fluxgraph.MakeBidirectionalEdge(subnetNodeA.Id, computeNodeA.Id) | ||
fluxgraph.MakeBidirectionalEdge(subnetNodeB.Id, computeNodeB.Id) | ||
|
||
out, err = fluxgraph.ToJson() | ||
assert.Nil(t, err) | ||
fmt.Println() | ||
fmt.Println("== Graph with Two Subnets, Each with a node:") | ||
fmt.Println(out) | ||
|
||
// Add a GPU to one, and cores to the other | ||
subpath := fmt.Sprintf("%s/%s", subnetNodeA.Metadata.Name, computeNodeA.Metadata.Name) | ||
gpuNodeA := fluxgraph.MakeGPU(NvidiaGPU, subpath, 1) | ||
fluxgraph.MakeBidirectionalEdge(computeNodeA.Id, gpuNodeA.Id) | ||
|
||
subpath = fmt.Sprintf("%s/%s", subnetNodeB.Metadata.Name, computeNodeB.Metadata.Name) | ||
coreNode := fluxgraph.MakeCore(CoreType, subpath) | ||
fluxgraph.MakeBidirectionalEdge(computeNodeB.Id, coreNode.Id) | ||
|
||
// Finally, add some memory to the second compute node | ||
memoryNode := fluxgraph.MakeMemory(MemoryType, subpath, 1<<10) | ||
fluxgraph.MakeBidirectionalEdge(computeNodeA.Id, memoryNode.Id) | ||
|
||
out, err = fluxgraph.ToJson() | ||
assert.Nil(t, err) | ||
fmt.Println() | ||
fmt.Println("== Graph with Two Subnets, Two Nodes, with GPU/Core/Memory:") | ||
fmt.Println(out) | ||
|
||
} |