Skip to content

Commit

Permalink
test: add start of tests for fluence package
Browse files Browse the repository at this point in the history
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
vsoch committed May 28, 2024
1 parent 422c313 commit a3a4f03
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/test.yaml
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
7 changes: 7 additions & 0 deletions src/fluence/Makefile
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/
77 changes: 77 additions & 0 deletions src/fluence/jgf/jgf_test.go
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)

}

0 comments on commit a3a4f03

Please sign in to comment.