gateway_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. package routing
  2. import (
  3. "net/netip"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestRebalance3_2Split(t *testing.T) {
  8. gateways := []Gateway{}
  9. gateways = append(gateways, Gateway{addr: netip.Addr{}, weight: 10})
  10. gateways = append(gateways, Gateway{addr: netip.Addr{}, weight: 5})
  11. CalculateBucketsForGateways(gateways)
  12. assert.Equal(t, 1431655764, gateways[0].bucketUpperBound) // INT_MAX/3*2
  13. assert.Equal(t, 2147483647, gateways[1].bucketUpperBound) // INT_MAX
  14. }
  15. func TestRebalanceEqualSplit(t *testing.T) {
  16. gateways := []Gateway{}
  17. gateways = append(gateways, Gateway{addr: netip.Addr{}, weight: 1})
  18. gateways = append(gateways, Gateway{addr: netip.Addr{}, weight: 1})
  19. gateways = append(gateways, Gateway{addr: netip.Addr{}, weight: 1})
  20. CalculateBucketsForGateways(gateways)
  21. assert.Equal(t, 715827882, gateways[0].bucketUpperBound) // INT_MAX/3
  22. assert.Equal(t, 1431655764, gateways[1].bucketUpperBound) // INT_MAX/3*2
  23. assert.Equal(t, 2147483647, gateways[2].bucketUpperBound) // INT_MAX
  24. }