Debian Codegraph @

routing/gateway_test.go

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