mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
this rewrites the load balancer which was pointed out to be problematic here: https://github.com/iron-io/functions/issues/570 with a test suite located at test/fnlb-test-harness -- this test is now 'passing' in the sense that now when running multiple functions nodes behind 1 load balancer every call goes to the same functions node. yay. used a different consistent hashing algorithm and also threw out all the fallback code (all the code, really). this is basically an mvp and there is some work that needs to be done for running multiple load balancers, allowing functions to run on more nodes as load increases and some basic features like http/2 -- also needs some love to be really robust; most of this is noted in TODOs in the file. this does basic health checking configurable in the same way as aws elb. I think we could probably do gossip but this works as a first cut. after N health checks fail then requests start to go to a different node, meanwhile all requests to that node will fail (need to fix). this continues to use consistent hashing, which is great in that we don't need to store anything, and we may be able to stick with the strategy in the future with some care.
73 lines
1.3 KiB
Go
73 lines
1.3 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestCHAdd(t *testing.T) {
|
|
var ch consistentHash
|
|
nodes := []string{"1", "2", "3"}
|
|
for _, n := range nodes {
|
|
ch.add(n)
|
|
}
|
|
|
|
if len(ch.nodes) != 3 {
|
|
t.Fatal("nodes list should be len of 3, got:", len(ch.nodes))
|
|
}
|
|
|
|
// test dupes don't get added
|
|
for _, n := range nodes {
|
|
ch.add(n)
|
|
}
|
|
|
|
if len(ch.nodes) != 3 {
|
|
t.Fatal("nodes list should be len of 3, got:", len(ch.nodes))
|
|
}
|
|
}
|
|
|
|
func TestCHRemove(t *testing.T) {
|
|
var ch consistentHash
|
|
nodes := []string{"1", "2", "3"}
|
|
for _, n := range nodes {
|
|
ch.add(n)
|
|
}
|
|
|
|
if len(ch.nodes) != 3 {
|
|
t.Fatal("nodes list should be len of 3, got:", len(ch.nodes))
|
|
}
|
|
|
|
ch.remove("4")
|
|
|
|
if len(ch.nodes) != 3 {
|
|
t.Fatal("nodes list should be len of 3, got:", len(ch.nodes))
|
|
}
|
|
|
|
ch.remove("3")
|
|
|
|
if len(ch.nodes) != 2 {
|
|
t.Fatal("nodes list should be len of 2, got:", len(ch.nodes))
|
|
}
|
|
|
|
ch.remove("3")
|
|
|
|
if len(ch.nodes) != 2 {
|
|
t.Fatal("nodes list should be len of 2, got:", len(ch.nodes))
|
|
}
|
|
}
|
|
|
|
func TestCHGet(t *testing.T) {
|
|
var ch consistentHash
|
|
nodes := []string{"1", "2", "3"}
|
|
for _, n := range nodes {
|
|
ch.add(n)
|
|
}
|
|
|
|
if len(ch.nodes) != 3 {
|
|
t.Fatal("nodes list should be len of 3, got:", len(ch.nodes))
|
|
}
|
|
|
|
keys := []string{"a", "b", "c"}
|
|
for _, k := range keys {
|
|
_ = ch.get(k)
|
|
// testing this doesn't panic basically? could test distro but meh
|
|
}
|
|
}
|