Skip to content

Commit

Permalink
Merge branch 'develop' into fixLiveTestReporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel committed Jan 24, 2024
2 parents 83d0e27 + 9550bbe commit b49e193
Show file tree
Hide file tree
Showing 60 changed files with 1,826 additions and 482 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ jobs:
run: go build -o chainlink.test .
- name: Setup DB
run: ./chainlink.test local db preparetest
- name: Install LOOP Plugins
run: |
pushd $(go list -m -f "{{.Dir}}" github.com/smartcontractkit/chainlink-feeds)
go install ./cmd/chainlink-feeds
popd
pushd $(go list -m -f "{{.Dir}}" github.com/smartcontractkit/chainlink-solana)
go install ./pkg/solana/cmd/chainlink-solana
popd
pushd $(go list -m -f "{{.Dir}}" github.com/smartcontractkit/chainlink-starknet/relayer)
go install ./pkg/chainlink/cmd/chainlink-starknet
popd
- name: Increase Race Timeout
if: github.event.schedule != ''
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/live-testnet-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -974,4 +974,4 @@ jobs:
if: always()
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/show-test-summary@ea889b3133bd7f16ab19ba4ba130de5d9162c669 # v2.3.4
with:
test_directory: "./"
test_directory: "./"
133 changes: 68 additions & 65 deletions common/client/node_selector_priority_level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,72 +17,75 @@ func TestPriorityLevelNodeSelector(t *testing.T) {
t.Parallel()

type nodeClient NodeClient[types.ID, Head]
var nodes []Node[types.ID, Head, nodeClient]
n1 := newMockNode[types.ID, Head, nodeClient](t)
n1.On("State").Return(nodeStateAlive)
n1.On("Order").Return(int32(1))

n2 := newMockNode[types.ID, Head, nodeClient](t)
n2.On("State").Return(nodeStateAlive)
n2.On("Order").Return(int32(1))

n3 := newMockNode[types.ID, Head, nodeClient](t)
n3.On("State").Return(nodeStateAlive)
n3.On("Order").Return(int32(1))

nodes = append(nodes, n1, n2, n3)
selector := newNodeSelector(NodeSelectionModePriorityLevel, nodes)
assert.Same(t, nodes[0], selector.Select())
assert.Same(t, nodes[1], selector.Select())
assert.Same(t, nodes[2], selector.Select())
assert.Same(t, nodes[0], selector.Select())
assert.Same(t, nodes[1], selector.Select())
assert.Same(t, nodes[2], selector.Select())
}

func TestPriorityLevelNodeSelector_None(t *testing.T) {
t.Parallel()

type nodeClient NodeClient[types.ID, Head]
var nodes []Node[types.ID, Head, nodeClient]

for i := 0; i < 3; i++ {
node := newMockNode[types.ID, Head, nodeClient](t)
if i == 0 {
// first node is out of sync
node.On("State").Return(nodeStateOutOfSync)
node.On("Order").Return(int32(1))
} else {
// others are unreachable
node.On("State").Return(nodeStateUnreachable)
node.On("Order").Return(int32(1))
}
nodes = append(nodes, node)
type testNode struct {
order int32
state nodeState
}
type testCase struct {
name string
nodes []testNode
expect []int // indexes of the nodes expected to be returned by Select
}

selector := newNodeSelector(NodeSelectionModePriorityLevel, nodes)
assert.Nil(t, selector.Select())
}

func TestPriorityLevelNodeSelector_DifferentOrder(t *testing.T) {
t.Parallel()

type nodeClient NodeClient[types.ID, Head]
var nodes []Node[types.ID, Head, nodeClient]
n1 := newMockNode[types.ID, Head, nodeClient](t)
n1.On("State").Return(nodeStateAlive)
n1.On("Order").Return(int32(1))

n2 := newMockNode[types.ID, Head, nodeClient](t)
n2.On("State").Return(nodeStateAlive)
n2.On("Order").Return(int32(2))

n3 := newMockNode[types.ID, Head, nodeClient](t)
n3.On("State").Return(nodeStateAlive)
n3.On("Order").Return(int32(3))
testCases := []testCase{
{
name: "TwoNodesSameOrder: Highest Allowed Order",
nodes: []testNode{
{order: 1, state: nodeStateAlive},
{order: 1, state: nodeStateAlive},
},
expect: []int{0, 1, 0, 1, 0, 1},
},
{
name: "TwoNodesSameOrder: Lowest Allowed Order",
nodes: []testNode{
{order: 100, state: nodeStateAlive},
{order: 100, state: nodeStateAlive},
},
expect: []int{0, 1, 0, 1, 0, 1},
},
{
name: "NoneAvailable",
nodes: []testNode{
{order: 1, state: nodeStateOutOfSync},
{order: 1, state: nodeStateUnreachable},
{order: 1, state: nodeStateUnreachable},
},
expect: []int{}, // no nodes should be selected
},
{
name: "DifferentOrder",
nodes: []testNode{
{order: 1, state: nodeStateAlive},
{order: 2, state: nodeStateAlive},
{order: 3, state: nodeStateAlive},
},
expect: []int{0, 0}, // only the highest order node should be selected
},
}

nodes = append(nodes, n1, n2, n3)
selector := newNodeSelector(NodeSelectionModePriorityLevel, nodes)
assert.Same(t, nodes[0], selector.Select())
assert.Same(t, nodes[0], selector.Select())
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
var nodes []Node[types.ID, Head, nodeClient]
for _, tn := range tc.nodes {
node := newMockNode[types.ID, Head, nodeClient](t)
node.On("State").Return(tn.state)
node.On("Order").Return(tn.order)
nodes = append(nodes, node)
}

selector := newNodeSelector(NodeSelectionModePriorityLevel, nodes)
for _, idx := range tc.expect {
if idx >= len(nodes) {
t.Fatalf("Invalid node index %d in test case '%s'", idx, tc.name)
}
assert.Same(t, nodes[idx], selector.Select())
}

// Check for nil selection if expected slice is empty
if len(tc.expect) == 0 {
assert.Nil(t, selector.Select())
}
})
}
}
Loading

0 comments on commit b49e193

Please sign in to comment.