diff --git a/p2c/least_loaded_test.go b/p2c/least_loaded_test.go index 5a45b3c..7121edb 100644 --- a/p2c/least_loaded_test.go +++ b/p2c/least_loaded_test.go @@ -11,6 +11,7 @@ import ( func TestLeastLoaded(t *testing.T) { t.Run("0 item", func(t *testing.T) { ll := p2c.NewLeastLoaded() + ll.Reset() item, done := ll.Next() done(balancer.DoneInfo{}) assert.Nil(t, item) diff --git a/p2c/pewma_test.go b/p2c/pewma_test.go index db8ede5..8d25965 100644 --- a/p2c/pewma_test.go +++ b/p2c/pewma_test.go @@ -50,6 +50,7 @@ func TestPeakEwma(t *testing.T) { t.Run("1 item", func(t *testing.T) { ll := NewPeakEwma() + ll.Reset() ll.Add(1, 1) item, done := ll.Next() done(balancer.DoneInfo{}) diff --git a/roundrobin/roundrobin.go b/roundrobin/smooth_weighted.go similarity index 100% rename from roundrobin/roundrobin.go rename to roundrobin/smooth_weighted.go diff --git a/roundrobin/roundrobin_test.go b/roundrobin/smooth_weighted_test.go similarity index 81% rename from roundrobin/roundrobin_test.go rename to roundrobin/smooth_weighted_test.go index 005f2b1..47824ce 100644 --- a/roundrobin/roundrobin_test.go +++ b/roundrobin/smooth_weighted_test.go @@ -37,4 +37,8 @@ func TestSW_Next(t *testing.T) { if results["server1"] != 500 || results["server2"] != 200 || results["server3"] != 300 { t.Error("the algorithm is wrong") } + + w.(*smoothRoundrobin).items[0].EffectiveWeight = w.(*smoothRoundrobin).items[0].CurrentWeight - 1 + s, _ = w.Next() + assert.Equal(t, "server3", s.(string)) }