You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hal/hal/cluster_test.go

149 lines
3.0 KiB

package hal
import (
"github.com/stretchr/testify/assert"
"testing"
)
// func TestCluster_Run(t *testing.T) {
// var mapping ModuleMapping
//
// firstModule := &Module{
// programStorage: map[int64]*ProgrammedInstruction{
// 1: {
// Instruction: InstructionStart,
// },
// },
// register: []float64{0},
// IO: map[int64]IO{},
// }
// secondModule := &Module{
// programStorage: map[int64]*ProgrammedInstruction{
// 1: {
// Instruction: InstructionStop,
// },
// },
// register: []float64{0},
// IO: map[int64]IO{},
// }
//
// mapping = map[MultiThreadedIOPort]MultiThreadedIOPort{
// {
// Module: firstModule,
// IOPort: 0,
// }: {
// Module: secondModule,
// IOPort: 0,
// },
// }
// assert.NoError(t, mapping.BuildCluster().Run(context.Background()))
// }
func TestModuleMapping_BuildCluster(t *testing.T) {
config := &ClusterConfig{
Nodes: []*ClusterNode{
{
Name: "node1",
},
{
Name: "node2",
},
{
Name: "node3",
},
},
Connections: []*ClusterConnection{
{
SourceNode: "node1",
SourcePort: 1,
DestNode: "node2",
DestPort: 1,
},
{
SourceNode: "node2",
SourcePort: 1,
DestNode: "node1",
DestPort: 1,
},
{
SourceNode: "node1",
SourcePort: 2,
DestNode: "node2",
DestPort: 2,
},
{
SourceNode: "node2",
SourcePort: 2,
DestNode: "node1",
DestPort: 2,
},
{
SourceNode: "node3",
SourcePort: 2,
DestNode: "node2",
DestPort: 3,
},
{
SourceNode: "node2",
SourcePort: 3,
DestNode: "node3",
DestPort: 2,
},
{
SourceNode: "node3",
SourcePort: 3,
DestNode: "node1",
DestPort: 3,
},
{
SourceNode: "node1",
SourcePort: 3,
DestNode: "node3",
DestPort: 3,
},
},
}
modules := make(map[string]*Module)
modules = map[string]*Module{
"node1": {
programStorage: map[int64]*ProgrammedInstruction{
1: {Instruction: InstructionStart},
2: {Instruction: InstructionStop},
},
register: []float64{0},
IO: map[int64]IO{},
},
"node2": {
programStorage: map[int64]*ProgrammedInstruction{
1: {Instruction: InstructionStart},
2: {Instruction: InstructionStop},
},
register: []float64{0},
IO: map[int64]IO{},
},
"node3": {
programStorage: map[int64]*ProgrammedInstruction{
1: {Instruction: InstructionStart},
2: {Instruction: InstructionStop},
},
register: []float64{0},
IO: map[int64]IO{},
},
}
cluster, err := config.BuildCluster(modules)
assert.NoError(t, err)
// First connection config
assert.NotNil(t, cluster.modules[0].IO[1])
assert.NotNil(t, cluster.modules[1].IO[1])
// Second
assert.NotNil(t, cluster.modules[0].IO[2])
assert.NotNil(t, cluster.modules[1].IO[2])
// Third
assert.NotNil(t, cluster.modules[1].IO[3])
assert.NotNil(t, cluster.modules[2].IO[2])
// Fourth
assert.NotNil(t, cluster.modules[0].IO[3])
assert.NotNil(t, cluster.modules[2].IO[3])
}